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

Unified Diff: src/effects/gradients/SkMeshGradient.h

Issue 451723003: SkPatchGrid interface (after SkPatch/SkPicture rebase). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/gmslides.gypi ('k') | src/effects/gradients/SkMeshGradient.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkMeshGradient.h
diff --git a/src/effects/gradients/SkMeshGradient.h b/src/effects/gradients/SkMeshGradient.h
new file mode 100644
index 0000000000000000000000000000000000000000..e25352e1dac75fac977586eeaf74c611e86805ce
--- /dev/null
+++ b/src/effects/gradients/SkMeshGradient.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkMeshGradient_DEFINED
+#define SkMeshGradient_DEFINED
+
+#include "SkPatch.h"
+#include "SkCanvas.h"
+
+/**
+ * Class that represents a Mesh Gradient. A mesh gradient is an array of coons patches, adjacent
+ * patches share their corners and a color is specified at each one of them. The colors are
+ * bilinearly interpolated across the patch.
+ *
+ * This implementation defines a bidimensional array of patches. There are 3 arrays to store the
+ * control points of the patches to avoid storing repeated data since there are several points
+ * shared between adjacent patches.
+ *
+ * The array fCornerPts stores the corner control points of the patches.
+ * The array fHrzPts holds the intermidiate control points of the top and bottom curves of a patch.
+ * The array fVrtPts holds the intermidiate control points of the left and right curves of a patch.
+ * The array fCornerColors holds the corner colors in the same format as fCornerPts.
+ * 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.
+ * the grid.
+ *
+ * fExists fCornerPts fHrzPts fVrtPts
+ * ------- -------------- ------------------- --------------
+ * | 1 | 1 | | C0 | C1 | C2 | | H0 | H1 | H2 | H3 | | V0 | V1 | V2 |
+ * ------- -------------- ------------------ ---------------
+ * | 1 | 1 | | C3 | C4 | C5 | | H4 | H5 | H6 | H7 | | V4 | V5 | V6 |
+ * ------- -------------- ------------------- --------------
+ * | C6 | C7 | C8 | | H8 | H9 | H10| H11| | V6 | V7 | V8 |
+ * -------------- ------------------- --------------
+ * | V9 | V10| V11|
+ * --------------
+ *
+ * With the above configuration we would have a 2x2 grid of patches:
+ * H0 H1 H2 H3
+ * / \/ \
+ * C0-------C1-------C2
+ * /| | |\
+ * v0 | v1 | v2
+ * v3 | V4 | v5
+ * \| | |/
+ * C3-H4-H5-C4-H6-H7-C5
+ * /| | |\
+ * v6 | v7 | v8
+ * v9 | v10 | v11
+ * \| | |/
+ * C6-------C7-------C8
+ * \ / \ /
+ * H8 H9 H10 H11
+ *
+ * When trying to get a patch at a certain position it justs builds it with the corresponding
+ * points.
+ * When adding a patch it tries to add the points at their corresponding position trying to comply
+ * with the adjacent points or overwriting them.
+ *
+ * Based the idea on the SVG2 spec:
+ * <meshGradient x="100" y="100">
+ * <meshRow>
+ * <meshPatch>
+ * <stop .../>
+ * Up to four stops in first patch. See details below.
+ * </meshPatch>
+ * <meshPatch>
+ * Any number of meshPatches in row.
+ * </meshPatch>
+ * </meshRow>
+ * <meshRow>
+ * Any number of meshRows, each with the same number of meshPatches as in the first row.
+ * </meshRow>
+ </meshGradient>
+ */
+class SkMeshGradient {
+
+public:
+ SkMeshGradient(int rows, int cols);
+ SkMeshGradient(int rows, int cols, const SkPoint* corners, const SkPoint* hrzCtrlPts,
+ const SkPoint* vrtCtrlPts, const SkColor* colors);
+
+ ~SkMeshGradient();
+
+ /**
+ * Add a patch at location (x,y). The function returns false if none of the new patch's control
+ * points are set, which may be because (x,y) are out of range or because the patch already
+ * 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
+ * If overwrite is true then the patch is always set and overwrites the values of adjacent
+ * patches. If it is set to false and the location is empty the function just set the control
+ * that are "empty" meaning that it does not overwrite values of adjacent patches.
+ */
+ bool addPatch(int x, int y, const SkPatch& patch);
+ bool addPatch(int x, int y, const SkPoint ctrlPts[12], const SkColor colors[4]);
+
+ /**
+ * Get patch at location (x,y). If the patch is not NULL it sets patch's
+ * control points and colors to the corresponding values.
+ */
+ void getPatchAt(int x, int y, SkPatch* patch) const;
+
+ /**
+ * Resizes the mesh gradient to contain the given rows and cols of patches.
+ * The function copies the values of the previous patches that are still within the new ranges.
+ */
+ 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
+
+ /**
+ * Resets the mesh gradient to contain rows and cols of patches. The main difference between
+ * this and resize is that resize keeps the previous values of control points and colors and
+ * this doesn't.
+ */
+ void reset(int rows, int cols, const SkPoint* corners, const SkPoint* hrzCtrlPts,
+ const SkPoint* vrtCtrlPts, const SkColor* colors);
+
+ /**
+ * Draws the mesh gradient.
+ */
+ void draw(SkCanvas* canvas, SkPaint& paint);
+
+ /**
+ * Get the dimensions of the grid of patches.
+ */
+ SkISize getDimensions() const {
+ return SkISize::Make(fCols, fRows);
+ }
+
+private:
+ int fRows, fCols;
+ SkPoint* fCornerPts;
+ SkColor* fCornerColors;
+ SkPoint* fHrzCtrlPts;
+ SkPoint* fVrtCtrlPts;
+};
+
+
+#endif
« no previous file with comments | « gyp/gmslides.gypi ('k') | src/effects/gradients/SkMeshGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698