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