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/GrContext.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 makeGrContext(const GrContextOptions & options)43 sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override { 44 return GrContext::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 } 59 onPlatformMakeNotCurrent() const60 void onPlatformMakeNotCurrent() const override {} onPlatformMakeCurrent() const61 void onPlatformMakeCurrent() const override {} onPlatformGetAutoContextRestore() const62 std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; } 63 64 typedef sk_gpu_test::D3DTestContext INHERITED; 65 }; 66 } // anonymous namespace 67 68 namespace sk_gpu_test { CreatePlatformD3DTestContext(D3DTestContext * sharedContext)69D3DTestContext* CreatePlatformD3DTestContext(D3DTestContext* sharedContext) { 70 return D3DTestContextImpl::Create(sharedContext); 71 } 72 } // namespace sk_gpu_test 73 74 #endif 75