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/gpu/d3d/D3DTestContext.h" 9 10 #ifdef SK_DIRECT3D 11 12 #include "include/gpu/GrDirectContext.h" 13 #include "tools/gpu/d3d/D3DTestUtils.h" 14 15 namespace { 16 17 class D3DTestContextImpl : public sk_gpu_test::D3DTestContext { 18 public: Create(D3DTestContext * sharedContext)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 ~D3DTestContextImpl()37 ~D3DTestContextImpl() override { this->teardown(); } 38 testAbandon()39 void testAbandon() override {} 40 finish()41 void finish() override {} 42 makeContext(const GrContextOptions & options)43 sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override { 44 return GrDirectContext::MakeDirect3D(fD3D, options); 45 } 46 47 protected: teardown()48 void teardown() override { 49 INHERITED::teardown(); 50 if (fOwnsContext) { 51 // delete all the D3D objects in the backend context 52 } 53 } 54 55 private: D3DTestContextImpl(const GrD3DBackendContext & backendContext,bool ownsContext)56 D3DTestContextImpl(const GrD3DBackendContext& backendContext, bool ownsContext) 57 : D3DTestContext(backendContext, ownsContext) { 58 fFenceSupport = true; 59 } 60 onPlatformMakeNotCurrent() const61 void onPlatformMakeNotCurrent() const override {} onPlatformMakeCurrent() const62 void onPlatformMakeCurrent() const override {} onPlatformGetAutoContextRestore() const63 std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; } 64 65 using INHERITED = sk_gpu_test::D3DTestContext; 66 }; 67 } // anonymous namespace 68 69 namespace sk_gpu_test { CreatePlatformD3DTestContext(D3DTestContext * sharedContext)70D3DTestContext* CreatePlatformD3DTestContext(D3DTestContext* sharedContext) { 71 return D3DTestContextImpl::Create(sharedContext); 72 } 73 } // namespace sk_gpu_test 74 75 #endif 76