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

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: Changed name to SkPatchGrid 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 SkMeshGradient_DEFINED
9 #define SkMeshGradient_DEFINED
10
11 #include "SkPatch.h"
12 #include "SkCanvas.h"
13
14 /**
15 * Class that represents a Mesh Gradient. A mesh gradient is an array of coons p atches, adjacent
egdaniel 2014/08/08 14:39:04 no longer gradient, fix comment
dandov 2014/08/08 18:31:45 Done.
16 * patches share their corners and a color is specified at each one of them. The colors are
17 * bilinearly interpolated across the patch.
18 *
19 * This implementation defines a bidimensional array of patches. There are 3 arr ays to store the
20 * control points of the patches to avoid storing repeated data since there are several points
21 * shared between adjacent patches.
22 *
23 * The array fCornerPts stores the corner control points of the patches.
24 * The array fHrzPts holds the intermidiate control points of the top and bottom curves of a patch.
25 * The array fVrtPts holds the intermidiate control points of the left and right curves of a patch.
26 * The array fCornerColors holds the corner colors in the same format as fCorner Pts.
27 *
28 * fCornerPts fHrzPts fVrtPts
29 * -------------- ------------------- --------------
30 * | C0 | C1 | C2 | | H0 | H1 | H2 | H3 | | V0 | V1 | V2 |
31 * -------------- ------------------ ---------------
32 * | C3 | C4 | C5 | | H4 | H5 | H6 | H7 | | V4 | V5 | V6 |
33 * -------------- ------------------- --------------
34 * | C6 | C7 | C8 | | H8 | H9 | H10| H11| | V6 | V7 | V8 |
35 * -------------- ------------------- --------------
36 * | V9 | V10| V11|
37 * --------------
38 *
39 * With the above configuration we would have a 2x2 grid of patches:
40 * H0 H1 H2 H3
41 * / \/ \
42 * C0-------C1-------C2
43 * /| | |\
44 * v0 | v1 | v2
45 * v3 | V4 | v5
46 * \| | |/
47 * C3-H4-H5-C4-H6-H7-C5
48 * /| | |\
49 * v6 | v7 | v8
50 * v9 | v10 | v11
51 * \| | |/
52 * C6-------C7-------C8
53 * \ / \ /
54 * H8 H9 H10 H11
55 *
56 * When trying to get a patch at a certain position it justs builds it with the corresponding
57 * points.
58 * When adding a patch it tries to add the points at their corresponding positio n trying to comply
59 * with the adjacent points or overwriting them.
60 *
61 * Based the idea on the SVG2 spec:
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 void getPatch(int x, int y, SkPatch* patch) const;
egdaniel 2014/08/08 14:39:04 maybe have this return a bool as well so it is kno
dandov 2014/08/08 18:31:45 Done. returns false in case the coordinates x,y ar
95
96 /**
97 * Resets the mesh gradient to contain rows and cols of patches. The main di fference between
98 * this and resize is that resize keeps the previous values of control point s and colors and
egdaniel 2014/08/08 14:39:04 no more resize so fix comment
dandov 2014/08/08 18:31:45 Done.
99 * this doesn't.
100 */
101 void reset(int rows, int cols);
102
103 /**
104 * Draws the mesh gradient.
105 */
106 void draw(SkCanvas* canvas, SkPaint& paint);
egdaniel 2014/08/08 14:39:04 Since we are deciding the draw order of the patche
dandov 2014/08/08 18:31:45 Done.
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
« gm/meshgradient.cpp ('K') | « gyp/gmslides.gypi ('k') | src/core/SkPatchGrid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698