Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include <stdio.h> | |
| 20 | |
| 21 namespace skiagm { | |
| 22 /** | |
| 23 * This GM draws a SkPatch. | |
| 24 */ | |
| 25 class SkPatchGM : public GM { | |
| 26 public: | |
| 27 SkPatchGM() { | |
| 28 this->setBGColor(0xFFFFFFFF); | |
| 29 } | |
| 30 | |
| 31 protected: | |
| 32 virtual SkString onShortName() SK_OVERRIDE { | |
| 33 return SkString("skpatch"); | |
| 34 } | |
| 35 | |
| 36 virtual SkISize onISize() SK_OVERRIDE { | |
| 37 return SkISize::Make(800, 800); | |
| 38 } | |
| 39 | |
| 40 virtual uint32_t onGetFlags() const SK_OVERRIDE { | |
| 41 // This is a GPU-specific GM. | |
|
dandov
2014/07/22 18:00:30
The GM is not GPU-specific anymore, should I retur
| |
| 42 return kGPUOnly_Flag; | |
| 43 } | |
| 44 | |
| 45 | |
| 46 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
| 47 | |
| 48 SkPaint paint; | |
| 49 SkColor colors[4] = { | |
| 50 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN | |
| 51 }; | |
| 52 SkPoint points[] = { | |
| 53 {100,100}, {130,50}, {500,70}, {650,60}, | |
| 54 {110,590}, {140,550}, {515,595}, {600,700}, | |
| 55 {70,150}, {125,400}, | |
| 56 {350,125}, {490,555} | |
| 57 }; | |
| 58 | |
| 59 SkPatch coons(points, &colors, 10); | |
| 60 coons.setData(); | |
| 61 | |
| 62 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,coons.getVertexCoun t(), | |
| 63 coons.getPoints(), coons.getTexCoords(), coons.getColors(), NULL, co ons.getIndices(), | |
| 64 coons.getIndexCount(), paint); | |
| 65 | |
| 66 //draw control points | |
| 67 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getBottomPoints( ), paint); | |
| 68 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getTopPoints(), paint); | |
| 69 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getLeftPoints(), paint); | |
| 70 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, coons.getRightPoints() , paint); | |
| 71 | |
| 72 paint.setStrokeWidth(5); | |
| 73 paint.setColor(SK_ColorRED); | |
| 74 | |
| 75 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getBottomPoints (), paint); | |
| 76 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getTopPoints(), paint); | |
| 77 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getLeftPoints() , paint); | |
| 78 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, coons.getRightPoints( ), paint); | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 typedef GM INHERITED; | |
| 83 }; | |
| 84 | |
| 85 DEF_GM( return SkNEW(SkPatchGM); ) | |
| 86 | |
| 87 } | |
| 88 | |
| 89 #endif | |
| OLD | NEW |