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 "src/gpu/GrDynamicAtlas.h"
12 #include "src/gpu/GrTBlockList.h"
13
14 class GrCCCachedAtlas;
15
16 /**
17 * GrDynamicAtlas with CCPR caching capabilities.
18 */
19 class GrCCAtlas : public GrDynamicAtlas {
20 public:
21 // This struct encapsulates the minimum and desired requirements for an atlas, as well as an
22 // approximate number of pixels to help select a good initial size.
23 struct Specs {
24 int fMaxPreferredTextureSize = 0;
25 int fMinTextureSize = 0;
26 int fMinWidth = 0; // If there are 100 20x10 paths, this should be 20.
27 int fMinHeight = 0; // If there are 100 20x10 paths, this should be 10.
28 int fApproxNumPixels = 0;
29
30 // Add space for a rect in the desired atlas specs.
31 void accountForSpace(int width, int height);
32 };
33
MakeLazyAtlasProxy(LazyInstantiateAtlasCallback && callback,const GrCaps & caps,GrSurfaceProxy::UseAllocator useAllocator)34 static sk_sp<GrTextureProxy> MakeLazyAtlasProxy(LazyInstantiateAtlasCallback&& callback,
35 const GrCaps& caps,
36 GrSurfaceProxy::UseAllocator useAllocator) {
37 return GrDynamicAtlas::MakeLazyAtlasProxy(std::move(callback),
38 GrColorType::kAlpha_8,
39 InternalMultisample::kYes,
40 caps,
41 useAllocator);
42 }
43
44 GrCCAtlas(const Specs&, const GrCaps&);
45 ~GrCCAtlas() override;
46 };
47
accountForSpace(int width,int height)48 inline void GrCCAtlas::Specs::accountForSpace(int width, int height) {
49 fMinWidth = std::max(width, fMinWidth);
50 fMinHeight = std::max(height, fMinHeight);
51 fApproxNumPixels += (width + kPadding) * (height + kPadding);
52 }
53
54 #endif
55