Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include "HelloSkiaExample.h" | |
| 2 | |
| 3 #include "SkDraw.h" | |
| 4 #include "SkGradientShader.h" | |
| 5 #include "SkGraphics.h" | |
| 6 #include "SkUnitMappers.h" | |
| 7 | |
| 8 // The following three methods need to be defined so that your example | |
| 9 // runs on Linux and Mac. | |
|
sglez
2013/06/05 16:15:32
Running buildbots on linux, mac and windows is nex
| |
| 10 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { | |
| 11 return new HelloSkia(hwnd, argc, argv); | |
| 12 } | |
| 13 | |
| 14 void application_init() { | |
| 15 SkGraphics::Init(); | |
| 16 SkEvent::Init(); | |
| 17 } | |
| 18 | |
| 19 void application_term() { | |
| 20 SkEvent::Term(); | |
| 21 SkGraphics::Term(); | |
| 22 } | |
| 23 | |
| 24 HelloSkia::HelloSkia(void* hWnd, int argc, char** argv) | |
| 25 : INHERITED(hWnd, argc, argv) | |
| 26 { | |
| 27 fBGColor = SK_ColorWHITE; | |
| 28 fRotationAngle = SkIntToScalar(0); | |
| 29 | |
| 30 setupBackend(kGPU_DeviceType); | |
| 31 } | |
| 32 | |
| 33 void HelloSkia::draw(SkCanvas* canvas) { | |
| 34 // Clear background | |
| 35 canvas->drawColor(fBGColor); | |
| 36 | |
| 37 SkPaint paint; | |
| 38 paint.setColor(SK_ColorRED); // SkColor is ARGB | |
| 39 | |
| 40 // Draw a rectangle with blue paint | |
| 41 SkRect rect = {10, 10, 128, 128}; | |
| 42 canvas->drawRect(rect, paint); | |
| 43 | |
| 44 // Set up a linear gradient and draw a circle | |
| 45 { | |
| 46 SkPoint linearPoints[] = {{0, 0}, {SkIntToScalar(300), SkIntToScalar(300 )}}; | |
| 47 SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; | |
| 48 | |
| 49 SkUnitMapper* linearMapper = new SkDiscreteMapper(100); | |
| 50 SkAutoUnref lm_deleter(linearMapper); | |
| 51 | |
| 52 SkShader* shader = SkGradientShader::CreateLinear( | |
| 53 linearPoints, linearColors, NULL, 2, SkShader::kMirror_TileMode, linearMapper); | |
| 54 SkAutoUnref shader_deleter(shader); | |
| 55 | |
| 56 paint.setShader(shader); | |
| 57 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 58 | |
| 59 canvas->drawCircle(200, 200, 64, paint); | |
| 60 | |
| 61 // Detach shader | |
| 62 paint.setShader(NULL); | |
| 63 } | |
| 64 | |
| 65 | |
| 66 // Draw a message with a nice black paint. | |
| 67 paint.setFlags( | |
| 68 SkPaint::kAntiAlias_Flag | | |
| 69 SkPaint::kSubpixelText_Flag | // ... avoid waggly text when rotatin g. | |
| 70 SkPaint::kUnderlineText_Flag); | |
| 71 paint.setColor(SK_ColorBLACK); | |
| 72 paint.setTextSize(SkIntToScalar(20)); | |
| 73 | |
| 74 canvas->save(); | |
| 75 | |
| 76 static const char message[] = "Hello Skia!!!"; | |
| 77 | |
| 78 // Translate and rotate | |
| 79 canvas->translate(300, 300); | |
| 80 fRotationAngle += SkFloatToScalar(0.2); | |
| 81 if (fRotationAngle > SkFloatToScalar(360.0)) { | |
| 82 fRotationAngle -= SkFloatToScalar(360.0); | |
| 83 } | |
| 84 canvas->rotate(fRotationAngle); | |
| 85 | |
| 86 // Draw the text: | |
| 87 canvas->drawText(message, strlen(message), 0, 0, paint); | |
| 88 | |
| 89 canvas->restore(); | |
| 90 | |
| 91 // Invalidate the window to force a redraw. Poor man's animation mechanism. | |
| 92 this->inval(NULL); | |
| 93 canvas->flush(); | |
| 94 | |
| 95 if (getDeviceType() == kGPU_DeviceType) { | |
| 96 present(); | |
| 97 } | |
| 98 } | |
| 99 | |
| OLD | NEW |