Debian Codegraph @

src/gpu/ganesh/ops/SmallPathShapeData.cpp

raw
1 /*
2 * Copyright 2020 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/ganesh/ops/SmallPathShapeData.h"
9
10 #include "include/core/SkMatrix.h"
11 #include "include/core/SkScalar.h"
12 #include "include/private/base/SkFixed.h"
13 #include "src/base/SkFloatBits.h"
14 #include "src/gpu/ganesh/GrStyle.h"
15 #include "src/gpu/ganesh/geometry/GrStyledShape.h"
16
17 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
18
19 namespace skgpu::ganesh {
20
21 SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, uint32_t dim) {
22 // Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
23 // relevant styling information.
24 SkASSERT(shape.style().isSimpleFill());
25 SkASSERT(shape.hasUnstyledKey());
26 int shapeKeySize = shape.unstyledKeySize();
27 fKey.reset(1 + shapeKeySize);
28 fKey[0] = dim;
29 shape.writeUnstyledKey(&fKey[1]);
30 }
31
32 SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, const SkMatrix& ctm) {
33 // Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
34 // relevant styling information.
35 SkASSERT(shape.style().isSimpleFill());
36 SkASSERT(shape.hasUnstyledKey());
37 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
38 SkScalar sx = ctm.get(SkMatrix::kMScaleX);
39 SkScalar sy = ctm.get(SkMatrix::kMScaleY);
40 SkScalar kx = ctm.get(SkMatrix::kMSkewX);
41 SkScalar ky = ctm.get(SkMatrix::kMSkewY);
42 SkScalar tx = ctm.get(SkMatrix::kMTransX);
43 SkScalar ty = ctm.get(SkMatrix::kMTransY);
44 // Allow 8 bits each in x and y of subpixel positioning.
45 tx -= SkScalarFloorToScalar(tx);
46 ty -= SkScalarFloorToScalar(ty);
47 SkFixed fracX = SkScalarToFixed(tx) & 0x0000FF00;
48 SkFixed fracY = SkScalarToFixed(ty) & 0x0000FF00;
49 int shapeKeySize = shape.unstyledKeySize();
50 fKey.reset(5 + shapeKeySize);
51 fKey[0] = SkFloat2Bits(sx);
52 fKey[1] = SkFloat2Bits(sy);
53 fKey[2] = SkFloat2Bits(kx);
54 fKey[3] = SkFloat2Bits(ky);
55 fKey[4] = fracX | (fracY >> 8);
56 shape.writeUnstyledKey(&fKey[5]);
57 }
58
59 } // namespace skgpu::ganesh
60
61 #endif // SK_ENABLE_OPTIMIZE_SIZE