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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | include/core/SkPatch.h » ('J')
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
new file mode 100644
index 0000000000000000000000000000000000000000..9e6eba123d7516883b0c2a703210c44adaafe392
--- /dev/null
+++ b/gm/patch.cpp
@@ -0,0 +1,123 @@
+
+/*
+ * Copyright 2013 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 "SkColorPriv.h"
+#include "SkDevice.h"
+#include "SkGeometry.h"
+
+#include "SkPatch.h"
+
+#include <stdio.h>
+
+namespace {
+extern const GrVertexAttrib kAttribs[] = {
+ {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
+ {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}
+};
+}
+
+namespace skiagm {
+/**
+ * This GM directly exercises effects that draw Bezier curves in the GPU backend.
+ */
+class SkPatchGM : public GM {
+public:
+ SkPatchGM() {
+ this->setBGColor(0xFFFFFFFF);
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("skpatch");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(800, 800);
+ }
+
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ // This is a GPU-specific GM.
+ return kGPUOnly_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},
+ {110,590}, {140,550}, {515,595}, {600,700},
+ {70,150}, {125,400},
+ {350,125}, {490,555}
+ };
+
+ SkCoonsPatch coons(points, &colors, 10);
+
+ GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget();
+ if (NULL != rt && NULL != rt->getContext()) {
+ GrContext* context = rt->getContext();
+ GrTestTarget tt;
+ context->getTestTarget(&tt);
+ SkASSERT(NULL != tt.target());
+ GrDrawState* drawState = tt.target()->drawState();
+ drawState->setVertexAttribs<kAttribs>(2);
+
+ drawState->setRenderTarget(rt);
+
+ //set up mesh, defines grcolors, no texture coordinates and intercalated data
+ SkPatchMesh meshGpu;
+ coons.genMesh(&meshGpu, SkPatchMesh::kGrColor_ColorFormat, false, true);
+
+ tt.target()->setVertexSourceToArray(meshGpu.getData(), meshGpu.getVertexCount());
+ tt.target()->setIndexSourceToArray(meshGpu.getIndices(), meshGpu.getIndexCount());
+ tt.target()->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, meshGpu.getVertexCount(),
+ meshGpu.getIndexCount());
+ } else {
+ SkPatchMesh mesh;
+
+ coons.genMesh(&mesh, SkPatchMesh::kSkColor_ColorFormat, false, false);
+
+ canvas->drawVertices(SkCanvas::kTriangles_VertexMode,mesh.getVertexCount(),
+ mesh.getPoints(), NULL, mesh.getColors(), NULL, mesh.getIndices(),
+ mesh.getIndexCount(), paint);
+ }
+ //draw control points
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getBottomPoints(), paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getTopPoints(), paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getLeftPoints(), paint);
+ canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getRightPoints(), paint);
+
+ paint.setStrokeWidth(5);
+ paint.setColor(SK_ColorRED);
+
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getBottomPoints(), paint);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getTopPoints(), paint);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getLeftPoints(), paint);
+ canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getRightPoints(), paint);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+DEF_GM( return SkNEW(SkPatchGM); )
+
+}
+
+#endif
« 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