xref: /aosp_15_r20/external/skia/tools/gpu/d3d/D3DTestContext.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/ganesh/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 
makeContext(const GrContextOptions & options)41     sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override {
42         return GrDirectContext::MakeDirect3D(fD3D, options);
43     }
44 
45 protected:
teardown()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:
D3DTestContextImpl(const GrD3DBackendContext & backendContext,bool ownsContext)54     D3DTestContextImpl(const GrD3DBackendContext& backendContext, bool ownsContext)
55             : D3DTestContext(backendContext, ownsContext) {
56         fFenceSupport = true;
57     }
58 
onPlatformMakeNotCurrent() const59     void onPlatformMakeNotCurrent() const override {}
onPlatformMakeCurrent() const60     void onPlatformMakeCurrent() const override {}
onPlatformGetAutoContextRestore() const61     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 {
CreatePlatformD3DTestContext(D3DTestContext * sharedContext)68 D3DTestContext* CreatePlatformD3DTestContext(D3DTestContext* sharedContext) {
69     return D3DTestContextImpl::Create(sharedContext);
70 }
71 }  // namespace sk_gpu_test
72 
73 #endif
74