OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 namespace skiagm { | 10 namespace skiagm { |
11 | 11 |
12 /** Create a bitmap image suitable for testing SkBitmap::scrollRect(). | 12 /** Create a bitmap image suitable for testing SkBitmap::scrollRect(). |
13 * | 13 * |
14 * @param quarterWidth bitmap will be 4x this many pixels wide | 14 * @param quarterWidth bitmap will be 4x this many pixels wide |
15 * @param quarterHeight bitmap will be 4x this many pixels tall | 15 * @param quarterHeight bitmap will be 4x this many pixels tall |
16 * @param bitmap the bitmap data is written into this object | 16 * @param bitmap the bitmap data is written into this object |
17 */ | 17 */ |
18 static void make_bitmap(int quarterWidth, int quarterHeight, SkBitmap *bitmap) { | 18 static void make_bitmap(int quarterWidth, int quarterHeight, SkBitmap *bitmap) { |
19 SkPaint pRed, pWhite, pGreen, pBlue, pLine, pAlphaGray; | 19 SkPaint pRed, pWhite, pGreen, pBlue, pLine, pAlphaGray; |
20 pRed.setColor(0xFFFF9999); | 20 pRed.setColor(0xFFFF9999); |
21 pWhite.setColor(0xFFFFFFFF); | 21 pWhite.setColor(0xFFFFFFFF); |
22 pGreen.setColor(0xFF99FF99); | 22 pGreen.setColor(0xFF99FF99); |
23 pBlue.setColor(0xFF9999FF); | 23 pBlue.setColor(0xFF9999FF); |
24 pLine.setColor(0xFF000000); | 24 pLine.setColor(0xFF000000); |
25 pLine.setStyle(SkPaint::kStroke_Style); | 25 pLine.setStyle(SkPaint::kStroke_Style); |
26 pAlphaGray.setColor(0x66888888); | 26 pAlphaGray.setColor(0x66888888); |
27 | 27 |
28 // Prepare bitmap, and a canvas that draws into it. | 28 // Prepare bitmap, and a canvas that draws into it. |
29 bitmap->reset(); | 29 bitmap->allocN32Pixels(quarterWidth*4, quarterHeight*4); |
30 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | |
31 quarterWidth*4, quarterHeight*4); | |
32 bitmap->allocPixels(); | |
33 SkCanvas canvas(*bitmap); | 30 SkCanvas canvas(*bitmap); |
34 | 31 |
35 SkScalar w = SkIntToScalar(quarterWidth); | 32 SkScalar w = SkIntToScalar(quarterWidth); |
36 SkScalar h = SkIntToScalar(quarterHeight); | 33 SkScalar h = SkIntToScalar(quarterHeight); |
37 canvas.drawRectCoords( 0, 0, w*2, h*2, pRed); | 34 canvas.drawRectCoords( 0, 0, w*2, h*2, pRed); |
38 canvas.drawRectCoords(w*2, 0, w*4, h*2, pGreen); | 35 canvas.drawRectCoords(w*2, 0, w*4, h*2, pGreen); |
39 canvas.drawRectCoords( 0, h*2, w*2, h*4, pBlue); | 36 canvas.drawRectCoords( 0, h*2, w*2, h*4, pBlue); |
40 canvas.drawRectCoords(w*2, h*2, w*4, h*4, pWhite); | 37 canvas.drawRectCoords(w*2, h*2, w*4, h*4, pWhite); |
41 canvas.drawRectCoords(w, h, w*3, h*3, pAlphaGray); | 38 canvas.drawRectCoords(w, h, w*3, h*3, pAlphaGray); |
42 canvas.drawLine(w*2, 0, w*2, h*4, pLine); | 39 canvas.drawLine(w*2, 0, w*2, h*4, pLine); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 static const int quarterHeight = 14; | 145 static const int quarterHeight = 14; |
149 SkBitmap origBitmap; | 146 SkBitmap origBitmap; |
150 }; | 147 }; |
151 | 148 |
152 ////////////////////////////////////////////////////////////////////////////// | 149 ////////////////////////////////////////////////////////////////////////////// |
153 | 150 |
154 static GM* MyFactory(void*) { return new BitmapScrollGM; } | 151 static GM* MyFactory(void*) { return new BitmapScrollGM; } |
155 static GMRegistry reg(MyFactory); | 152 static GMRegistry reg(MyFactory); |
156 | 153 |
157 } | 154 } |
OLD | NEW |