Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 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 GrCCAtlas_DEFINED |
| 9 | #define GrCCAtlas_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 GrCCAtlas { |
| 27 | public: |
| 28 | static constexpr int kMinSize = 1024; |
| 29 | |
| 30 | GrCCAtlas(const GrCaps&, int minWidth, int minHeight); |
| 31 | ~GrCCAtlas(); |
| 32 | |
| 33 | bool addRect(int devWidth, int devHeight, SkIPoint16* loc); |
| 34 | const SkISize& drawBounds() { return fDrawBounds; } |
| 35 | |
| 36 | sk_sp<GrRenderTargetContext> SK_WARN_UNUSED_RESULT |
| 37 | finalize(GrOnFlushResourceProvider*, std::unique_ptr<GrDrawOp> atlasOp); |
| 38 | |
| 39 | GrTextureProxy* textureProxy() const { return fTextureProxy.get(); } |
| 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 |