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