Chromium Code Reviews| Index: helloskia/HelloSkia.cpp |
| diff --git a/helloskia/HelloSkia.cpp b/helloskia/HelloSkia.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1abd348de8444336c79bc2ca64a09f885c8fcce8 |
| --- /dev/null |
| +++ b/helloskia/HelloSkia.cpp |
| @@ -0,0 +1,90 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + * |
| + */ |
| + |
| +#include "HelloSkia.h" |
| + |
| +#include "SkGraphics.h" |
| +#include "SkDraw.h" |
| + |
| +#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
|
| +/* |
| +#include "gl/GrGLInterface.h" |
| +#include "gl/GrGLUtil.h" |
| +*/ |
|
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.
|
| +#include "GrRenderTarget.h" |
| +#include "GrContext.h" |
| +#include "SkGpuDevice.h" |
| +#endif |
| + |
| +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
|
| + return new HelloWindow(hwnd, argc, argv); |
| +} |
| + |
| +void application_init() { |
| +#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
|
| + setenv("ANDROID_ROOT", "/android/device/data", 0); |
| +#endif |
| + SkGraphics::Init(); |
| + SkEvent::Init(); |
| +} |
| + |
| +void application_term() { |
| + SkEvent::Term(); |
| + SkGraphics::Term(); |
| +} |
| + |
| +HelloWindow::HelloWindow(void* hWnd, int argc, char** argv) |
| + : INHERITED(hWnd) |
| +{ |
| + this->setConfig(SkBitmap::kARGB_8888_Config); |
| + this->setVisibleP(true); |
| + this->setClipToBounds(false); |
| + |
| + fBGColor = 0xffffffff; |
|
caryclark
2013/06/03 19:02:01
Use SK_ColorWHITE
sglez
2013/06/03 20:24:07
Done.
|
| + 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.
|
| +} |
| + |
| +void HelloWindow::draw(SkCanvas* canvas) { |
| + // Clear background |
| + canvas->drawColor(fBGColor); |
| + |
| + SkPaint paint; |
| + paint.setColor(0xff0000ff); // SkColor is ARGB |
| + |
|
caryclark
2013/06/03 19:02:01
Use SK_ColorBLUE etc
sglez
2013/06/03 20:24:08
Done.
|
| + // Draw a rectangle with blue paint |
| + SkRect rect = {10, 10, 128, 128}; |
| + 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.
|
| + |
| + // Draw a circle with anti aliased red paint |
| + paint.setFlags(SkPaint::kAntiAlias_Flag); |
| + paint.setColor(0xff00ff00); |
| + |
| + 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.
|
| + |
| + // Draw a message with a nice paint. |
| + paint.setFlags( |
| + SkPaint::kAntiAlias_Flag | |
| + SkPaint::kUnderlineText_Flag | |
| + SkPaint::kSubpixelText_Flag /* Do this to avoid waggly text when rotating. */); |
| + paint.setColor(0xff000000); |
| + paint.setTextSize(SkIntToScalar(20)); |
|
caryclark
2013/06/03 19:02:01
Consider bracketing all SkScalars like this
|
| + |
| + canvas->save(); |
| + static const char message[] = "Hello Skia!!!"; |
| + canvas->translate(300, 300); |
| + fRotationAngle += 0.2; |
|
caryclark
2013/06/03 19:02:01
You can use SkFloatToScalar here
sglez
2013/06/03 20:24:08
Done.
|
| + if (fRotationAngle > 360.0) { |
| + fRotationAngle -= 360.0; |
| + } |
| + canvas->rotate(fRotationAngle); |
| + canvas->drawText(message, strlen(message), 0, 0, paint); |
| + canvas->restore(); |
| + this->inval(NULL); |
| +} |
| + |