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
14class GrCaps;
15class GrCCPathParser;
16class 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    using CoverageCountBatchID = int;
30
31    GrCCAtlas(const GrCaps&, int minSize);
32    ~GrCCAtlas();
33
34    bool addRect(int devWidth, int devHeight, SkIPoint16* loc);
35    const SkISize& drawBounds() { return fDrawBounds; }
36
37    void setCoverageCountBatchID(CoverageCountBatchID batchID) {
38        SkASSERT(!fCoverageCountBatchID);
39        SkASSERT(!fTextureProxy);
40        fCoverageCountBatchID = batchID;
41    }
42
43    sk_sp<GrRenderTargetContext> SK_WARN_UNUSED_RESULT finalize(GrOnFlushResourceProvider*,
44                                                                sk_sp<const GrCCPathParser>);
45
46    GrTextureProxy* textureProxy() const { return fTextureProxy.get(); }
47
48private:
49    class Node;
50    class DrawCoverageCountOp;
51
52    bool internalPlaceRect(int w, int h, SkIPoint16* loc);
53
54    const int fMaxAtlasSize;
55
56    int fWidth, fHeight;
57    std::unique_ptr<Node> fTopNode;
58    SkISize fDrawBounds = {0, 0};
59
60    CoverageCountBatchID fCoverageCountBatchID SkDEBUGCODE(= 0);
61    sk_sp<GrTextureProxy> fTextureProxy;
62};
63
64#endif
65