• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SurfaceFillContext_v1_DEFINED
9 #define SurfaceFillContext_v1_DEFINED
10 
11 #include "include/core/SkSize.h"
12 #include "include/private/GrTypesPriv.h"
13 #include "src/gpu/GrImageInfo.h"
14 #include "src/gpu/GrSwizzle.h"
15 #include "src/gpu/SurfaceFillContext.h"
16 #include "src/gpu/ops/OpsTask.h"
17 
18 #include <array>
19 #include <tuple>
20 
21 class GrFragmentProcessor;
22 class GrImageContext;
23 class GrOp;
24 class GrBackendFormat;
25 class GrRecordingContext;
26 class GrSurfaceProxyView;
27 class SkColorSpace;
28 
29 namespace skgpu::v1 {
30 
31 class SurfaceFillContext : public skgpu::SurfaceFillContext {
32 public:
33     SurfaceFillContext(GrRecordingContext*,
34                        GrSurfaceProxyView readView,
35                        GrSurfaceProxyView writeView,
36                        const GrColorInfo&,
37                        bool flushTimeOpsTask = false);
38 
39     void discard() override;
40 
41     void fillRectWithFP(const SkIRect& dstRect, std::unique_ptr<GrFragmentProcessor> fp) override;
42 
43     bool blitTexture(GrSurfaceProxyView view,
44                      const SkIRect& srcRect,
45                      const SkIPoint& dstPoint) override;
46 
47     OpsTask* getOpsTask();
48     sk_sp<GrRenderTask> refRenderTask() override;
49 
numSamples()50     int numSamples() const { return this->asRenderTargetProxy()->numSamples(); }
wrapsVkSecondaryCB()51     bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
52 
arenaAlloc()53     SkArenaAlloc* arenaAlloc() { return this->arenas()->arenaAlloc(); }
subRunAlloc()54     GrSubRunAllocator* subRunAlloc() { return this->arenas()->subRunAlloc(); }
55 
56 #if GR_TEST_UTILS
testingOnly_PeekLastOpsTask()57     OpsTask* testingOnly_PeekLastOpsTask() { return fOpsTask.get(); }
58 #endif
59 
writeSurfaceView()60     const GrSurfaceProxyView& writeSurfaceView() const { return fWriteView; }
61 
62 protected:
63     /**
64      * Creates a constant color paint for a clear, using src-over if possible to improve batching.
65      */
66     static void ClearToGrPaint(std::array<float, 4> color, GrPaint* paint);
67 
68     void addOp(GrOp::Owner);
69 
70     OpsTask* replaceOpsTask();
71 
72 private:
arenas()73     sk_sp<GrArenas> arenas() { return fWriteView.proxy()->asRenderTargetProxy()->arenas(); }
74 
75     /** Override to be notified in subclass before the current ops task is replaced. */
willReplaceOpsTask(OpsTask * prevTask,OpsTask * nextTask)76     virtual void willReplaceOpsTask(OpsTask* prevTask, OpsTask* nextTask) {}
77 
78     /**
79      * Override to be called to participate in the decision to discard all previous ops if a
80      * fullscreen clear occurs.
81      */
canDiscardPreviousOpsOnFullClear()82     virtual OpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const {
83         return OpsTask::CanDiscardPreviousOps::kYes;
84     }
85 
86     void internalClear(const SkIRect* scissor,
87                        std::array<float, 4> color,
88                        bool upgradePartialToFull = false) override;
89 
90     void addDrawOp(GrOp::Owner);
91 
92     SkDEBUGCODE(void onValidate() const override;)
93 
94     // The OpsTask can be closed by some other surface context that has picked it up. For this
95     // reason, the OpsTask should only ever be accessed via 'getOpsTask'.
96     sk_sp<OpsTask> fOpsTask;
97 
98     bool fFlushTimeOpsTask;
99 
100     using INHERITED = skgpu::SurfaceFillContext;
101 };
102 
103 } // namespace skgpu::v1
104 
105 #endif // SurfaceFillContext_v1_DEFINED
106