dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | #ifndef SkPatchUtils_DEFINED |
| 9 | #define SkPatchUtils_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkMatrix.h" |
| 12 | #include "include/core/SkVertices.h" |
| 13 | #include "include/private/SkColorData.h" |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 14 | |
Brian Osman | e0a9962 | 2018-07-09 16:12:27 -0400 | [diff] [blame] | 15 | class SkColorSpace; |
| 16 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 17 | class SK_API SkPatchUtils { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 18 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 19 | public: |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 20 | // Enums for control points based on the order specified in the constructor (clockwise). |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 21 | enum { |
| 22 | kNumCtrlPts = 12, |
| 23 | kNumCorners = 4, |
| 24 | kNumPtsCubic = 4 |
| 25 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 26 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 27 | /** |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 28 | * Get the points corresponding to the top cubic of cubics. |
| 29 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 30 | static void GetTopCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 31 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Get the points corresponding to the bottom cubic of cubics. |
| 34 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 35 | static void GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 36 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Get the points corresponding to the left cubic of cubics. |
| 39 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 40 | static void GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 41 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Get the points corresponding to the right cubic of cubics. |
| 44 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 45 | static void GetRightCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 46 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 47 | /** |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 48 | * Method that calculates a level of detail (number of subdivisions) for a patch in both axis. |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 49 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 50 | static SkISize GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 51 | |
| 52 | static sk_sp<SkVertices> MakeVertices(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | 435071e | 2017-05-23 11:22:56 -0400 | [diff] [blame] | 53 | const SkPoint texCoords[4], int lodX, int lodY, |
Brian Osman | e0a9962 | 2018-07-09 16:12:27 -0400 | [diff] [blame] | 54 | SkColorSpace* colorSpace = nullptr); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | #endif |