| 1 |
/* |
| 2 |
* Copyright 2020 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "tools/ganesh/d3d/D3DTestContext.h" |
| 9 |
|
| 10 |
#ifdef SK_DIRECT3D |
| 11 |
|
| 12 |
#include "include/gpu/ganesh/GrDirectContext.h" |
| 13 |
#include "tools/ganesh/d3d/D3DTestUtils.h" |
| 14 |
|
| 15 |
namespace { |
| 16 |
|
| 17 |
class D3DTestContextImpl : public sk_gpu_test::D3DTestContext { |
| 18 |
public: |
| 19 |
static D3DTestContext* Create(D3DTestContext* sharedContext) { |
| 20 |
GrD3DBackendContext backendContext; |
| 21 |
bool ownsContext; |
| 22 |
if (sharedContext) { |
| 23 |
// take from the given context |
| 24 |
ownsContext = false; |
| 25 |
backendContext = sharedContext->getD3DBackendContext(); |
| 26 |
} else { |
| 27 |
// create our own |
| 28 |
if (!sk_gpu_test::CreateD3DBackendContext(&backendContext)) { |
| 29 |
return nullptr; |
| 30 |
} |
| 31 |
|
| 32 |
ownsContext = true; |
| 33 |
} |
| 34 |
return new D3DTestContextImpl(backendContext, ownsContext); |
| 35 |
} |
| 36 |
|
| 37 |
~D3DTestContextImpl() override { this->teardown(); } |
| 38 |
|
| 39 |
void testAbandon() override {} |
| 40 |
|
| 41 |
sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override { |
| 42 |
return GrDirectContext::MakeDirect3D(fD3D, options); |
| 43 |
} |
| 44 |
|
| 45 |
protected: |
| 46 |
void teardown() override { |
| 47 |
INHERITED::teardown(); |
| 48 |
if (fOwnsContext) { |
| 49 |
// delete all the D3D objects in the backend context |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
private: |
| 54 |
D3DTestContextImpl(const GrD3DBackendContext& backendContext, bool ownsContext) |
| 55 |
: D3DTestContext(backendContext, ownsContext) { |
| 56 |
fFenceSupport = true; |
| 57 |
} |
| 58 |
|
| 59 |
void onPlatformMakeNotCurrent() const override {} |
| 60 |
void onPlatformMakeCurrent() const override {} |
| 61 |
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; } |
| 62 |
|
| 63 |
using INHERITED = sk_gpu_test::D3DTestContext; |
| 64 |
}; |
| 65 |
} // anonymous namespace |
| 66 |
|
| 67 |
namespace sk_gpu_test { |
| 68 |
D3DTestContext* CreatePlatformD3DTestContext(D3DTestContext* sharedContext) { |
| 69 |
return D3DTestContextImpl::Create(sharedContext); |
| 70 |
} |
| 71 |
} // namespace sk_gpu_test |
| 72 |
|
| 73 |
#endif |