• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ops/SmallPathShapeData.h"
9 
10 #include "src/gpu/geometry/GrStyledShape.h"
11 
12 namespace skgpu::v1 {
13 
SmallPathShapeDataKey(const GrStyledShape & shape,uint32_t dim)14 SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, uint32_t dim) {
15     // 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 
SmallPathShapeDataKey(const GrStyledShape & shape,const SkMatrix & ctm)25 SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, const SkMatrix& ctm) {
26     // 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 }
51 
52 } // namespace skgpu::v1
53