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