blob: 1f8ed0b8b1194467691398638edbc76a9f646bd4 [file] [log] [blame]
Robert Phillips5b68ed42020-08-10 14:46:42 -04001/*
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
Robert Phillipsde60d7a2021-09-13 17:17:45 -04008#include "src/gpu/ops/SmallPathShapeData.h"
Robert Phillips5b68ed42020-08-10 14:46:42 -04009
10#include "src/gpu/geometry/GrStyledShape.h"
11
Robert Phillipsde60d7a2021-09-13 17:17:45 -040012namespace skgpu::v1 {
13
14SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, uint32_t dim) {
Robert Phillips5b68ed42020-08-10 14:46:42 -040015 // Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
16 // relevant styling information.
17 SkASSERT(shape.style().isSimpleFill());
18 SkASSERT(shape.hasUnstyledKey());
19 int shapeKeySize = shape.unstyledKeySize();
20 fKey.reset(1 + shapeKeySize);
21 fKey[0] = dim;
22 shape.writeUnstyledKey(&fKey[1]);
23}
24
Robert Phillipsde60d7a2021-09-13 17:17:45 -040025SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, const SkMatrix& ctm) {
Robert Phillips5b68ed42020-08-10 14:46:42 -040026 // Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
27 // relevant styling information.
28 SkASSERT(shape.style().isSimpleFill());
29 SkASSERT(shape.hasUnstyledKey());
30 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
31 SkScalar sx = ctm.get(SkMatrix::kMScaleX);
32 SkScalar sy = ctm.get(SkMatrix::kMScaleY);
33 SkScalar kx = ctm.get(SkMatrix::kMSkewX);
34 SkScalar ky = ctm.get(SkMatrix::kMSkewY);
35 SkScalar tx = ctm.get(SkMatrix::kMTransX);
36 SkScalar ty = ctm.get(SkMatrix::kMTransY);
37 // Allow 8 bits each in x and y of subpixel positioning.
38 tx -= SkScalarFloorToScalar(tx);
39 ty -= SkScalarFloorToScalar(ty);
40 SkFixed fracX = SkScalarToFixed(tx) & 0x0000FF00;
41 SkFixed fracY = SkScalarToFixed(ty) & 0x0000FF00;
42 int shapeKeySize = shape.unstyledKeySize();
43 fKey.reset(5 + shapeKeySize);
44 fKey[0] = SkFloat2Bits(sx);
45 fKey[1] = SkFloat2Bits(sy);
46 fKey[2] = SkFloat2Bits(kx);
47 fKey[3] = SkFloat2Bits(ky);
48 fKey[4] = fracX | (fracY >> 8);
49 shape.writeUnstyledKey(&fKey[5]);
50}
Robert Phillipsde60d7a2021-09-13 17:17:45 -040051
52} // namespace skgpu::v1