• 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/SurfaceFillContext.h"
15 #include "src/gpu/Swizzle.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 resolveMSAA() override;
42 
43     void fillRectWithFP(const SkIRect& dstRect, std::unique_ptr<GrFragmentProcessor> fp) override;
44 
45     bool blitTexture(GrSurfaceProxyView view,
46                      const SkIRect& srcRect,
47                      const SkIPoint& dstPoint) override;
48 
49     OpsTask* getOpsTask();
50     sk_sp<GrRenderTask> refRenderTask() override;
51 
numSamples()52     int numSamples() const { return this->asRenderTargetProxy()->numSamples(); }
wrapsVkSecondaryCB()53     bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
54 
arenaAlloc()55     SkArenaAlloc* arenaAlloc() { return this->arenas()->arenaAlloc(); }
subRunAlloc()56     GrSubRunAllocator* subRunAlloc() { return this->arenas()->subRunAlloc(); }
57 
58 #if GR_TEST_UTILS
testingOnly_PeekLastOpsTask()59     OpsTask* testingOnly_PeekLastOpsTask() { return fOpsTask.get(); }
60 #endif
61 
writeSurfaceView()62     const GrSurfaceProxyView& writeSurfaceView() const { return fWriteView; }
63 
64 protected:
65     /**
66      * Creates a constant color paint for a clear, using src-over if possible to improve batching.
67      */
68     static void ClearToGrPaint(std::array<float, 4> color, GrPaint* paint);
69 
70     void addOp(GrOp::Owner);
71 
72     OpsTask* replaceOpsTask();
73 
74 private:
arenas()75     sk_sp<GrArenas> arenas() { return fWriteView.proxy()->asRenderTargetProxy()->arenas(); }
76 
77     /** Override to be notified in subclass before the current ops task is replaced. */
willReplaceOpsTask(OpsTask * prevTask,OpsTask * nextTask)78     virtual void willReplaceOpsTask(OpsTask* prevTask, OpsTask* nextTask) {}
79 
80     /**
81      * Override to be called to participate in the decision to discard all previous ops if a
82      * fullscreen clear occurs.
83      */
canDiscardPreviousOpsOnFullClear()84     virtual OpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const {
85         return OpsTask::CanDiscardPreviousOps::kYes;
86     }
87 
88     void internalClear(const SkIRect* scissor,
89                        std::array<float, 4> color,
90                        bool upgradePartialToFull = false) override;
91 
92     void addDrawOp(GrOp::Owner);
93 
94     SkDEBUGCODE(void onValidate() const override;)
95 
96     // The OpsTask can be closed by some other surface context that has picked it up. For this
97     // reason, the OpsTask should only ever be accessed via 'getOpsTask'.
98     sk_sp<OpsTask> fOpsTask;
99 
100     bool fFlushTimeOpsTask;
101 
102     using INHERITED = skgpu::SurfaceFillContext;
103 };
104 
105 } // namespace skgpu::v1
106 
107 #endif // SurfaceFillContext_v1_DEFINED
108