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 41 // There is really nothing to here since we don't own any unqueued command buffers here. submit()42 void submit() override {} 43 finish()44 void finish() override {} 45 makeGrContext(const GrContextOptions & options)46 sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override { 47 return GrContext::MakeDirect3D(fD3D, options); 48 } 49 50 protected: teardown()51 void teardown() override { 52 INHERITED::teardown(); 53 if (fOwnsContext) { 54 // delete all the D3D objects in the backend context 55 } 56 } 57 58 private: D3DTestContextImpl(const GrD3DBackendContext & backendContext,bool ownsContext)59 D3DTestContextImpl(const GrD3DBackendContext& backendContext, bool ownsContext) 60 : D3DTestContext(backendContext, ownsContext) { 61 } 62 onPlatformMakeNotCurrent() const63 void onPlatformMakeNotCurrent() const override {} onPlatformMakeCurrent() const64 void onPlatformMakeCurrent() const override {} onPlatformGetAutoContextRestore() const65 std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; } onPlatformSwapBuffers() const66 void onPlatformSwapBuffers() const override {} 67 68 typedef sk_gpu_test::D3DTestContext INHERITED; 69 }; 70 } // anonymous namespace 71 72 namespace sk_gpu_test { CreatePlatformD3DTestContext(D3DTestContext * sharedContext)73D3DTestContext* CreatePlatformD3DTestContext(D3DTestContext* sharedContext) { 74 return D3DTestContextImpl::Create(sharedContext); 75 } 76 } // namespace sk_gpu_test 77 78 #endif 79