Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 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 * The array fExists holds bools to determine if there is an existing patch at a certain location of | |
|
egdaniel
2014/08/07 17:58:55
Can remove the comments about fExists
dandov
2014/08/07 18:11:46
Done.
| |
| 28 * the grid. | |
| 29 * | |
| 30 * fExists fCornerPts fHrzPts fVrt Pts | |
| 31 * ------- -------------- ------------------- ------- ------- | |
| 32 * | 1 | 1 | | C0 | C1 | C2 | | H0 | H1 | H2 | H3 | | V0 | V 1 | V2 | | |
| 33 * ------- -------------- ------------------ -------- ------- | |
| 34 * | 1 | 1 | | C3 | C4 | C5 | | H4 | H5 | H6 | H7 | | V4 | V 5 | V6 | | |
| 35 * ------- -------------- ------------------- ------- ------- | |
| 36 * | C6 | C7 | C8 | | H8 | H9 | H10| H11| | V6 | V 7 | V8 | | |
| 37 * -------------- ------------------- ------- ------- | |
| 38 * | V9 | V 10| V11| | |
| 39 * ------- ------- | |
| 40 * | |
| 41 * With the above configuration we would have a 2x2 grid of patches: | |
| 42 * H0 H1 H2 H3 | |
| 43 * / \/ \ | |
| 44 * C0-------C1-------C2 | |
| 45 * /| | |\ | |
| 46 * v0 | v1 | v2 | |
| 47 * v3 | V4 | v5 | |
| 48 * \| | |/ | |
| 49 * C3-H4-H5-C4-H6-H7-C5 | |
| 50 * /| | |\ | |
| 51 * v6 | v7 | v8 | |
| 52 * v9 | v10 | v11 | |
| 53 * \| | |/ | |
| 54 * C6-------C7-------C8 | |
| 55 * \ / \ / | |
| 56 * H8 H9 H10 H11 | |
| 57 * | |
| 58 * When trying to get a patch at a certain position it justs builds it with the corresponding | |
| 59 * points. | |
| 60 * When adding a patch it tries to add the points at their corresponding positio n trying to comply | |
| 61 * with the adjacent points or overwriting them. | |
| 62 * | |
| 63 * Based the idea on the SVG2 spec: | |
| 64 * <meshGradient x="100" y="100"> | |
| 65 * <meshRow> | |
| 66 * <meshPatch> | |
| 67 * <stop .../> | |
| 68 * Up to four stops in first patch. See details below. | |
| 69 * </meshPatch> | |
| 70 * <meshPatch> | |
| 71 * Any number of meshPatches in row. | |
| 72 * </meshPatch> | |
| 73 * </meshRow> | |
| 74 * <meshRow> | |
| 75 * Any number of meshRows, each with the same number of meshPatches as in the first row. | |
| 76 * </meshRow> | |
| 77 </meshGradient> | |
| 78 */ | |
| 79 class SkMeshGradient { | |
| 80 | |
| 81 public: | |
| 82 SkMeshGradient(int rows, int cols); | |
| 83 SkMeshGradient(int rows, int cols, const SkPoint* corners, const SkPoint* hr zCtrlPts, | |
| 84 const SkPoint* vrtCtrlPts, const SkColor* colors); | |
| 85 | |
| 86 ~SkMeshGradient(); | |
| 87 | |
| 88 /** | |
| 89 * Add a patch at location (x,y). The function returns false if none of the new patch's control | |
| 90 * points are set, which may be because (x,y) are out of range or because th e patch already | |
| 91 * exists at the given location and overwrite was set to false. | |
|
egdaniel
2014/08/07 17:58:55
what is overwrite here?
dandov
2014/08/07 18:11:46
Forgot to fix some of the comments. Overwrite was
| |
| 92 * If overwrite is true then the patch is always set and overwrites the valu es of adjacent | |
| 93 * patches. If it is set to false and the location is empty the function jus t set the control | |
| 94 * that are "empty" meaning that it does not overwrite values of adjacent pa tches. | |
| 95 */ | |
| 96 bool addPatch(int x, int y, const SkPatch& patch); | |
| 97 bool addPatch(int x, int y, const SkPoint ctrlPts[12], const SkColor colors[ 4]); | |
| 98 | |
| 99 /** | |
| 100 * Get patch at location (x,y). If the patch is not NULL it sets patch's | |
| 101 * control points and colors to the corresponding values. | |
| 102 */ | |
| 103 void getPatchAt(int x, int y, SkPatch* patch) const; | |
| 104 | |
| 105 /** | |
| 106 * Resizes the mesh gradient to contain the given rows and cols of patches. | |
| 107 * The function copies the values of the previous patches that are still wit hin the new ranges. | |
| 108 */ | |
| 109 void resize(int rows, int cols); | |
|
egdaniel
2014/08/07 17:58:55
Do you have a plan to use this function? My gut in
dandov
2014/08/07 18:11:46
I was thinking for a similar case as Illustrator's
| |
| 110 | |
| 111 /** | |
| 112 * Resets the mesh gradient to contain rows and cols of patches. The main di fference between | |
| 113 * this and resize is that resize keeps the previous values of control point s and colors and | |
| 114 * this doesn't. | |
| 115 */ | |
| 116 void reset(int rows, int cols, const SkPoint* corners, const SkPoint* hrzCtr lPts, | |
| 117 const SkPoint* vrtCtrlPts, const SkColor* colors); | |
| 118 | |
| 119 /** | |
| 120 * Draws the mesh gradient. | |
| 121 */ | |
| 122 void draw(SkCanvas* canvas, SkPaint& paint); | |
| 123 | |
| 124 /** | |
| 125 * Get the dimensions of the grid of patches. | |
| 126 */ | |
| 127 SkISize getDimensions() const { | |
| 128 return SkISize::Make(fCols, fRows); | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 int fRows, fCols; | |
| 133 SkPoint* fCornerPts; | |
| 134 SkColor* fCornerColors; | |
| 135 SkPoint* fHrzCtrlPts; | |
| 136 SkPoint* fVrtCtrlPts; | |
| 137 }; | |
| 138 | |
| 139 | |
| 140 #endif | |
| OLD | NEW |