Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrDynamicAtlas.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 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 GrDynamicAtlas_DEFINED
9#define GrDynamicAtlas_DEFINED
10
13
17struct SkIPoint16;
18struct SkIRect;
19
20/**
21 * This class implements a dynamic size skgpu::Rectanizer that grows until it reaches the
22 * implementation-dependent max texture size. When finalized, it also creates and stores a
23 * GrTextureProxy for the underlying atlas.
24 */
26public:
27 // As long as GrSurfaceOrigin exists, we just have to decide on one for the atlas texture.
29 inline static constexpr int kPadding = 1; // Amount of padding below and to the right of each
30 // path.
31
34
35 enum class InternalMultisample : bool {
36 kNo = false,
37 kYes = true
38 };
39
43 const GrCaps&,
45
48 kPow2
49 };
50
52 int maxAtlasSize, const GrCaps&,
54 virtual ~GrDynamicAtlas();
55
56 void reset(SkISize initialSize, const GrCaps& desc);
57
58 GrColorType colorType() const { return fColorType; }
59 int maxAtlasSize() const { return fMaxAtlasSize; }
60 GrTextureProxy* textureProxy() const { return fTextureProxy.get(); }
63 bool isInstantiated() const { return fTextureProxy->isInstantiated(); }
64
65 // Attempts to add a rect to the atlas. Returns true if successful, along with the rect's
66 // top-left location in the atlas.
67 bool addRect(int width, int height, SkIPoint16* location);
68 const SkISize& drawBounds() { return fDrawBounds; }
69
70 // Instantiates our texture proxy for the atlas. After this call, it is no longer valid to call
71 // addRect(), setUserBatchID(), or this method again.
72 //
73 // 'backingTexture', if provided, is a renderable texture with which to instantiate our proxy.
74 // If null then we will create a texture using the resource provider. The purpose of this param
75 // is to provide a guaranteed way to recycle textures from previous atlases.
76 [[nodiscard]] bool instantiate(GrOnFlushResourceProvider*,
77 sk_sp<GrTexture> backingTexture = nullptr);
78
79private:
80 class Node;
81
82 Node* makeNode(Node* previous, int l, int t, int r, int b);
83 bool internalPlaceRect(int w, int h, SkIPoint16* loc);
84
86 const InternalMultisample fInternalMultisample;
87 const int fMaxAtlasSize;
88 const RectanizerAlgorithm fRectanizerAlgorithm;
89 int fWidth;
90 int fHeight;
91 SkISize fDrawBounds;
92
93 SkSTArenaAllocWithReset<512> fNodeAllocator;
94 Node* fTopNode = nullptr;
95
96 sk_sp<GrTextureProxy> fTextureProxy;
97 sk_sp<GrTexture> fBackingTexture;
98};
99
100#endif
m reset()
GrColorType
GrSurfaceOrigin
Definition GrTypes.h:147
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
SkColorType fColorType
virtual ~GrDynamicAtlas()
GrColorType colorType() const
GrSurfaceProxyView writeView(const GrCaps &) const
GrTextureProxy * textureProxy() const
const SkISize & drawBounds()
static constexpr GrSurfaceOrigin kTextureOrigin
static constexpr int kPadding
bool instantiate(GrOnFlushResourceProvider *, sk_sp< GrTexture > backingTexture=nullptr)
GrSurfaceProxy::LazyInstantiateCallback LazyInstantiateAtlasCallback
static sk_sp< GrTextureProxy > MakeLazyAtlasProxy(LazyInstantiateAtlasCallback &&, GrColorType colorType, InternalMultisample, const GrCaps &, GrSurfaceProxy::UseAllocator)
bool addRect(int width, int height, SkIPoint16 *location)
bool isInstantiated() const
GrSurfaceProxyView readView(const GrCaps &) const
int maxAtlasSize() const
std::function< LazyCallbackResult(GrResourceProvider *, const LazySurfaceDesc &)> LazyInstantiateCallback
bool isInstantiated() const
T * get() const
Definition SkRefCnt.h:303
static bool b
Definition dart.idl:29
SkScalar w
SkScalar h
int32_t height
int32_t width