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

Unified Diff: gm/patch.cpp

Issue 424663006: SkCanvas interface for drawing a patch. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed implicit casting in patch.cpp 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 | gyp/utils.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/patch.cpp
diff --git a/gm/patch.cpp b/gm/patch.cpp
index eb99944c0bbce2ae0d7e53a67af600594df105f0..5658ef6a889d9d65788a708a7cff44e57259b9d6 100644
--- a/gm/patch.cpp
+++ b/gm/patch.cpp
@@ -14,14 +14,71 @@
#include "GrContext.h"
#include "GrTest.h"
-
#include "SkPatch.h"
+static void draw_control_points(SkCanvas* canvas, SkPatch& patch, SkPaint& paint) {
+ //draw control points
+ SkPaint copy(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);
+
+ copy.setColor(SK_ColorBLACK);
+ copy.setStrokeWidth(0.5);
+ SkPoint corners[4] = { bottom[0], bottom[3], top[0], top[3] };
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, bottom, copy);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, bottom+1, copy);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, top, copy);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, left, copy);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, right, copy);
+
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, top+1, copy);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, left+1, copy);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 2, right+1, copy);
+
+ copy.setStrokeWidth(2);
+
+ copy.setColor(SK_ColorRED);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, corners, copy);
+
+ copy.setColor(SK_ColorBLUE);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, bottom+1, copy);
+
+ copy.setColor(SK_ColorCYAN);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, top+1, copy);
+
+ copy.setColor(SK_ColorYELLOW);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, left+1, copy);
+
+ copy.setColor(SK_ColorGREEN);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right+1, copy);
+}
+
+static void draw_random_patch(SkPoint points[12], SkColor colors[4], SkCanvas* canvas,
+ SkPaint& paint, SkRandom* rnd) {
+ SkPoint ptsCpy[12];
+ memcpy(ptsCpy, points, 12 * sizeof(SkPoint));
+ for (int i = 0; i < 5; i++) {
+ int index = rnd->nextRangeU(0, 11);
+ SkScalar dx = rnd->nextRangeScalar(-50, 50), dy = rnd->nextRangeScalar(-50, 50);
+ ptsCpy[index].offset(dx, dy);
+ }
+ SkPatch patch(ptsCpy, colors);
+ canvas->drawPatch(patch, paint);
+ draw_control_points(canvas, patch, paint);
+}
+
namespace skiagm {
/**
* This GM draws a SkPatch.
*/
class SkPatchGM : public GM {
+
public:
SkPatchGM() {
this->setBGColor(0xFFFFFFFF);
@@ -37,77 +94,50 @@ protected:
}
virtual uint32_t onGetFlags() const SK_OVERRIDE {
- return kGPUOnly_Flag;
+ return kSkipTiled_Flag | kSkipPipe_Flag | kSkipPicture_Flag;
}
-
-
+
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
-
+
SkPaint paint;
SkColor colors[4] = {
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN
};
- SkPoint points[] = {
- {100,100},{130,50},{500,70}, {650,60},
- {350,125},{490,555},{600,700},
- {515,595},{140,550},{110,590},
- {125,400},{70,150}
-
+ SkPoint points[12] = {
+ {50,50},{75,20},{125,80}, {150,50},
+ {120,75},{180,125},{150,150},
+ {125,120},{75,180},{50,150},
+ {20,125},{80,75}
};
-
- SkPatch coons(points, colors);
- SkPatch::VertexData data;
- coons.getVertexData(&data, 10);
-
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode,data.fVertexCount,
- data.fPoints, data.fTexCoords, data.fColors, NULL, data.fIndices,
- data.fIndexCount, paint);
-
- //draw control points
- SkPoint bottom[4];
- coons.getBottomPoints(bottom);
- SkPoint top[4];
- coons.getTopPoints(top);
- SkPoint left[4];
- coons.getLeftPoints(left);
- SkPoint right[4];
- coons.getRightPoints(right);
-
- 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(10);
-
- 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);
+ SkRandom rnd;
+ SkScalar scale = 0.5f;
+ canvas->save();
+ for (SkScalar x = 0; x < 4; x++) {
+ canvas->save();
+ canvas->scale(scale * (x + 1), scale * (x + 1));
+ canvas->translate(x * 100, 0);
+ draw_random_patch(points, colors, canvas, paint, &rnd);
+ canvas->restore();
+ }
+ canvas->translate(0, 270);
+ SkScalar skew = 0.1f;
+ for (SkScalar x = 0; x < 4; x++) {
+ canvas->save();
+ canvas->scale(scale * (x + 1), scale * (x + 1));
+ canvas->skew(skew * (x + 1), skew * (x + 1));
+ canvas->translate(x * 100, 0);
+ draw_random_patch(points, colors, canvas, paint, &rnd);
+ canvas->restore();
+ }
+ canvas->restore();
}
private:
typedef GM INHERITED;
};
-DEF_GM( return SkNEW(SkPatchGM); )
+DEF_GM(return SkNEW(SkPatchGM); )
}
« no previous file with comments | « no previous file | gyp/utils.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698