• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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 GrCCPRAtlas_DEFINED
9 #define GrCCPRAtlas_DEFINED
10 
11 #include "SkRefCnt.h"
12 #include "SkSize.h"
13 
14 class GrCaps;
15 class GrDrawOp;
16 class GrOnFlushResourceProvider;
17 class GrRenderTargetContext;
18 class GrTextureProxy;
19 struct SkIPoint16;
20 
21 /**
22  * This class implements a dynamic size GrRectanizer that grows until it reaches the implementation-
23  * dependent max texture size. When finalized, it also creates and stores a GrTextureProxy for the
24  * underlying atlas.
25  */
26 class GrCCPRAtlas {
27 public:
28     static constexpr int kMinSize = 1024;
29 
30     GrCCPRAtlas(const GrCaps&, int minWidth, int minHeight);
31     ~GrCCPRAtlas();
32 
33     bool addRect(int devWidth, int devHeight, SkIPoint16* loc);
drawBounds()34     const SkISize& drawBounds() { return fDrawBounds; }
35 
36     sk_sp<GrRenderTargetContext> SK_WARN_UNUSED_RESULT finalize(GrOnFlushResourceProvider*,
37                                                                 std::unique_ptr<GrDrawOp> atlasOp);
38 
textureProxy()39     sk_sp<GrTextureProxy> textureProxy() const { return fTextureProxy; }
40 
41 private:
42     class Node;
43 
44     bool internalPlaceRect(int w, int h, SkIPoint16* loc);
45 
46     const int                                fMaxAtlasSize;
47 
48     int                                      fWidth;
49     int                                      fHeight;
50     SkISize                                  fDrawBounds;
51     std::unique_ptr<Node>                    fTopNode;
52 
53     sk_sp<GrTextureProxy>                    fTextureProxy;
54 };
55 
56 #endif
57