blob: 4834ea4531f4a6bab25bc96f39b3647a95d06407 [file] [log] [blame]
Chris Dalton83420eb2021-06-23 18:47:09 -06001/*
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
15struct 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.
23class GrAtlasRenderTask : public GrOpsTask {
24public:
Robert Phillipsa92913e2021-07-12 16:31:52 -040025 GrAtlasRenderTask(GrRecordingContext*,
26 sk_sp<GrArenas>,
Chris Dalton83420eb2021-06-23 18:47:09 -060027 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'.
35 bool addPath(const SkMatrix&, const SkPath&, bool antialias, SkIPoint pathDevTopLeft,
36 int widthInAtlas, int heightInAtlas, bool transposedInAtlas,
37 SkIPoint16* locationInAtlas);
38
39 // Must be called at flush time. The texture proxy is instantiated with 'backingTexture', if
40 // provided. See GrDynamicAtlas.
41 void instantiate(GrOnFlushResourceProvider* onFlushRP,
42 sk_sp<GrTexture> backingTexture = nullptr) {
43 SkASSERT(this->isClosed());
44 fDynamicAtlas->instantiate(onFlushRP, std::move(backingTexture));
45 }
46
47private:
48 // Adds internal ops to render the atlas before deferring to GrOpsTask::onMakeClosed.
49 ExpectedOutcome onMakeClosed(GrRecordingContext*, SkIRect* targetUpdateBounds) override;
50
51 void stencilAtlasRect(GrRecordingContext*, const SkRect&, const SkPMColor4f&,
52 const GrUserStencilSettings*);
53 void addAtlasDrawOp(GrOp::Owner, bool usesMSAA, const GrCaps&);
54
55 // Executes the GrOpsTask and resolves msaa if needed.
56 bool onExecute(GrOpFlushState* flushState) override;
57
58 SkPath* getUberPath(SkPathFillType fillType, bool antialias) {
59 int idx = (int)antialias << 1;
60 idx |= (int)fillType & 1;
61 return &fUberPaths[idx];
62 }
63
64 const std::unique_ptr<GrDynamicAtlas> fDynamicAtlas;
65 SkPath fUberPaths[4]; // 2 fillTypes * 2 antialias modes.
66};
67
68#endif