blob: ee7a1f6dbcb7bbd1681da297d6b53472ec124fd1 [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
15class SK_API SkPatchUtils {
halcanary9d524f22016-03-29 09:03:52 -070016
dandovecfff212014-08-04 10:02:00 -070017public:
dandovb3c9d1c2014-08-12 08:34:29 -070018 // Enums for control points based on the order specified in the constructor (clockwise).
dandovb3c9d1c2014-08-12 08:34:29 -070019 enum {
20 kNumCtrlPts = 12,
21 kNumCorners = 4,
22 kNumPtsCubic = 4
23 };
halcanary9d524f22016-03-29 09:03:52 -070024
dandovb3c9d1c2014-08-12 08:34:29 -070025 /**
dandovb3c9d1c2014-08-12 08:34:29 -070026 * Get the points corresponding to the top cubic of cubics.
27 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040028 static void GetTopCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070029
dandovb3c9d1c2014-08-12 08:34:29 -070030 /**
31 * Get the points corresponding to the bottom cubic of cubics.
32 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040033 static void GetBottomCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070034
dandovb3c9d1c2014-08-12 08:34:29 -070035 /**
36 * Get the points corresponding to the left cubic of cubics.
37 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040038 static void GetLeftCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070039
dandovb3c9d1c2014-08-12 08:34:29 -070040 /**
41 * Get the points corresponding to the right cubic of cubics.
42 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040043 static void GetRightCubic(const SkPoint cubics[12], SkPoint points[4]);
halcanary9d524f22016-03-29 09:03:52 -070044
dandovb3c9d1c2014-08-12 08:34:29 -070045 /**
Mike Reed4ebb43e2017-04-05 11:06:15 -040046 * Method that calculates a level of detail (number of subdivisions) for a patch in both axis.
dandovb3c9d1c2014-08-12 08:34:29 -070047 */
Mike Reed4ebb43e2017-04-05 11:06:15 -040048 static SkISize GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix);
Mike Reed795c5ea2017-03-17 14:29:05 -040049
50 static sk_sp<SkVertices> MakeVertices(const SkPoint cubics[12], const SkColor colors[4],
Mike Reed435071e2017-05-23 11:22:56 -040051 const SkPoint texCoords[4], int lodX, int lodY,
Mike Reede8fa4272017-05-23 14:19:45 -040052 bool interpColorsLinearly = false);
dandovecfff212014-08-04 10:02:00 -070053};
54
55#endif