aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-09-22 07:29:03 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-22 07:29:03 -0700
commit4a8126e7f81384526629b1e21bf89b632ea13cd9 (patch)
tree9ee0776304de9dc98e48efc4943dd0fdc45db453 /gm
parenta29b5d8430ada72bc73b1e6e1b8f09e4b046b2ff (diff)
Introduce Props to surface (patchset #27 id:520001 of https://codereview.chromium.org/551463004/)"
This reverts commit 29c857d0f3a1cb837f73406eeb6ba9771879b5e7. TBR= Author: reed@google.com Review URL: https://codereview.chromium.org/588143004
Diffstat (limited to 'gm')
-rwxr-xr-xgm/dftext.cpp5
-rw-r--r--gm/image.cpp2
-rw-r--r--gm/surface.cpp109
-rw-r--r--gm/xfermodes3.cpp3
4 files changed, 115 insertions, 4 deletions
diff --git a/gm/dftext.cpp b/gm/dftext.cpp
index 65e64a9093..dccc62adb4 100755
--- a/gm/dftext.cpp
+++ b/gm/dftext.cpp
@@ -48,8 +48,9 @@ protected:
#if SK_SUPPORT_GPU
GrContext* ctx = inputCanvas->getGrContext();
SkImageInfo info = SkImageInfo::MakeN32Premul(onISize());
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, info, 0,
- SkSurface::kDistanceField_TextRenderMode));
+ SkSurfaceProps props(SkSurfaceProps::kUseDistanceFieldFonts_Flag,
+ SkSurfaceProps::kLegacyFontHost_InitType);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, info, 0, &props));
SkCanvas* canvas = surface->getCanvas();
#else
SkCanvas* canvas = inputCanvas;
diff --git a/gm/image.cpp b/gm/image.cpp
index 1c2b4a7e55..a0959b2fdd 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -179,7 +179,7 @@ protected:
#if SK_SUPPORT_GPU
GrContext* ctx = canvas->getGrContext();
- SkAutoTUnref<SkSurface> surf4(SkSurface::NewRenderTarget(ctx, info, 0));
+ SkAutoTUnref<SkSurface> surf4(SkSurface::NewRenderTarget(ctx, info));
#endif
test_surface(canvas, surf0, true);
diff --git a/gm/surface.cpp b/gm/surface.cpp
new file mode 100644
index 0000000000..dbcced2cbf
--- /dev/null
+++ b/gm/surface.cpp
@@ -0,0 +1,109 @@
+/*
+ * 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, const char label[]) {
+ 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(32);
+ paint.setTextAlign(SkPaint::kCenter_Align);
+ canvas->drawText(label, strlen(label), W / 2, H * 3 / 4, paint);
+}
+
+class SurfacePropsGM : public skiagm::GM {
+public:
+ SurfacePropsGM() {}
+
+protected:
+ SkString onShortName() SK_OVERRIDE {
+ return SkString("surfaceprops");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(W * 4, H * 5);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ 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 struct {
+ SkPixelGeometry fGeo;
+ const char* fLabel;
+ } rec[] = {
+ { kUnknown_SkPixelGeometry, "Unknown" },
+ { kRGB_H_SkPixelGeometry, "RGB_H" },
+ { kBGR_H_SkPixelGeometry, "BGR_H" },
+ { kRGB_V_SkPixelGeometry, "RGB_V" },
+ { kBGR_V_SkPixelGeometry, "BGR_V" },
+ };
+
+ SkScalar x = 0;
+ for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) {
+ for (int disallowDither = 0; disallowDither <= 1; ++disallowDither) {
+ SkScalar y = 0;
+ for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
+ SkAutoTUnref<SkSurface> surface(make_surface(ctx, info, rec[i].fGeo,
+ disallowAA, disallowDither));
+ test_draw(surface->getCanvas(), rec[i].fLabel);
+ surface->draw(canvas, x, y, NULL);
+ y += H;
+ }
+ x += W;
+ }
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+DEF_GM( return new SurfacePropsGM )
diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp
index 74ca643b23..1ca740893b 100644
--- a/gm/xfermodes3.cpp
+++ b/gm/xfermodes3.cpp
@@ -132,7 +132,8 @@ private:
desc.fConfig = SkImageInfo2GrPixelConfig(baseCanvas->imageInfo());
desc.fFlags = kRenderTarget_GrTextureFlagBit;
SkAutoTUnref<GrSurface> surface(context->createUncachedTexture(desc, NULL, 0));
- SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(surface.get()));
+ SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(surface.get(),
+ SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)));
if (device.get()) {
tempCanvas = SkNEW_ARGS(SkCanvas, (device.get()));
}