| 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 "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkView.h" | 9 #include "SkView.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #if SK_SUPPORT_GPU | 27 #if SK_SUPPORT_GPU |
| 28 #include "SkGpuDevice.h" | 28 #include "SkGpuDevice.h" |
| 29 #else | 29 #else |
| 30 class GrContext; | 30 class GrContext; |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 #define INT_SIZE 64 | 33 #define INT_SIZE 64 |
| 34 #define SCALAR_SIZE SkIntToScalar(INT_SIZE) | 34 #define SCALAR_SIZE SkIntToScalar(INT_SIZE) |
| 35 | 35 |
| 36 static void make_bitmap(SkBitmap* bitmap) { | 36 static void make_bitmap(SkBitmap* bitmap) { |
| 37 bitmap->setConfig(SkBitmap::kARGB_8888_Config, INT_SIZE, INT_SIZE); | 37 bitmap->allocN32Pixels(INT_SIZE, INT_SIZE); |
| 38 bitmap->allocPixels(); | |
| 39 SkCanvas canvas(*bitmap); | 38 SkCanvas canvas(*bitmap); |
| 40 | 39 |
| 41 canvas.drawColor(SK_ColorRED); | 40 canvas.drawColor(SK_ColorRED); |
| 42 SkPaint paint; | 41 SkPaint paint; |
| 43 paint.setAntiAlias(true); | 42 paint.setAntiAlias(true); |
| 44 const SkPoint pts[] = { { 0, 0 }, { SCALAR_SIZE, SCALAR_SIZE } }; | 43 const SkPoint pts[] = { { 0, 0 }, { SCALAR_SIZE, SCALAR_SIZE } }; |
| 45 const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE }; | 44 const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE }; |
| 46 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, | 45 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, |
| 47 SkShader::kClamp_TileMode))->
unref(); | 46 SkShader::kClamp_TileMode))->
unref(); |
| 48 canvas.drawCircle(SCALAR_SIZE/2, SCALAR_SIZE/2, SCALAR_SIZE/2, paint); | 47 canvas.drawCircle(SCALAR_SIZE/2, SCALAR_SIZE/2, SCALAR_SIZE/2, paint); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 " States of America."; | 156 " States of America."; |
| 158 | 157 |
| 159 const int BIG_H = 120; | 158 const int BIG_H = 120; |
| 160 | 159 |
| 161 SkPaint paint; | 160 SkPaint paint; |
| 162 paint.setAntiAlias(true); | 161 paint.setAntiAlias(true); |
| 163 paint.setTextSize(SkIntToScalar(BIG_H)); | 162 paint.setTextSize(SkIntToScalar(BIG_H)); |
| 164 | 163 |
| 165 const int BIG_W = SkScalarRoundToInt(paint.measureText(gText, strlen(gText))
); | 164 const int BIG_W = SkScalarRoundToInt(paint.measureText(gText, strlen(gText))
); |
| 166 | 165 |
| 167 bm->setConfig(SkBitmap::kARGB_8888_Config, BIG_W, BIG_H); | 166 bm->allocN32Pixels(BIG_W, BIG_H); |
| 168 bm->allocPixels(); | |
| 169 bm->eraseColor(SK_ColorWHITE); | 167 bm->eraseColor(SK_ColorWHITE); |
| 170 | 168 |
| 171 SkCanvas canvas(*bm); | 169 SkCanvas canvas(*bm); |
| 172 | 170 |
| 173 canvas.drawText(gText, strlen(gText), 0, paint.getTextSize()*4/5, paint); | 171 canvas.drawText(gText, strlen(gText), 0, paint.getTextSize()*4/5, paint); |
| 174 } | 172 } |
| 175 | 173 |
| 176 class BitmapRectView2 : public SampleView { | 174 class BitmapRectView2 : public SampleView { |
| 177 SkBitmap fBitmap; | 175 SkBitmap fBitmap; |
| 178 | 176 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 private: | 236 private: |
| 239 typedef SkView INHERITED; | 237 typedef SkView INHERITED; |
| 240 }; | 238 }; |
| 241 | 239 |
| 242 ////////////////////////////////////////////////////////////////////////////// | 240 ////////////////////////////////////////////////////////////////////////////// |
| 243 | 241 |
| 244 static SkView* F0() { return new BitmapRectView; } | 242 static SkView* F0() { return new BitmapRectView; } |
| 245 static SkView* F1() { return new BitmapRectView2; } | 243 static SkView* F1() { return new BitmapRectView2; } |
| 246 static SkViewRegister gR0(F0); | 244 static SkViewRegister gR0(F0); |
| 247 static SkViewRegister gR1(F1); | 245 static SkViewRegister gR1(F1); |
| OLD | NEW |