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; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 15 | class GrCCPathParser; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 16 | class GrDrawOp; |
| 17 | class GrOnFlushResourceProvider; |
| 18 | class GrRenderTargetContext; |
| 19 | class GrTextureProxy; |
| 20 | struct SkIPoint16; |
| 21 | |
| 22 | /** |
| 23 | * This class implements a dynamic size GrRectanizer that grows until it reaches the implementation- |
| 24 | * dependent max texture size. When finalized, it also creates and stores a GrTextureProxy for the |
| 25 | * underlying atlas. |
| 26 | */ |
| 27 | class GrCCAtlas { |
| 28 | public: |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 29 | using CoverageCountBatchID = int; |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 30 | static constexpr int kPadding = 1; // Amount of padding below and to the right of each path. |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 31 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 32 | // This struct encapsulates the minimum and desired requirements for an atlas, as well as an |
| 33 | // approximate number of pixels to help select a good initial size. |
| 34 | struct Specs { |
| 35 | int fMaxPreferredTextureSize = 0; |
| 36 | int fMinTextureSize = 0; |
| 37 | int fMinWidth = 0; // If there are 100 20x10 paths, this should be 20. |
| 38 | int fMinHeight = 0; // If there are 100 20x10 paths, this should be 10. |
| 39 | int fApproxNumPixels = 0; |
| 40 | |
| 41 | // Add space for a rect in the desired atlas specs. |
| 42 | void accountForSpace(int width, int height); |
| 43 | }; |
| 44 | |
| 45 | GrCCAtlas(const Specs&); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 46 | ~GrCCAtlas(); |
| 47 | |
| 48 | bool addRect(int devWidth, int devHeight, SkIPoint16* loc); |
| 49 | const SkISize& drawBounds() { return fDrawBounds; } |
| 50 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 51 | void setCoverageCountBatchID(CoverageCountBatchID batchID) { |
| 52 | SkASSERT(!fCoverageCountBatchID); |
| 53 | SkASSERT(!fTextureProxy); |
| 54 | fCoverageCountBatchID = batchID; |
| 55 | } |
| 56 | |
| 57 | sk_sp<GrRenderTargetContext> SK_WARN_UNUSED_RESULT finalize(GrOnFlushResourceProvider*, |
| 58 | sk_sp<const GrCCPathParser>); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 59 | |
| 60 | GrTextureProxy* textureProxy() const { return fTextureProxy.get(); } |
| 61 | |
| 62 | private: |
| 63 | class Node; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 64 | class DrawCoverageCountOp; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 65 | |
| 66 | bool internalPlaceRect(int w, int h, SkIPoint16* loc); |
| 67 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 68 | const int fMaxTextureSize; |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 69 | int fWidth, fHeight; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 70 | std::unique_ptr<Node> fTopNode; |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 71 | SkISize fDrawBounds = {0, 0}; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 72 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 73 | CoverageCountBatchID fCoverageCountBatchID SkDEBUGCODE(= 0); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 74 | sk_sp<GrTextureProxy> fTextureProxy; |
| 75 | }; |
| 76 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 77 | inline void GrCCAtlas::Specs::accountForSpace(int width, int height) { |
| 78 | fMinWidth = SkTMax(width, fMinWidth); |
| 79 | fMinHeight = SkTMax(height, fMinHeight); |
| 80 | fApproxNumPixels += (width + kPadding) * (height + kPadding); |
| 81 | } |
| 82 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 83 | #endif |