| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkColor.h" | 11 #include "SkColor.h" |
| 12 #include "SkShader.h" | 12 #include "SkShader.h" |
| 13 | 13 |
| 14 namespace skiagm { | 14 namespace skiagm { |
| 15 | 15 |
| 16 // This GM draws a 3x3 grid (with the center element excluded) of rectangles | 16 // This GM draws a 3x3 grid (with the center element excluded) of rectangles |
| 17 // filled with a bitmap shader. The bitmap shader is transformed so that the | 17 // filled with a bitmap shader. The bitmap shader is transformed so that the |
| 18 // pattern cell is at the center (excluded) region. | 18 // pattern cell is at the center (excluded) region. |
| 19 // | 19 // |
| 20 // In Repeat and Mirror mode, this tests that the bitmap shader still draws | 20 // In Repeat and Mirror mode, this tests that the bitmap shader still draws |
| 21 // even though the pattern cell is outside the clip. | 21 // even though the pattern cell is outside the clip. |
| 22 // | 22 // |
| 23 // In Clamp mode, this tests that the clamp is handled properly. For PDF, | 23 // In Clamp mode, this tests that the clamp is handled properly. For PDF, |
| 24 // (and possibly other exported formats) this also "tests" that the image itself | 24 // (and possibly other exported formats) this also "tests" that the image itself |
| 25 // is not stored (well, you'll need to open it up with an external tool to | 25 // is not stored (well, you'll need to open it up with an external tool to |
| 26 // verify that). | 26 // verify that). |
| 27 | 27 |
| 28 static SkBitmap create_bitmap() { | 28 static SkBitmap create_bitmap() { |
| 29 SkBitmap bmp; | 29 SkBitmap bmp; |
| 30 bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 30 bmp.allocN32Pixels(2, 2); |
| 31 bmp.allocPixels(); | |
| 32 bmp.lockPixels(); | |
| 33 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); | 31 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); |
| 34 pixels[0] = SkPreMultiplyColor(SK_ColorRED); | 32 pixels[0] = SkPreMultiplyColor(SK_ColorRED); |
| 35 pixels[1] = SkPreMultiplyColor(SK_ColorGREEN); | 33 pixels[1] = SkPreMultiplyColor(SK_ColorGREEN); |
| 36 pixels[2] = SkPreMultiplyColor(SK_ColorBLACK); | 34 pixels[2] = SkPreMultiplyColor(SK_ColorBLACK); |
| 37 pixels[3] = SkPreMultiplyColor(SK_ColorBLUE); | 35 pixels[3] = SkPreMultiplyColor(SK_ColorBLUE); |
| 38 bmp.unlockPixels(); | |
| 39 | 36 |
| 40 return bmp; | 37 return bmp; |
| 41 } | 38 } |
| 42 | 39 |
| 43 static const SkScalar RECT_SIZE = 64; | 40 static const SkScalar RECT_SIZE = 64; |
| 44 static const SkScalar SLIDE_SIZE = 300; | 41 static const SkScalar SLIDE_SIZE = 300; |
| 45 | 42 |
| 46 class ClippedBitmapShadersGM : public GM { | 43 class ClippedBitmapShadersGM : public GM { |
| 47 public: | 44 public: |
| 48 ClippedBitmapShadersGM(SkShader::TileMode mode, bool hq=false) | 45 ClippedBitmapShadersGM(SkShader::TileMode mode, bool hq=false) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kRepeat_TileMode); ) | 120 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kRepeat_TileMode); ) |
| 124 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kMirror_TileMode); ) | 121 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kMirror_TileMode); ) |
| 125 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kClamp_TileMode); ) | 122 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kClamp_TileMode); ) |
| 126 | 123 |
| 127 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kRepeat_TileMode, true); ) | 124 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kRepeat_TileMode, true); ) |
| 128 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kMirror_TileMode, true); ) | 125 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kMirror_TileMode, true); ) |
| 129 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kClamp_TileMode, true); ) | 126 DEF_GM( return new ClippedBitmapShadersGM(SkShader::kClamp_TileMode, true); ) |
| 130 | 127 |
| 131 | 128 |
| 132 } | 129 } |
| OLD | NEW |