Chromium Code Reviews| Index: gm/surface.cpp |
| diff --git a/gm/surface.cpp b/gm/surface.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f014e28c30dd4959b0510dcd81bcd32bc42c1521 |
| --- /dev/null |
| +++ b/gm/surface.cpp |
| @@ -0,0 +1,102 @@ |
| +/* |
| + * Copyright 2014 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "gm.h" |
| +#include "SkGradientShader.h" |
| +#include "SkSurface.h" |
| +#include "SkSurfaceProps.h" |
| + |
| +#define W 200 |
| +#define H 100 |
| + |
| +static SkShader* make_shader() { |
| + int a = 0x99; |
| + int b = 0xBB; |
| + SkPoint pts[] = { { 0, 0 }, { W, H } }; |
| + SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) }; |
| + return SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode); |
| +} |
| + |
| +static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelGeometry geo, |
| + int disallowAA, int disallowDither) { |
| + uint32_t flags = 0; |
| + if (disallowAA) { |
| + flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; |
| + } |
| + if (disallowDither) { |
| + flags |= SkSurfaceProps::kDisallowDither_Flag; |
| + } |
| + |
| + SkSurfaceProps props(flags, geo); |
| + if (ctx) { |
| + return SkSurface::NewRenderTarget(ctx, info, 0, &props); |
| + } else { |
| + return SkSurface::NewRaster(info, &props); |
| + } |
| +} |
| + |
| +static void test_draw(SkCanvas* canvas) { |
| + SkPaint paint; |
| + |
| + paint.setAntiAlias(true); |
| + paint.setLCDRenderText(true); |
| + paint.setDither(true); |
| + |
| + paint.setShader(make_shader())->unref(); |
| + canvas->drawRect(SkRect::MakeWH(W, H), paint); |
| + paint.setShader(NULL); |
| + |
| + paint.setColor(SK_ColorWHITE); |
| + paint.setTextSize(47); |
| + paint.setTextAlign(SkPaint::kCenter_Align); |
| + canvas->drawText("Surface", 7, W / 2, H * 4 / 5, paint); |
| +} |
| + |
| +class SurfaceGM : public skiagm::GM { |
| +public: |
| + SurfaceGM() {} |
| + |
| +protected: |
| + SkString onShortName() { |
| + return SkString("surface"); |
| + } |
| + |
| + virtual SkISize onISize() { return SkISize::Make(W * 4, H * 3); } |
| + |
| + virtual void onDraw(SkCanvas* canvas) { |
| + GrContext* ctx = canvas->getGrContext(); |
| + |
| + // must be opaque to have a hope of testing LCD text |
| + const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType); |
| + |
| + const SkPixelGeometry gGeo[] = { |
| + kUnknown_SkPixelGeometry, |
| + kRGB_H_SkPixelGeometry, |
| + kBGR_H_SkPixelGeometry, |
|
bungeman-skia
2014/09/18 21:14:10
Can we have at least one of the verticals here?
reed1
2014/09/18 21:24:41
Done.
|
| + }; |
| + |
| + SkScalar x = 0; |
| + for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { |
| + for (int disallowDither = 0; disallowDither <= 1; ++disallowDither) { |
| + SkScalar y = 0; |
| + for (size_t geoIndex = 0; geoIndex < SK_ARRAY_COUNT(gGeo); ++geoIndex) { |
| + SkAutoTUnref<SkSurface> surface(make_surface(ctx, info, gGeo[geoIndex], |
| + disallowAA, disallowDither)); |
| + test_draw(surface->getCanvas()); |
| + surface->draw(canvas, x, y, NULL); |
| + y += H; |
| + } |
| + x += W; |
| + } |
| + } |
| + } |
| + |
| +private: |
| + typedef GM INHERITED; |
| +}; |
| + |
| +DEF_GM( return new SurfaceGM ) |