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

Side by Side Diff: gm/patch.cpp

Issue 405163003: SkPatch abstraction (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Skip tiled flag 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 // This test only works with the GPU backend.
10
11 #include "gm.h"
12
13 #if SK_SUPPORT_GPU
14
15 #include "GrContext.h"
16 #include "GrTest.h"
17
18 #include "SkPatch.h"
19
20 namespace skiagm {
21 /**
22 * This GM draws a SkPatch.
23 */
24 class SkPatchGM : public GM {
25 public:
26 SkPatchGM() {
27 this->setBGColor(0xFFFFFFFF);
28 }
29
30 protected:
31 virtual SkString onShortName() SK_OVERRIDE {
32 return SkString("patch_primitive");
33 }
34
35 virtual SkISize onISize() SK_OVERRIDE {
36 return SkISize::Make(800, 800);
37 }
38
39 virtual uint32_t onGetFlags() const SK_OVERRIDE {
40 return kSkipTiled_Flag;
41 }
42
43 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
44
45 SkPaint paint;
46
47 SkColor colors[4] = {
48 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN
49 };
50 SkPoint points[12] = {
51 {100,100},{130,50},{500,70}, {650,60},
52 {350,125},{490,555},{600,700},
53 {515,595},{140,550},{110,590},
54 {125,400},{70,150}
55 };
56
57 SkPatch coons(points, colors);
58 SkPatch::VertexData data;
59 coons.getVertexData(&data, 10);
60
61 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,data.fVertexCount,
62 data.fPoints, data.fTexCoords, data.fColors, NULL, data.fIndices,
63 data.fIndexCount, paint);
64
65 //draw control points
66 SkPoint bottom[4];
67 coons.getBottomPoints(bottom);
68 SkPoint top[4];
69 coons.getTopPoints(top);
70 SkPoint left[4];
71 coons.getLeftPoints(left);
72 SkPoint right[4];
73 coons.getRightPoints(right);
74
75 SkPoint corners[4] = { bottom[0], bottom[3], top[0], top[3] };
76 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, bottom, paint);
77 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, bottom+1, paint);
78 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, top, paint);
79 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, left, paint);
80 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, right, paint);
81
82 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, top+1, paint);
83 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, left+1, paint);
84 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, right+1, paint);
85
86 paint.setStrokeWidth(10);
87
88 paint.setColor(SK_ColorRED);
89 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, corners, paint);
90
91 paint.setColor(SK_ColorBLUE);
92 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, bottom+1, paint);
93
94 paint.setColor(SK_ColorCYAN);
95 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, top+1, paint);
96
97 paint.setColor(SK_ColorYELLOW);
98 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, left+1, paint);
99
100 paint.setColor(SK_ColorGREEN);
101 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, right+1, paint);
102 }
103
104 private:
105 typedef GM INHERITED;
106 };
107
108 DEF_GM( return SkNEW(SkPatchGM); )
109
110 }
111
112 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698