blob: bf17c05f8c8166b35aaa9699630fe535f6809783 [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;
15class GrDrawOp;
16class GrOnFlushResourceProvider;
17class GrRenderTargetContext;
18class GrTextureProxy;
19struct 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 */
26class GrCCAtlas {
27public:
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
41private:
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