blob: 0751f81f6f7202e02d3b8d4a6cdea9564b951946 [file] [log] [blame]
dandovecfff212014-08-04 10:02:00 -07001/*
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 Clarka4083c92017-09-15 11:59:23 -040011#include "SkColorData.h"
dandovecfff212014-08-04 10:02:00 -070012#include "SkMatrix.h"
Mike Reed795c5ea2017-03-17 14:29:05 -040013#include "SkVertices.h"
dandovecfff212014-08-04 10:02:00 -070014
Brian Osmane0a99622018-07-09 16:12:27 -040015class SkColorSpace;
16
dandovecfff212014-08-04 10:02:00 -070017class SK_API SkPatchUtils {
halcanary9d524f22016-03-29 09:03:52 -070018
dandovecfff212014-08-04 10:02:00 -070019public:
dandovb3c9d1c2014-08-12 08:34:29 -070020 // Enums for control points based on the order specified in the constructor (clockwise).
dandovb3c9d1c2014-08-12 08:34:29 -070021 enum {
22 kNumCtrlPts = 12,
23 kNumCorners = 4,
24 kNumPtsCubic = 4
25 };
halcanary9d524f22016-03-29 09:03:52 -070026
dandovb3c9d1c2014-08-12 08:34:29 -070027 /**
dandovb3c9d1c2014-08-12 08:34:29 -070028 * Get the points corresponding to the top cubic of cubics.
29 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040030 static void GetTopCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070031
dandovb3c9d1c2014-08-12 08:34:29 -070032 /**
33 * Get the points corresponding to the bottom cubic of cubics.
34 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040035 static void GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070036
dandovb3c9d1c2014-08-12 08:34:29 -070037 /**
38 * Get the points corresponding to the left cubic of cubics.
39 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040040 static void GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070041
dandovb3c9d1c2014-08-12 08:34:29 -070042 /**
43 * Get the points corresponding to the right cubic of cubics.
44 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040045 static void GetRightCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070046
dandovb3c9d1c2014-08-12 08:34:29 -070047 /**
Mike Reed4ebb43e2017-04-05 11:06:15 -040048 * Method that calculates a level of detail (number of subdivisions) for a patch in both axis.
dandovb3c9d1c2014-08-12 08:34:29 -070049 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040050 static SkISize GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix);
Mike Reed795c5ea2017-03-17 14:29:05 -040051
52 static sk_sp<SkVertices> MakeVertices(const SkPoint cubics[12], const SkColor colors[4],
Mike Reed435071e2017-05-23 11:22:56 -040053 const SkPoint texCoords[4], int lodX, int lodY,
Brian Osmane0a99622018-07-09 16:12:27 -040054 SkColorSpace* colorSpace = nullptr);
dandovecfff212014-08-04 10:02:00 -070055};
56
57#endif