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

Unified Diff: gm/meshgradient.cpp

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gm/patch.cpp » ('j') | include/core/SkPatchGrid.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/meshgradient.cpp
diff --git a/gm/meshgradient.cpp b/gm/meshgradient.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ef3a8dc9afba27258c4dbe638af76d556c475f58
--- /dev/null
+++ b/gm/meshgradient.cpp
@@ -0,0 +1,167 @@
+
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// This test only works with the GPU backend.
+
+#include "gm.h"
+
+#if SK_SUPPORT_GPU
+
+#include "GrContext.h"
+#include "GrTest.h"
+
+#include "SkPatchGrid.h"
+
+static void draw_control_points(SkCanvas* canvas, const SkPatch& patch) {
+ //draw control points
+ SkPaint paint;
+ SkPoint bottom[4];
+ patch.getBottomPoints(bottom);
+ SkPoint top[4];
+ patch.getTopPoints(top);
+ SkPoint left[4];
+ patch.getLeftPoints(left);
+ SkPoint right[4];
+ patch.getRightPoints(right);
+
+ paint.setColor(SK_ColorBLACK);
+ paint.setStrokeWidth(0.5);
+ SkPoint corners[4] = { bottom[0], bottom[3], top[0], top[3] };
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, bottom, paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, bottom+1, paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, top, paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, left, paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, right, paint);
+
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, top+1, paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, left+1, paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, right+1, paint);
+
+ paint.setStrokeWidth(2);
+
+ paint.setColor(SK_ColorRED);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, corners, paint);
+
+ paint.setColor(SK_ColorBLUE);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, bottom+1, paint);
+
+ paint.setColor(SK_ColorCYAN);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, top+1, paint);
+
+ paint.setColor(SK_ColorYELLOW);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, left+1, paint);
+
+ paint.setColor(SK_ColorGREEN);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right+1, paint);
+}
+
+namespace skiagm {
+/**
+ * This GM draws a mesh gradient.
+ */
+class SkMeshGradientGM : public GM {
+
+public:
+ SkMeshGradientGM() {
+ this->setBGColor(0xFFFFFFFF);
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("mesh_gradient");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(800, 800);
+ }
+
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag;
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+
+ SkPaint paint;
+
+ SkPoint vertices[3][3] = {
+ {{50,50}, {150,50}, {250,50}},
+ {{50,150}, {160,140}, {250,150}},
+ {{50,250}, {170,460}, {250,250}}
+ };
+
+ SkColor cornerColors[3][3] = {
+ {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE},
+ {SK_ColorRED, SK_ColorBLUE, SK_ColorRED},
+ {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE}
+ };
+
+ SkPoint hrzCtrl[3][4] = {
+ {{75,80},{125,20},{175,50},{225,50}},
+ {{75,180},{125,120},{175,150},{225,150}},
+ {{75,250},{125,250},{175,250},{225,250}}
+ };
+
+ SkPoint vrtCtrl[4][3] = {
+ {{50,75},{150,75},{250,75}},
+ {{50,125},{150,125},{250,125}},
+ {{50,175},{150,175},{250,175}},
+ {{50,225},{150,225},{250,225}}
+ };
+
+ canvas->scale(5, 5);
+ SkPatchGrid grid(2, 2);
+ for (int i = 0; i<2; i++) {
egdaniel 2014/08/08 14:39:04 nit: add spaces around <
dandov 2014/08/08 18:31:45 Done.
+ for (int j = 0; j<2; j++) {
+ SkPoint points[12];
+
+ //set corners
+ points[SkPatch::kTopP0_CubicCtrlPts] = vertices[i][j];
+ points[SkPatch::kTopP3_CubicCtrlPts] = vertices[i][j + 1];
+ points[SkPatch::kBottomP0_CubicCtrlPts] = vertices[i + 1][j];
+ points[SkPatch::kBottomP3_CubicCtrlPts] = vertices[i + 1][j + 1];
+
+ points[SkPatch::kTopP1_CubicCtrlPts] = hrzCtrl[i][j * 2];
+ points[SkPatch::kTopP2_CubicCtrlPts] = hrzCtrl[i][j * 2 + 1];
+ points[SkPatch::kBottomP1_CubicCtrlPts] = hrzCtrl[i + 1][j * 2];
+ points[SkPatch::kBottomP2_CubicCtrlPts] = hrzCtrl[i + 1][j * 2 + 1];
+
+ points[SkPatch::kLeftP1_CubicCtrlPts] = vrtCtrl[i * 2][j];
+ points[SkPatch::kLeftP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1][j];
+ points[SkPatch::kRightP1_CubicCtrlPts] = vrtCtrl[i * 2][j + 1];
+ points[SkPatch::kRightP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1][j + 1];
+
+ SkColor colors[4];
+ colors[0] = cornerColors[i][j];
+ colors[1] = cornerColors[i][j + 1];
+ colors[3] = cornerColors[i + 1][j];
+ colors[2] = cornerColors[i + 1][j + 1];
+
+ grid.setPatch(j, i, points, colors);
+ }
+ }
+
+ grid.draw(canvas, paint);
+ SkISize dims = grid.getDimensions();
+ for (int y = 0; y < dims.height(); y++) {
+ for (int x = 0; x < dims.width(); x++) {
+ SkPatch patch;
+ grid.getPatch(x, y, &patch);
+ draw_control_points(canvas, patch);
+ }
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+DEF_GM(return SkNEW(SkMeshGradientGM); )
+
+}
+
+#endif
« no previous file with comments | « no previous file | gm/patch.cpp » ('j') | include/core/SkPatchGrid.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698