Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
AtlasPathRenderer.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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 AtlasPathRenderer_DEFINED
9#define AtlasPathRenderer_DEFINED
10
11#include "include/gpu/GrTypes.h"
12#include "src/core/SkIPoint16.h"
13#include "src/core/SkTHash.h"
18
19class GrOp;
21
22namespace skgpu::ganesh {
23
24class AtlasRenderTask;
25
26// Draws paths by first rendering their coverage mask into an offscreen atlas.
28public:
29 static bool IsSupported(GrRecordingContext*);
30
31 // Returns a GrAtlasPathRenderer if it is supported, otherwise null.
33
34 const char* name() const override { return "GrAtlasPathRenderer"; }
35
36 // Returns a fragment processor that modulates inputFP by the given deviceSpacePath's coverage,
37 // implemented using an internal atlas.
38 //
39 // Returns 'inputFP' wrapped in GrFPFailure() if the path was too large, or if the current atlas
40 // is full and already used by either opBeingClipped or inputFP. (Currently, "too large" means
41 // larger than fMaxAtlasSize in either dimension, more than 256^2 total pixels, or more than
42 // 128^2 total pixels if the surfaceDrawContext supports MSAA or DMSAA.)
43 //
44 // Also returns GrFPFailure() if the view matrix has perspective.
46 const GrOp* opBeingClipped,
47 std::unique_ptr<GrFragmentProcessor> inputFP,
48 const SkIRect& drawBounds,
49 const SkMatrix&,
50 const SkPath&);
51
52private:
53 // The atlas is not compatible with DDL. We can only use it on direct contexts.
55
59
60 CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
61
62 bool onDrawPath(const DrawPathArgs&) override;
63
64 // Returns true if the given device-space path bounds are small enough to fit in an atlas and to
65 // benefit from atlasing. (Currently, "small enough" means no larger than fMaxAtlasSize in
66 // either dimension, no more than 256^2 total pixels, or no more than 128^2 total pixels if the
67 // fallbackAAType is kMSAA.)
68 bool pathFitsInAtlas(const SkRect& pathDevBounds, GrAAType fallbackAAType) const;
69
70 // Returns true if the draw being set up already uses the given atlasProxy.
71 using DrawRefsAtlasCallback = std::function<bool(const GrSurfaceProxy* atlasProxy)>;
72
73 // Adds the filled path to an atlas.
74 //
75 // pathFitsInAtlas() and is_visible() both must have returned true before making this call.
76 //
77 // Fails and returns false if the current atlas is full and already in use according to
78 // DrawRefsAtlasCallback.
79 bool addPathToAtlas(GrRecordingContext*,
80 const SkMatrix&,
81 const SkPath&,
82 const SkRect& pathDevBounds,
83 SkIRect* devIBounds,
84 SkIPoint16* locationInAtlas,
85 bool* transposedInAtlas,
86 const DrawRefsAtlasCallback&);
87
88 // Instantiates texture(s) for all atlases we've created since the last flush. Atlases that are
89 // the same size will be instantiated with the same backing texture.
90 bool preFlush(GrOnFlushResourceProvider*) override;
91
92 float fAtlasMaxSize = 0;
93 float fAtlasMaxPathWidth = 0;
94 int fAtlasInitialSize = 0;
95
96 // A collection of all atlases we've created and used since the last flush. We instantiate these
97 // at flush time during preFlush().
99
100 // This simple cache remembers the locations of cacheable path masks in the most recent atlas.
101 // Its main motivation is for clip paths.
102 struct AtlasPathKey {
103 void set(const SkMatrix&, const SkPath&);
104 bool operator==(const AtlasPathKey& k) const {
105 static_assert(sizeof(*this) == sizeof(uint32_t) * 8);
106 return !memcmp(this, &k, sizeof(*this));
107 }
108 uint32_t fPathGenID;
109 float fAffineMatrix[6];
110 uint32_t fFillRule;
111
113 };
114
116};
117
118} // namespace skgpu::ganesh
119
120#endif // GrAtlasPathRenderer_DEFINED
std::tuple< bool, std::unique_ptr< GrFragmentProcessor > > GrFPResult
GrAAType
Definition GrOp.h:70
static bool IsSupported(GrRecordingContext *)
bool onDrawPath(const DrawPathArgs &) override
static sk_sp< AtlasPathRenderer > Make(GrRecordingContext *rContext)
bool preFlush(GrOnFlushResourceProvider *) override
const char * name() const override
StencilSupport onGetStencilSupport(const GrStyledShape &) const override
CanDrawPath onCanDrawPath(const CanDrawPathArgs &) const override
GrFPResult makeAtlasClipEffect(const skgpu::ganesh::SurfaceDrawContext *, const GrOp *opBeingClipped, std::unique_ptr< GrFragmentProcessor > inputFP, const SkIRect &drawBounds, const SkMatrix &, const SkPath &)