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