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

Unified Diff: gm/patch.cpp

Issue 463493002: SkCanvas::drawPatch param SkPoint[12] (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Removed GPU headers from GM 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 | « bench/PatchBench.cpp ('k') | gyp/bench.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 3f1e07910be6ea21407018c8a2bb5134ea03e77c..d4fe4ff1f33ee5c26ce8e56ca7fe2be203feea2d 100644
--- a/gm/patch.cpp
+++ b/gm/patch.cpp
@@ -6,40 +6,45 @@
* found in the LICENSE file.
*/
-// This test only works with the GPU backend.
-
#include "gm.h"
+#include "SkGradientShader.h"
+#include "SkPatchUtils.h"
+
+static SkShader* make_shader() {
+ const SkColor colors[] = {
+ SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, SK_ColorMAGENTA, SK_ColorBLUE,
+ SK_ColorYELLOW,
+ };
+ const SkPoint pts[] = { { 100.f / 4.f, 0.f }, { 3.f * 100.f / 4.f, 100.f } };
+
+ return SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode);
+}
-#if SK_SUPPORT_GPU
-
-#include "GrContext.h"
-#include "GrTest.h"
-#include "SkPatch.h"
-
-static void draw_control_points(SkCanvas* canvas, const SkPatch& patch) {
+static void draw_control_points(SkCanvas* canvas, const SkPoint cubics[12]) {
//draw control points
SkPaint paint;
- SkPoint bottom[SkPatch::kNumPtsCubic];
- patch.getBottomPoints(bottom);
- SkPoint top[SkPatch::kNumPtsCubic];
- patch.getTopPoints(top);
- SkPoint left[SkPatch::kNumPtsCubic];
- patch.getLeftPoints(left);
- SkPoint right[SkPatch::kNumPtsCubic];
- patch.getRightPoints(right);
+ SkPoint bottom[SkPatchUtils::kNumPtsCubic];
+ SkPatchUtils::getBottomCubic(cubics, bottom);
+ SkPoint top[SkPatchUtils::kNumPtsCubic];
+ SkPatchUtils::getTopCubic(cubics, top);
+ SkPoint left[SkPatchUtils::kNumPtsCubic];
+ SkPatchUtils::getLeftCubic(cubics, left);
+ SkPoint right[SkPatchUtils::kNumPtsCubic];
+ SkPatchUtils::getRightCubic(cubics, right);
paint.setColor(SK_ColorBLACK);
- paint.setStrokeWidth(0.5);
+ paint.setStrokeWidth(0.5f);
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, 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);
+ 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);
@@ -47,21 +52,21 @@ static void draw_control_points(SkCanvas* canvas, const SkPatch& patch) {
canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, corners, paint);
paint.setColor(SK_ColorBLUE);
- canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, bottom+1, paint);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, bottom + 1, paint);
paint.setColor(SK_ColorCYAN);
- canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, top+1, paint);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, top + 1, paint);
paint.setColor(SK_ColorYELLOW);
- canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, left+1, paint);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, left + 1, paint);
paint.setColor(SK_ColorGREEN);
- canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right+1, paint);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right + 1, paint);
}
namespace skiagm {
/**
- * This GM draws a SkPatch.
+ * This GM draws a cubics coons patch using the specialized call SkCanvas::drawPatch.
*/
class SkPatchGM : public GM {
@@ -88,44 +93,63 @@ protected:
SkPaint paint;
// The order of the colors and points is clockwise starting at upper-left corner.
- SkColor colors[SkPatch::kNumColors] = {
- SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN
- };
- SkPoint points[SkPatch::kNumCtrlPts] = {
+ const SkPoint cubics[SkPatchUtils::kNumCtrlPts] = {
//top points
- {50,50},{75,20},{125,80}, {150,50},
+ {100,100},{150,50},{250,150}, {300,100},
//right points
- {120,75},{180,125},
+ {250, 150},{350,250},
//bottom points
- {150,150},{125,120},{75,180},{50,150},
+ {300,300},{250,250},{150,350},{100,300},
//left points
- {20,125},{80,75}
+ {50,250},{150,150}
};
- SkPatch patch(points, colors);
- static const SkScalar kScale = 0.5f;
- canvas->translate(100, 100);
- canvas->save();
- for (SkScalar x = 0; x < 4; x++) {
- canvas->save();
- canvas->scale(kScale * (x + 1), kScale * (x + 1));
- canvas->translate(x * 100, 0);
- canvas->drawPatch(patch, paint);
- draw_control_points(canvas, patch);
- canvas->restore();
- }
+ const SkColor colors[SkPatchUtils::kNumCorners] = {
+ SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN
+ };
+ const SkPoint texCoords[SkPatchUtils::kNumCorners] = {
+ {0.0f, 0.0f}, {100.0f, 0.0f}, {100.0f,100.0f}, {0.0f, 100.0f}}
+ ;
- canvas->translate(0, 270);
+ const SkXfermode::Mode modes[] = {
+ SkXfermode::kSrc_Mode,
+ SkXfermode::kDst_Mode,
+ SkXfermode::kModulate_Mode,
+ };
- static const SkScalar kSkew = 0.2f;
- for (SkScalar x = 0; x < 4; x++) {
- canvas->save();
- canvas->scale(kScale * (x + 1), kScale * (x + 1));
- canvas->translate(x * 100, 0);
- canvas->skew(kSkew * (x + 1), kSkew * (x + 1));
- canvas->drawPatch(patch, paint);
- draw_control_points(canvas, patch);
- canvas->restore();
+ SkAutoTUnref<SkShader> shader(make_shader());
+
+ canvas->save();
+ for (int y = 0; y < 3; y++) {
+ SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(modes[y]));
+
+ for (int x = 0; x < 4; x++) {
+ canvas->save();
+ canvas->translate(x * 350.0f, y * 350.0f);
+ switch (x) {
+ case 0:
+ canvas->drawPatch(cubics, NULL, NULL, xfer, paint);
+ break;
+ case 1:
+ canvas->drawPatch(cubics, colors, NULL, xfer, paint);
+ break;
+ case 2:
+ paint.setShader(shader);
+ canvas->drawPatch(cubics, NULL, texCoords, xfer, paint);
+ paint.setShader(NULL);
+ break;
+ case 3:
+ paint.setShader(shader);
+ canvas->drawPatch(cubics, colors, texCoords, xfer, paint);
+ paint.setShader(NULL);
+ break;
+ default:
+ break;
+ }
+
+ draw_control_points(canvas, cubics);
+ canvas->restore();
+ }
}
canvas->restore();
}
@@ -137,5 +161,3 @@ private:
DEF_GM(return SkNEW(SkPatchGM); )
}
-
-#endif
« no previous file with comments | « bench/PatchBench.cpp ('k') | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698