Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 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 GrGrAtlasRenderTask_DEFINED |
| 9 | #define GrGrAtlasRenderTask_DEFINED |
| 10 | |
| 11 | #include "include/core/SkPath.h" |
| 12 | #include "src/gpu/GrDynamicAtlas.h" |
| 13 | #include "src/gpu/GrOpsTask.h" |
| 14 | |
| 15 | struct SkIPoint16; |
| 16 | |
| 17 | // Represents a GrRenderTask that draws paths into an atlas. This task gets added the DAG and left |
| 18 | // open, lays out its atlas while future tasks call addPath(), and finally adds its internal draw |
| 19 | // ops during onMakeClosed(). |
| 20 | // |
| 21 | // The atlas texture does not get instantiated automatically. It is the creator's responsibility to |
| 22 | // call instantiate() at flush time. |
| 23 | class GrAtlasRenderTask : public GrOpsTask { |
| 24 | public: |
Robert Phillips | a92913e | 2021-07-12 16:31:52 -0400 | [diff] [blame] | 25 | GrAtlasRenderTask(GrRecordingContext*, |
| 26 | sk_sp<GrArenas>, |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 27 | std::unique_ptr<GrDynamicAtlas>); |
| 28 | |
| 29 | const GrTextureProxy* atlasProxy() const { return fDynamicAtlas->textureProxy(); } |
| 30 | GrSurfaceProxyView readView(const GrCaps& caps) const { return fDynamicAtlas->readView(caps); } |
| 31 | |
| 32 | // Allocates a rectangle for, and stages the given path to be rendered into the atlas. Returns |
| 33 | // false if there was not room in the atlas. On success, writes out the location of the path's |
| 34 | // upper-left corner to 'locationInAtlas'. |
Chris Dalton | 5e332c8 | 2021-07-21 16:04:47 -0600 | [diff] [blame^] | 35 | bool addPath(const SkMatrix&, const SkPath&, SkIPoint pathDevTopLeft, int widthInAtlas, |
| 36 | int heightInAtlas, bool transposedInAtlas, SkIPoint16* locationInAtlas); |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 37 | |
| 38 | // Must be called at flush time. The texture proxy is instantiated with 'backingTexture', if |
| 39 | // provided. See GrDynamicAtlas. |
| 40 | void instantiate(GrOnFlushResourceProvider* onFlushRP, |
| 41 | sk_sp<GrTexture> backingTexture = nullptr) { |
| 42 | SkASSERT(this->isClosed()); |
| 43 | fDynamicAtlas->instantiate(onFlushRP, std::move(backingTexture)); |
| 44 | } |
| 45 | |
| 46 | private: |
| 47 | // Adds internal ops to render the atlas before deferring to GrOpsTask::onMakeClosed. |
| 48 | ExpectedOutcome onMakeClosed(GrRecordingContext*, SkIRect* targetUpdateBounds) override; |
| 49 | |
| 50 | void stencilAtlasRect(GrRecordingContext*, const SkRect&, const SkPMColor4f&, |
| 51 | const GrUserStencilSettings*); |
Chris Dalton | 5e332c8 | 2021-07-21 16:04:47 -0600 | [diff] [blame^] | 52 | void addAtlasDrawOp(GrOp::Owner, const GrCaps&); |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 53 | |
| 54 | // Executes the GrOpsTask and resolves msaa if needed. |
| 55 | bool onExecute(GrOpFlushState* flushState) override; |
| 56 | |
Chris Dalton | 5e332c8 | 2021-07-21 16:04:47 -0600 | [diff] [blame^] | 57 | SkPath* getUberPath(GrFillRule fillRule) { |
| 58 | return &fUberPaths[fillRule == GrFillRule::kEvenOdd]; |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | const std::unique_ptr<GrDynamicAtlas> fDynamicAtlas; |
Chris Dalton | 5e332c8 | 2021-07-21 16:04:47 -0600 | [diff] [blame^] | 62 | SkPath fUberPaths[2]; // 2 fill rules: "nonzero" and "even/odd". |
Chris Dalton | 83420eb | 2021-06-23 18:47:09 -0600 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #endif |