xref: /aosp_15_r20/external/skia/src/gpu/ganesh/mock/GrMockRenderTask.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 Google Inc.
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 #ifndef GrMockRenderTask_DEFINED
9 #define GrMockRenderTask_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/private/base/SkAssert.h"
13 #include "include/private/base/SkDebug.h"
14 #include "include/private/base/SkTArray.h"
15 #include "include/private/gpu/ganesh/GrTypesPriv.h"
16 #include "src/gpu/ganesh/GrRenderTask.h"
17 #include "src/gpu/ganesh/GrSurfaceProxy.h"
18 
19 #include <utility>
20 
21 class GrOpFlushState;
22 class GrRecordingContext;
23 class GrResourceAllocator;
24 struct SkIRect;
25 
26 class GrMockRenderTask final : public GrRenderTask {
27 public:
GrMockRenderTask()28     GrMockRenderTask() : GrRenderTask() {
29         // Mock tasks are never "owned" by a drawmgr in the first place.
30         this->setFlag(kDisowned_Flag);
31     }
32 
addTarget(sk_sp<GrSurfaceProxy> proxy)33     void addTarget(sk_sp<GrSurfaceProxy> proxy) { fTargets.push_back(std::move(proxy)); }
addDependency(GrRenderTask * dep)34     void addDependency(GrRenderTask* dep) { fDependencies.push_back(dep); }
addUsed(sk_sp<GrSurfaceProxy> proxy)35     void addUsed(sk_sp<GrSurfaceProxy> proxy) { fUsed.push_back(std::move(proxy)); }
36 
37     // Overrides.
38 #ifdef SK_DEBUG
visitProxies_debugOnly(const GrVisitProxyFunc &)39     void visitProxies_debugOnly(const GrVisitProxyFunc&) const override { return; }
40 #endif
gatherProxyIntervals(GrResourceAllocator *)41     void gatherProxyIntervals(GrResourceAllocator*) const override {}
onMakeClosed(GrRecordingContext *,SkIRect *)42     ExpectedOutcome onMakeClosed(GrRecordingContext*, SkIRect*) override { SkUNREACHABLE; }
onIsUsed(GrSurfaceProxy * proxy)43     bool onIsUsed(GrSurfaceProxy* proxy) const override {
44         for (const auto& entry : fUsed) {
45             if (entry.get() == proxy) {
46                 return true;
47             }
48         }
49         return false;
50     }
onExecute(GrOpFlushState *)51     bool onExecute(GrOpFlushState*) override { return true; }
52 
53 #if defined(GPU_TEST_UTILS)
name()54     const char* name() const final { return "Mock"; }
55 #endif
56 
57 private:
58     skia_private::TArray<sk_sp<GrSurfaceProxy>> fUsed;
59 };
60 
61 #endif
62