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

Side by Side Diff: gm/surface.cpp

Issue 551463004: introduce Props to surface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | gm/xfermodes3.cpp » ('j') | include/core/SkSurface.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
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 bool disallowAA, bool 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) {
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(47);
55 paint.setTextAlign(SkPaint::kCenter_Align);
56 canvas->drawText("Surface", 7, W / 2, H * 4 / 5, paint);
57 }
58
59 class SurfaceGM : public skiagm::GM {
60 public:
61 SurfaceGM() {}
62
63 protected:
64 SkString onShortName() {
65 return SkString("surface");
66 }
67
68 virtual SkISize onISize() { return SkISize::Make(W * 4, H * 3); }
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 SkPixelGeometry gGeo[] = {
77 kUnknown_SkPixelGeometry,
78 kRGB_H_SkPixelGeometry,
79 kBGR_H_SkPixelGeometry,
80 };
81
82 SkScalar x = 0;
83 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) {
bungeman-skia 2014/09/18 18:31:20 for (bool aa = false; !aa; aa = true) {
84 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither) {
85 SkScalar y = 0;
86 for (size_t geoIndex = 0; geoIndex < SK_ARRAY_COUNT(gGeo); ++geo Index) {
87 SkAutoTUnref<SkSurface> surface(make_surface(ctx, info, gGeo [geoIndex],
88 disallowAA, dis allowDither));
89 test_draw(surface->getCanvas());
90 surface->draw(canvas, x, y, NULL);
91 y += H;
92 }
93 x += W;
94 }
95 }
96 }
97
98 private:
99 typedef GM INHERITED;
100 };
101
102 DEF_GM( return new SurfaceGM )
OLDNEW
« no previous file with comments | « no previous file | gm/xfermodes3.cpp » ('j') | include/core/SkSurface.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698