OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 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 "SkGradientShader.h" |
| 9 #include "SkSurface.h" |
| 10 #include "checkerboard.h" |
| 11 #include "gm.h" |
| 12 |
| 13 static void make_transparency(SkCanvas* canvas, |
| 14 SkScalar width, |
| 15 SkScalar height) { |
| 16 SkPoint pts[2]; |
| 17 pts[0] = SkPoint::Make(0, 0); |
| 18 pts[1] = SkPoint::Make(width, 0); |
| 19 const SkColor kColors[] = { |
| 20 SK_ColorBLACK, |
| 21 SK_ColorGRAY, |
| 22 SK_ColorWHITE, |
| 23 SK_ColorRED, |
| 24 SK_ColorYELLOW, |
| 25 SK_ColorGREEN, |
| 26 SK_ColorCYAN, |
| 27 SK_ColorBLUE, |
| 28 SK_ColorMAGENTA, |
| 29 }; |
| 30 const SkScalar kRowHeight = height / SK_ARRAY_COUNT(kColors); |
| 31 for (size_t i = 0; i < SK_ARRAY_COUNT(kColors); ++i) { |
| 32 SkColor shaderColors[2]; |
| 33 shaderColors[0] = SK_AlphaTRANSPARENT; |
| 34 shaderColors[1] = kColors[i]; |
| 35 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear( |
| 36 pts, shaderColors, NULL, 2, SkShader::kClamp_TileMode)); |
| 37 SkRect r = SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight); |
| 38 SkPaint p; |
| 39 p.setShader(shader); |
| 40 canvas->drawRect(r, p); |
| 41 } |
| 42 } |
| 43 |
| 44 /** |
| 45 * This GM verifies that a transparent bitmap drawn over a |
| 46 * checkerboard pattern looks correct. |
| 47 */ |
| 48 DEF_SIMPLE_GM(transparency_check, canvas, 1912, 1080) { |
| 49 skiagm::Checkerboard(canvas); |
| 50 { |
| 51 SkAutoCanvasRestore autoCanvasRestore(canvas, true); |
| 52 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(256, 9)); |
| 53 make_transparency(surface->getCanvas(), 256.0f, 9.0f); |
| 54 canvas->scale(7.5f, 120.0f); |
| 55 surface->draw(canvas, 0, 0, NULL); |
| 56 } |
| 57 } |
OLD | NEW |