Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "gm.h" | |
| 9 #include "SkGradientShader.h" | |
| 10 #include "SkSurface.h" | |
| 11 #include "SkSurfaceProps.h" | |
| 12 | |
| 13 #define W 200 | |
| 14 #define H 100 | |
| 15 | |
|
robertphillips
2014/09/19 18:25:36
make_linear_gradient ?
reed1
2014/09/19 19:16:33
hmm, not important to the caller, so I chose to ke
| |
| 16 static SkShader* make_shader() { | |
| 17 int a = 0x99; | |
| 18 int b = 0xBB; | |
| 19 SkPoint pts[] = { { 0, 0 }, { W, H } }; | |
| 20 SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) }; | |
| 21 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp _TileMode); | |
| 22 } | |
| 23 | |
| 24 static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelG eometry geo, | |
| 25 int disallowAA, int disallowDither) { | |
| 26 uint32_t flags = 0; | |
| 27 if (disallowAA) { | |
| 28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; | |
| 29 } | |
| 30 if (disallowDither) { | |
| 31 flags |= SkSurfaceProps::kDisallowDither_Flag; | |
| 32 } | |
| 33 | |
| 34 SkSurfaceProps props(flags, geo); | |
| 35 if (ctx) { | |
| 36 return SkSurface::NewRenderTarget(ctx, info, 0, &props); | |
| 37 } else { | |
| 38 return SkSurface::NewRaster(info, &props); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 static void test_draw(SkCanvas* canvas, const char label[]) { | |
| 43 SkPaint paint; | |
| 44 | |
| 45 paint.setAntiAlias(true); | |
| 46 paint.setLCDRenderText(true); | |
| 47 paint.setDither(true); | |
| 48 | |
| 49 paint.setShader(make_shader())->unref(); | |
| 50 canvas->drawRect(SkRect::MakeWH(W, H), paint); | |
| 51 paint.setShader(NULL); | |
| 52 | |
| 53 paint.setColor(SK_ColorWHITE); | |
| 54 paint.setTextSize(32); | |
| 55 paint.setTextAlign(SkPaint::kCenter_Align); | |
| 56 canvas->drawText(label, strlen(label), W / 2, H * 3 / 4, paint); | |
| 57 } | |
| 58 | |
|
robertphillips
2014/09/19 18:25:36
// Exercise SkSurfaceProps variants. This renders
reed1
2014/09/19 19:16:33
Done.
| |
| 59 class SurfaceGM : public skiagm::GM { | |
| 60 public: | |
| 61 SurfaceGM() {} | |
| 62 | |
| 63 protected: | |
|
robertphillips
2014/09/19 18:25:36
SK_OVERRIDE(s) ?
virtual on onShortName ?
reed1
2014/09/19 19:16:33
Done.
| |
| 64 SkString onShortName() { | |
| 65 return SkString("surface"); | |
| 66 } | |
| 67 | |
| 68 virtual SkISize onISize() { return SkISize::Make(W * 4, H * 5); } | |
| 69 | |
| 70 virtual void onDraw(SkCanvas* canvas) { | |
| 71 GrContext* ctx = canvas->getGrContext(); | |
| 72 | |
| 73 // must be opaque to have a hope of testing LCD text | |
| 74 const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType) ; | |
| 75 | |
| 76 const struct { | |
| 77 SkPixelGeometry fGeo; | |
| 78 const char* fLabel; | |
| 79 } rec[] = { | |
| 80 { kUnknown_SkPixelGeometry, "Unknown" }, | |
| 81 { kRGB_H_SkPixelGeometry, "RGB_H" }, | |
| 82 { kBGR_H_SkPixelGeometry, "BGR_H" }, | |
| 83 { kRGB_V_SkPixelGeometry, "RGB_V" }, | |
| 84 { kBGR_V_SkPixelGeometry, "BGR_V" }, | |
| 85 }; | |
| 86 | |
| 87 SkScalar x = 0; | |
| 88 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { | |
| 89 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither) { | |
| 90 SkScalar y = 0; | |
| 91 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { | |
| 92 SkAutoTUnref<SkSurface> surface(make_surface(ctx, info, rec[ i].fGeo, | |
| 93 disallowAA, dis allowDither)); | |
| 94 test_draw(surface->getCanvas(), rec[i].fLabel); | |
| 95 surface->draw(canvas, x, y, NULL); | |
| 96 y += H; | |
| 97 } | |
| 98 x += W; | |
| 99 } | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 typedef GM INHERITED; | |
| 105 }; | |
| 106 | |
| 107 DEF_GM( return new SurfaceGM ) | |
| OLD | NEW |