blob: 1d679f2393013065bde9ff09081f9e22c53e88f0 [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'.
Chris Dalton5e332c82021-07-21 16:04:47 -060035 bool addPath(const SkMatrix&, const SkPath&, SkIPoint pathDevTopLeft, int widthInAtlas,
36 int heightInAtlas, bool transposedInAtlas, SkIPoint16* locationInAtlas);
Chris Dalton83420eb2021-06-23 18:47:09 -060037
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
46private:
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 Dalton5e332c82021-07-21 16:04:47 -060052 void addAtlasDrawOp(GrOp::Owner, const GrCaps&);
Chris Dalton83420eb2021-06-23 18:47:09 -060053
54 // Executes the GrOpsTask and resolves msaa if needed.
55 bool onExecute(GrOpFlushState* flushState) override;
56
Chris Dalton5e332c82021-07-21 16:04:47 -060057 SkPath* getUberPath(GrFillRule fillRule) {
58 return &fUberPaths[fillRule == GrFillRule::kEvenOdd];
Chris Dalton83420eb2021-06-23 18:47:09 -060059 }
60
61 const std::unique_ptr<GrDynamicAtlas> fDynamicAtlas;
Chris Dalton5e332c82021-07-21 16:04:47 -060062 SkPath fUberPaths[2]; // 2 fill rules: "nonzero" and "even/odd".
Chris Dalton83420eb2021-06-23 18:47:09 -060063};
64
65#endif