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 | |
Cary Clark | a4083c9 | 2017-09-15 11:59:23 -0400 | [diff] [blame] | 11 | #include "SkColorData.h" |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 12 | #include "SkMatrix.h" |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 13 | #include "SkVertices.h" |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 14 | |
| 15 | class SK_API SkPatchUtils { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 16 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 17 | public: |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 18 | // Enums for control points based on the order specified in the constructor (clockwise). |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 19 | enum { |
| 20 | kNumCtrlPts = 12, |
| 21 | kNumCorners = 4, |
| 22 | kNumPtsCubic = 4 |
| 23 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 24 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 25 | /** |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 26 | * Get the points corresponding to the top cubic of cubics. |
| 27 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 28 | static void GetTopCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 29 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Get the points corresponding to the bottom cubic of cubics. |
| 32 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 33 | static void GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 34 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Get the points corresponding to the left cubic of cubics. |
| 37 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 38 | static void GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 39 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Get the points corresponding to the right cubic of cubics. |
| 42 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 43 | static void GetRightCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 44 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 45 | /** |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 46 | * 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] | 47 | */ |
Mike Reed | 4ebb43e | 2017-04-05 11:06:15 -0400 | [diff] [blame] | 48 | static SkISize GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 49 | |
| 50 | 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] | 51 | const SkPoint texCoords[4], int lodX, int lodY, |
Mike Reed | e8fa427 | 2017-05-23 14:19:45 -0400 | [diff] [blame] | 52 | bool interpColorsLinearly = false); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | #endif |