Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(945)

Side by Side Diff: include/core/SkPatchGrid.h

Issue 451723003: SkPatchGrid interface (after SkPatch/SkPicture rebase). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Renamed GM to SKPatchGridGM and removed last mesh references in comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 SkPatchGrid_DEFINED
9 #define SkPatchGrid_DEFINED
10
11 #include "SkPatch.h"
12 #include "SkCanvas.h"
egdaniel 2014/08/08 18:45:41 annoying nit: but alphabetize these please
dandov 2014/08/08 19:00:55 Done.
13
14 /**
15 * Class that represents a grid of patches. Adjacent patches share their corners and a color is
16 * specified at each one of them. The colors are bilinearly interpolated across the patch.
17 *
18 * This implementation defines a bidimensional array of patches. There are 3 arr ays to store the
19 * control points of the patches to avoid storing repeated data since there are several points
20 * shared between adjacent patches.
21 *
22 * The array fCornerPts stores the corner control points of the patches.
23 * The array fHrzPts holds the intermidiate control points of the top and bottom curves of a patch.
24 * The array fVrtPts holds the intermidiate control points of the left and right curves of a patch.
25 * The array fCornerColors holds the corner colors in the same format as fCorner Pts.
26 *
27 * fCornerPts fHrzPts fVrtPts
28 * -------------- ------------------- --------------
29 * | C0 | C1 | C2 | | H0 | H1 | H2 | H3 | | V0 | V1 | V2 |
30 * -------------- ------------------ ---------------
31 * | C3 | C4 | C5 | | H4 | H5 | H6 | H7 | | V4 | V5 | V6 |
32 * -------------- ------------------- --------------
33 * | C6 | C7 | C8 | | H8 | H9 | H10| H11| | V6 | V7 | V8 |
34 * -------------- ------------------- --------------
35 * | V9 | V10| V11|
36 * --------------
37 *
38 * With the above configuration we would have a 2x2 grid of patches:
39 * H0 H1 H2 H3
40 * / \/ \
41 * C0-------C1-------C2
42 * /| | |\
43 * v0 | v1 | v2
44 * v3 | V4 | v5
45 * \| | |/
46 * C3-H4-H5-C4-H6-H7-C5
47 * /| | |\
48 * v6 | v7 | v8
49 * v9 | v10 | v11
50 * \| | |/
51 * C6-------C7-------C8
52 * \ / \ /
53 * H8 H9 H10 H11
54 *
55 * When trying to get a patch at a certain position it justs builds it with the corresponding
56 * points.
57 * When adding a patch it tries to add the points at their corresponding positio n trying to comply
58 * with the adjacent points or overwriting them.
59 *
60 * Based the idea on the SVG2 spec for mesh gradients in which a grid of patches is build as in the
61 * the following example:
62 * <meshGradient x="100" y="100">
63 * <meshRow>
64 * <meshPatch>
65 * <stop .../>
66 * Up to four stops in first patch. See details below.
67 * </meshPatch>
68 * <meshPatch>
69 * Any number of meshPatches in row.
70 * </meshPatch>
71 * </meshRow>
72 * <meshRow>
73 * Any number of meshRows, each with the same number of meshPatches as in the first row.
74 * </meshRow>
75 * </meshGradient>
76 */
77 class SkPatchGrid {
78
79 public:
80 SkPatchGrid(int rows, int cols);
81
82 ~SkPatchGrid();
83
84 /**
85 * Add a patch at location (x,y) overwriting the previous patch and shared p oints.
86 */
87 bool setPatch(int x, int y, const SkPatch& patch);
88 bool setPatch(int x, int y, const SkPoint ctrlPts[12], const SkColor colors[ 4]);
89
90 /**
91 * Get patch at location (x,y). If the patch is not NULL it sets patch's
92 * control points and colors to the corresponding values.
93 */
94 bool getPatch(int x, int y, SkPatch* patch) const;
95
96 /**
97 * Resets the grid of patches to contain rows and cols of patches.
98 */
99 void reset(int rows, int cols);
100
101 /**
102 * Draws the grid of patches. The patches are drawn starting at patch (0,0) drawing columns, so
103 * for a 2x2 grid the order would be (0,0)->(0,1)->(1,0)->(1,1). The order f ollows the order
104 * of the parametric coordinates of the coons patch.
105 */
106 void draw(SkCanvas* canvas, SkPaint& paint);
107
108 /**
109 * Get the dimensions of the grid of patches.
110 */
111 SkISize getDimensions() const {
112 return SkISize::Make(fCols, fRows);
113 }
114
115 private:
116 int fRows, fCols;
117 SkPoint* fCornerPts;
118 SkColor* fCornerColors;
119 SkPoint* fHrzCtrlPts;
120 SkPoint* fVrtCtrlPts;
121 };
122
123
124 #endif
OLDNEW
« no previous file with comments | « gyp/gmslides.gypi ('k') | src/core/SkPatchGrid.cpp » ('j') | src/core/SkPatchGrid.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698