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

Side by Side Diff: gm/surface.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on Created 4 years, 9 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 | « gm/srcmode.cpp ('k') | gm/tablecolorfilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 #include "SkSurface.h" 10 #include "SkSurface.h"
11 #include "SkSurfaceProps.h" 11 #include "SkSurfaceProps.h"
12 12
13 #define W 200 13 #define W 200
14 #define H 100 14 #define H 100
15 15
16 static SkShader* make_shader() { 16 static sk_sp<SkShader> make_shader() {
17 int a = 0x99; 17 int a = 0x99;
18 int b = 0xBB; 18 int b = 0xBB;
19 SkPoint pts[] = { { 0, 0 }, { W, H } }; 19 SkPoint pts[] = { { 0, 0 }, { W, H } };
20 SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) }; 20 SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) };
21 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode); 21 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam p_TileMode);
22 } 22 }
23 23
24 static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelG eometry geo, 24 static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelG eometry geo,
25 int disallowAA, int disallowDither) { 25 int disallowAA, int disallowDither) {
26 uint32_t flags = 0; 26 uint32_t flags = 0;
27 if (disallowAA) { 27 if (disallowAA) {
28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; 28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag;
29 } 29 }
30 if (disallowDither) { 30 if (disallowDither) {
31 flags |= SkSurfaceProps::kDisallowDither_Flag; 31 flags |= SkSurfaceProps::kDisallowDither_Flag;
32 } 32 }
33 33
34 SkSurfaceProps props(flags, geo); 34 SkSurfaceProps props(flags, geo);
35 if (ctx) { 35 if (ctx) {
36 return SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props) ; 36 return SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props) ;
37 } else { 37 } else {
38 return SkSurface::NewRaster(info, &props); 38 return SkSurface::NewRaster(info, &props);
39 } 39 }
40 } 40 }
41 41
42 static void test_draw(SkCanvas* canvas, const char label[]) { 42 static void test_draw(SkCanvas* canvas, const char label[]) {
43 SkPaint paint; 43 SkPaint paint;
44 44
45 paint.setAntiAlias(true); 45 paint.setAntiAlias(true);
46 paint.setLCDRenderText(true); 46 paint.setLCDRenderText(true);
47 paint.setDither(true); 47 paint.setDither(true);
48 48
49 paint.setShader(make_shader())->unref(); 49 paint.setShader(make_shader());
50 canvas->drawRect(SkRect::MakeWH(W, H), paint); 50 canvas->drawRect(SkRect::MakeWH(W, H), paint);
51 paint.setShader(nullptr); 51 paint.setShader(nullptr);
52 52
53 paint.setColor(SK_ColorWHITE); 53 paint.setColor(SK_ColorWHITE);
54 paint.setTextSize(32); 54 paint.setTextSize(32);
55 paint.setTextAlign(SkPaint::kCenter_Align); 55 paint.setTextAlign(SkPaint::kCenter_Align);
56 sk_tool_utils::set_portable_typeface(&paint); 56 sk_tool_utils::set_portable_typeface(&paint);
57 canvas->drawText(label, strlen(label), W / 2, H * 3 / 4, paint); 57 canvas->drawText(label, strlen(label), W / 2, H * 3 / 4, paint);
58 } 58 }
59 59
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 SkAutoTUnref<SkImage> image2(surf2->newImageSnapshot()); 152 SkAutoTUnref<SkImage> image2(surf2->newImageSnapshot());
153 canvas->drawImage(image2, 10 + SkIntToScalar(image->width()) + 10, 10, n ullptr); 153 canvas->drawImage(image2, 10 + SkIntToScalar(image->width()) + 10, 10, n ullptr);
154 } 154 }
155 155
156 private: 156 private:
157 typedef GM INHERITED; 157 typedef GM INHERITED;
158 }; 158 };
159 DEF_GM( return new NewSurfaceGM ) 159 DEF_GM( return new NewSurfaceGM )
160 160
OLDNEW
« no previous file with comments | « gm/srcmode.cpp ('k') | gm/tablecolorfilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698