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

Side by Side Diff: gm/transparency.cpp

Issue 1790353002: Revert of more shader-->sp conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/tinybitmap.cpp ('k') | gm/vertices.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 2015 Google Inc. 2 * Copyright 2015 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 "SkGradientShader.h" 8 #include "SkGradientShader.h"
9 #include "SkSurface.h" 9 #include "SkSurface.h"
10 #include "gm.h" 10 #include "gm.h"
11 11
12 static void make_transparency(SkCanvas* canvas, SkScalar width, SkScalar height) { 12 static void make_transparency(SkCanvas* canvas,
13 SkScalar width,
14 SkScalar height) {
13 SkPoint pts[2]; 15 SkPoint pts[2];
14 pts[0] = SkPoint::Make(0, 0); 16 pts[0] = SkPoint::Make(0, 0);
15 pts[1] = SkPoint::Make(width, 0); 17 pts[1] = SkPoint::Make(width, 0);
16 const SkColor kColors[] = { 18 const SkColor kColors[] = {
17 SK_ColorBLACK, 19 SK_ColorBLACK,
18 SK_ColorGRAY, 20 SK_ColorGRAY,
19 SK_ColorWHITE, 21 SK_ColorWHITE,
20 SK_ColorRED, 22 SK_ColorRED,
21 SK_ColorYELLOW, 23 SK_ColorYELLOW,
22 SK_ColorGREEN, 24 SK_ColorGREEN,
23 SK_ColorCYAN, 25 SK_ColorCYAN,
24 SK_ColorBLUE, 26 SK_ColorBLUE,
25 SK_ColorMAGENTA, 27 SK_ColorMAGENTA,
26 }; 28 };
27 const SkScalar kRowHeight = height / SK_ARRAY_COUNT(kColors); 29 const SkScalar kRowHeight = height / SK_ARRAY_COUNT(kColors);
28 for (size_t i = 0; i < SK_ARRAY_COUNT(kColors); ++i) { 30 for (size_t i = 0; i < SK_ARRAY_COUNT(kColors); ++i) {
29 SkColor shaderColors[2]; 31 SkColor shaderColors[2];
30 shaderColors[0] = SK_AlphaTRANSPARENT; 32 shaderColors[0] = SK_AlphaTRANSPARENT;
31 shaderColors[1] = kColors[i]; 33 shaderColors[1] = kColors[i];
34 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(
35 pts, shaderColors, nullptr, 2, SkShader::kClamp_TileMode));
36 SkRect r = SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight);
32 SkPaint p; 37 SkPaint p;
33 p.setShader(SkGradientShader::MakeLinear(pts, shaderColors, nullptr, 2, 38 p.setShader(shader);
34 SkShader::kClamp_TileMode)); 39 canvas->drawRect(r, p);
35 canvas->drawRect(SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight), p);
36 } 40 }
37 } 41 }
38 42
39 // http://crrev.com/834303005 43 // http://crrev.com/834303005
40 static sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int si ze) { 44 static SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size) {
41 SkBitmap bm; 45 SkBitmap bm;
42 bm.allocN32Pixels(2 * size, 2 * size); 46 bm.allocN32Pixels(2 * size, 2 * size);
43 bm.eraseColor(c1); 47 bm.eraseColor(c1);
44 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2); 48 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
45 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2); 49 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
46 return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader:: kRepeat_TileMode); 50 return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
51 SkShader::kRepeat_TileMode);
47 } 52 }
48 53
49 // http://crrev.com/834303005 54 // http://crrev.com/834303005
50 static void checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { 55 static void checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) {
51 SkPaint paint; 56 SkPaint paint;
52 paint.setShader(create_checkerboard_shader(c1, c2, size)); 57 paint.setShader(create_checkerboard_shader(c1, c2, size))->unref();
53 canvas->drawPaint(paint); 58 canvas->drawPaint(paint);
54 } 59 }
55 60
56 /** 61 /**
57 * This GM verifies that a transparent bitmap drawn over a 62 * This GM verifies that a transparent bitmap drawn over a
58 * checkerboard pattern looks correct. 63 * checkerboard pattern looks correct.
59 */ 64 */
60 DEF_SIMPLE_GM(transparency_check, canvas, 1792, 1080) { 65 DEF_SIMPLE_GM(transparency_check, canvas, 1792, 1080) {
61 checkerboard(canvas, sk_tool_utils::color_to_565(0xFF999999), 66 checkerboard(canvas, sk_tool_utils::color_to_565(0xFF999999),
62 sk_tool_utils::color_to_565(0xFF666666), 8); 67 sk_tool_utils::color_to_565(0xFF666666), 8);
63 { 68 {
64 SkAutoCanvasRestore autoCanvasRestore(canvas, true); 69 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
65 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(256, 9)); 70 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(256, 9));
66 make_transparency(surface->getCanvas(), 256.0f, 9.0f); 71 make_transparency(surface->getCanvas(), 256.0f, 9.0f);
67 canvas->scale(7.0f, 120.0f); 72 canvas->scale(7.0f, 120.0f);
68 surface->draw(canvas, 0, 0, nullptr); 73 surface->draw(canvas, 0, 0, nullptr);
69 } 74 }
70 } 75 }
OLDNEW
« no previous file with comments | « gm/tinybitmap.cpp ('k') | gm/vertices.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698