OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2013 Google Inc. | |
3 * | |
4 * | |
5 * Use of this source code is governed by a BSD-style license that can be | |
6 * found in the LICENSE file. | |
7 * | |
8 */ | |
9 | |
10 #include "HelloSkia.h" | |
11 | |
12 #include "SkGraphics.h" | |
13 #include "SkDraw.h" | |
14 | |
15 #if HELLOSKIA_USE_GPU | |
caryclark
2013/06/03 19:02:01
does the GPU version work yet?
sglez
2013/06/03 20:24:07
No, I'm posting the software version for review be
| |
16 /* | |
17 #include "gl/GrGLInterface.h" | |
18 #include "gl/GrGLUtil.h" | |
19 */ | |
caryclark
2013/06/03 19:02:01
Why commented out? If this documentation, include
sglez
2013/06/03 20:24:07
This shouldn't be here, sorry about that.
| |
20 #include "GrRenderTarget.h" | |
21 #include "GrContext.h" | |
22 #include "SkGpuDevice.h" | |
23 #endif | |
24 | |
25 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { | |
caryclark
2013/06/03 19:02:01
static
sglez
2013/06/03 20:24:07
These three functions need outside visibility sinc
caryclark
2013/06/04 11:48:12
Yes, you're right. I forgot the historic naming co
| |
26 return new HelloWindow(hwnd, argc, argv); | |
27 } | |
28 | |
29 void application_init() { | |
30 #ifdef SK_BUILD_FOR_MAC | |
caryclark
2013/06/03 19:02:01
I assume this is if SK_BUILD_FOR_ANDROID
sglez
2013/06/03 20:24:07
I had copied this from SampleApp.
I just now del
| |
31 setenv("ANDROID_ROOT", "/android/device/data", 0); | |
32 #endif | |
33 SkGraphics::Init(); | |
34 SkEvent::Init(); | |
35 } | |
36 | |
37 void application_term() { | |
38 SkEvent::Term(); | |
39 SkGraphics::Term(); | |
40 } | |
41 | |
42 HelloWindow::HelloWindow(void* hWnd, int argc, char** argv) | |
43 : INHERITED(hWnd) | |
44 { | |
45 this->setConfig(SkBitmap::kARGB_8888_Config); | |
46 this->setVisibleP(true); | |
47 this->setClipToBounds(false); | |
48 | |
49 fBGColor = 0xffffffff; | |
caryclark
2013/06/03 19:02:01
Use SK_ColorWHITE
sglez
2013/06/03 20:24:07
Done.
| |
50 fRotationAngle = 0.0; | |
caryclark
2013/06/03 19:02:01
Declare fRotationAngle as an SkScalar (if you have
sglez
2013/06/03 20:24:08
Done.
| |
51 } | |
52 | |
53 void HelloWindow::draw(SkCanvas* canvas) { | |
54 // Clear background | |
55 canvas->drawColor(fBGColor); | |
56 | |
57 SkPaint paint; | |
58 paint.setColor(0xff0000ff); // SkColor is ARGB | |
59 | |
caryclark
2013/06/03 19:02:01
Use SK_ColorBLUE etc
sglez
2013/06/03 20:24:08
Done.
| |
60 // Draw a rectangle with blue paint | |
61 SkRect rect = {10, 10, 128, 128}; | |
62 canvas->drawRect(rect, paint); | |
caryclark
2013/06/03 19:02:01
I assume you wanted to draw the rect aliased
sglez
2013/06/03 20:24:08
Yes, it was intentional.
| |
63 | |
64 // Draw a circle with anti aliased red paint | |
65 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
66 paint.setColor(0xff00ff00); | |
67 | |
68 canvas->drawCircle(200,200,64,paint); | |
caryclark
2013/06/03 19:02:01
put spaces after the commas (to be consistent with
sglez
2013/06/03 20:24:08
Done.
| |
69 | |
70 // Draw a message with a nice paint. | |
71 paint.setFlags( | |
72 SkPaint::kAntiAlias_Flag | | |
73 SkPaint::kUnderlineText_Flag | | |
74 SkPaint::kSubpixelText_Flag /* Do this to avoid waggly text when rot ating. */); | |
75 paint.setColor(0xff000000); | |
76 paint.setTextSize(SkIntToScalar(20)); | |
caryclark
2013/06/03 19:02:01
Consider bracketing all SkScalars like this
| |
77 | |
78 canvas->save(); | |
79 static const char message[] = "Hello Skia!!!"; | |
80 canvas->translate(300, 300); | |
81 fRotationAngle += 0.2; | |
caryclark
2013/06/03 19:02:01
You can use SkFloatToScalar here
sglez
2013/06/03 20:24:08
Done.
| |
82 if (fRotationAngle > 360.0) { | |
83 fRotationAngle -= 360.0; | |
84 } | |
85 canvas->rotate(fRotationAngle); | |
86 canvas->drawText(message, strlen(message), 0, 0, paint); | |
87 canvas->restore(); | |
88 this->inval(NULL); | |
89 } | |
90 | |
OLD | NEW |