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 #include "src/gpu/ccpr/GrCCAtlas.h"
9
10 #include "include/private/SkTPin.h"
11 #include "src/core/SkIPoint16.h"
12 #include "src/gpu/GrOnFlushResourceProvider.h"
13
choose_initial_atlas_size(const GrCCAtlas::Specs & specs)14 static SkISize choose_initial_atlas_size(const GrCCAtlas::Specs& specs) {
15 // Begin with the first pow2 dimensions whose area is theoretically large enough to contain the
16 // pending paths, favoring height over width if necessary.
17 int log2area = SkNextLog2(std::max(specs.fApproxNumPixels, 1));
18 int height = 1 << ((log2area + 1) / 2);
19 int width = 1 << (log2area / 2);
20
21 width = SkTPin(width, specs.fMinTextureSize, specs.fMaxPreferredTextureSize);
22 height = SkTPin(height, specs.fMinTextureSize, specs.fMaxPreferredTextureSize);
23
24 return SkISize::Make(width, height);
25 }
26
choose_max_atlas_size(const GrCCAtlas::Specs & specs,const GrCaps & caps)27 static int choose_max_atlas_size(const GrCCAtlas::Specs& specs, const GrCaps& caps) {
28 return (std::max(specs.fMinHeight, specs.fMinWidth) <= specs.fMaxPreferredTextureSize) ?
29 specs.fMaxPreferredTextureSize : caps.maxRenderTargetSize();
30 }
31
GrCCAtlas(const Specs & specs,const GrCaps & caps)32 GrCCAtlas::GrCCAtlas(const Specs& specs, const GrCaps& caps)
33 : GrDynamicAtlas(GrColorType::kAlpha_8, InternalMultisample::kYes,
34 choose_initial_atlas_size(specs), choose_max_atlas_size(specs, caps),
35 caps) {
36 SkASSERT(specs.fMaxPreferredTextureSize > 0);
37 }
38
~GrCCAtlas()39 GrCCAtlas::~GrCCAtlas() {
40 }
41