Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkBackingFit.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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
9
11#include "src/base/SkMathPriv.h"
12
13#include <algorithm>
14
15namespace skgpu {
16
18 // Map 'value' to a larger multiple of 2. Values <= 'kMagicTol' will pop up to
19 // the next power of 2. Those above 'kMagicTol' will only go up half the floor power of 2.
20 auto adjust = [](int value) {
21 constexpr int kMinApproxSize = 16;
22 constexpr int kMagicTol = 1024;
23
24 value = std::max(kMinApproxSize, value);
25
26 if (SkIsPow2(value)) {
27 return value;
28 }
29
30 int ceilPow2 = SkNextPow2(value);
31 if (value <= kMagicTol) {
32 return ceilPow2;
33 }
34
35 int floorPow2 = ceilPow2 >> 1;
36 int mid = floorPow2 + (floorPow2 >> 1);
37
38 if (value <= mid) {
39 return mid;
40 }
41 return ceilPow2;
42 };
43
44 return {adjust(size.width()), adjust(size.height())};
45}
46
47} // namespace skgpu
static int SkNextPow2(int value)
Definition SkMathPriv.h:272
constexpr bool SkIsPow2(T value)
Definition SkMath.h:51
uint8_t value
SkISize GetApproxSize(SkISize size)