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

Side by Side Diff: gm/patch.cpp

Issue 405163003: SkPatch abstraction (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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') | include/core/SkPatch.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2013 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 #include "SkColorPriv.h"
18 #include "SkDevice.h"
19 #include "SkGeometry.h"
20
21 #include "SkPatch.h"
22
23 #include <stdio.h>
24
25 namespace {
26 extern const GrVertexAttrib kAttribs[] = {
27 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
28 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}
29 };
30 }
31
32 namespace skiagm {
33 /**
34 * This GM directly exercises effects that draw Bezier curves in the GPU backend .
35 */
36 class SkPatchGM : public GM {
37 public:
38 SkPatchGM() {
39 this->setBGColor(0xFFFFFFFF);
40 }
41
42 protected:
43 virtual SkString onShortName() SK_OVERRIDE {
44 return SkString("skpatch");
45 }
46
47 virtual SkISize onISize() SK_OVERRIDE {
48 return SkISize::Make(800, 800);
49 }
50
51 virtual uint32_t onGetFlags() const SK_OVERRIDE {
52 // This is a GPU-specific GM.
53 return kGPUOnly_Flag;
54 }
55
56
57 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
58
59 SkPaint paint;
60 SkColor colors[4] = {
61 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN
62 };
63 SkPoint points[] = {
64 {100,100}, {130,50}, {500,70}, {650,60},
65 {110,590}, {140,550}, {515,595}, {600,700},
66 {70,150}, {125,400},
67 {350,125}, {490,555}
68 };
69
70 SkCoonsPatch coons(points, &colors, 10);
71
72 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
73 if (NULL != rt && NULL != rt->getContext()) {
74 GrContext* context = rt->getContext();
75 GrTestTarget tt;
76 context->getTestTarget(&tt);
77 SkASSERT(NULL != tt.target());
78 GrDrawState* drawState = tt.target()->drawState();
79 drawState->setVertexAttribs<kAttribs>(2);
80
81 drawState->setRenderTarget(rt);
82
83 //set up mesh, defines grcolors, no texture coordinates and intercal ated data
84 SkPatchMesh meshGpu;
85 coons.genMesh(&meshGpu, SkPatchMesh::kGrColor_ColorFormat, false, tr ue);
86
87 tt.target()->setVertexSourceToArray(meshGpu.getData(), meshGpu.getVe rtexCount());
88 tt.target()->setIndexSourceToArray(meshGpu.getIndices(), meshGpu.get IndexCount());
89 tt.target()->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, meshGpu.g etVertexCount(),
90 meshGpu.getIndexCount());
91 } else {
92 SkPatchMesh mesh;
93
94 coons.genMesh(&mesh, SkPatchMesh::kSkColor_ColorFormat, false, false );
95
96 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,mesh.getVertexC ount(),
97 mesh.getPoints(), NULL, mesh.getColors(), NULL, mesh.getIndices( ),
98 mesh.getIndexCount(), paint);
99 }
100 //draw control points
101 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getBottomPoints( ), paint);
102 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getTopPoints(), paint);
103 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getLeftPoints(), paint);
104 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getRightPoints() , paint);
105
106 paint.setStrokeWidth(5);
107 paint.setColor(SK_ColorRED);
108
109 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getBottomPoints (), paint);
110 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getTopPoints(), paint);
111 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getLeftPoints() , paint);
112 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getRightPoints( ), paint);
113 }
114
115 private:
116 typedef GM INHERITED;
117 };
118
119 DEF_GM( return SkNEW(SkPatchGM); )
120
121 }
122
123 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | include/core/SkPatch.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698