blob: cac82af894a5b6b8ae6e6a646fb7de5a02d8f0d8 [file] [log] [blame]
Chris Dalton383a2ef2018-01-08 17:21:41 -05001/*
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
14class GrCaps;
Chris Dalton9ca27842018-01-18 12:24:50 -070015class GrCCPathParser;
Chris Dalton383a2ef2018-01-08 17:21:41 -050016class GrDrawOp;
17class GrOnFlushResourceProvider;
18class GrRenderTargetContext;
19class GrTextureProxy;
20struct 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 */
27class GrCCAtlas {
28public:
29 static constexpr int kMinSize = 1024;
30
Chris Dalton9ca27842018-01-18 12:24:50 -070031 using CoverageCountBatchID = int;
32
Chris Dalton383a2ef2018-01-08 17:21:41 -050033 GrCCAtlas(const GrCaps&, int minWidth, int minHeight);
34 ~GrCCAtlas();
35
36 bool addRect(int devWidth, int devHeight, SkIPoint16* loc);
37 const SkISize& drawBounds() { return fDrawBounds; }
38
Chris Dalton9ca27842018-01-18 12:24:50 -070039 void setCoverageCountBatchID(CoverageCountBatchID batchID) {
40 SkASSERT(!fCoverageCountBatchID);
41 SkASSERT(!fTextureProxy);
42 fCoverageCountBatchID = batchID;
43 }
44
45 sk_sp<GrRenderTargetContext> SK_WARN_UNUSED_RESULT finalize(GrOnFlushResourceProvider*,
46 sk_sp<const GrCCPathParser>);
Chris Dalton383a2ef2018-01-08 17:21:41 -050047
48 GrTextureProxy* textureProxy() const { return fTextureProxy.get(); }
49
50private:
51 class Node;
Chris Dalton9ca27842018-01-18 12:24:50 -070052 class DrawCoverageCountOp;
Chris Dalton383a2ef2018-01-08 17:21:41 -050053
54 bool internalPlaceRect(int w, int h, SkIPoint16* loc);
55
56 const int fMaxAtlasSize;
57
58 int fWidth;
59 int fHeight;
60 SkISize fDrawBounds;
61 std::unique_ptr<Node> fTopNode;
62
Chris Dalton9ca27842018-01-18 12:24:50 -070063 CoverageCountBatchID fCoverageCountBatchID SkDEBUGCODE(= 0);
Chris Dalton383a2ef2018-01-08 17:21:41 -050064 sk_sp<GrTextureProxy> fTextureProxy;
65};
66
67#endif