| Index: experimental/example.cpp
|
| diff --git a/experimental/example.cpp b/experimental/example.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0175f93b6b64565b875da6313a595babaaf1f3fd
|
| --- /dev/null
|
| +++ b/experimental/example.cpp
|
| @@ -0,0 +1,135 @@
|
| +/*
|
| + * Copyright 2015 Google Inc.
|
| + *
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + *
|
| + */
|
| +
|
| +
|
| +#include "SkSurface.h"
|
| +#include "SkWindow.h"
|
| +
|
| +#include "gl/GrGLInterface.h"
|
| +#include "SkApplication.h"
|
| +#include "SkCanvas.h"
|
| +#include "SkGradientShader.h"
|
| +#include "SkGraphics.h"
|
| +#include "SkGr.h"
|
| +#include "SkString.h"
|
| +
|
| +class SkCanvas;
|
| +
|
| +void application_init() {
|
| + SkGraphics::Init();
|
| + SkEvent::Init();
|
| +}
|
| +
|
| +void application_term() {
|
| + SkEvent::Term();
|
| + SkGraphics::Term();
|
| +}
|
| +
|
| +class ExampleWindow : public SkOSWindow {
|
| +public:
|
| + enum DeviceType {
|
| + kRaster_DeviceType,
|
| + kGPU_DeviceType,
|
| + };
|
| +
|
| + ExampleWindow(void* hwnd) : INHERITED(hwnd) {
|
| + fType = kGPU_DeviceType;
|
| + fRenderTarget = NULL;
|
| + fRotationAngle = 0;
|
| + fName = "Example";
|
| + this->setUpBackend();
|
| + }
|
| +
|
| + ~ExampleWindow() {
|
| + SkSafeUnref(fContext);
|
| + fContext = NULL;
|
| +
|
| + SkSafeUnref(fInterface);
|
| + fInterface = NULL;
|
| +
|
| + SkSafeUnref(fRenderTarget);
|
| + fRenderTarget = NULL;
|
| +
|
| + INHERITED::detach();
|
| + }
|
| +
|
| +protected:
|
| + SkSurface* createSurface() override {
|
| + SkSurfaceProps props(INHERITED::getSurfaceProps());
|
| + return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
|
| + }
|
| +
|
| + void draw(SkCanvas* canvas) override {
|
| + // Clear background
|
| + canvas->drawColor(SK_ColorWHITE);
|
| + SkPaint paint;
|
| + // Draw a message with a nice black paint.
|
| + paint.setFlags(SkPaint::kAntiAlias_Flag);
|
| + paint.setColor(SK_ColorBLACK);
|
| + paint.setTextSize(SkIntToScalar(20));
|
| +
|
| + static const char message[] = "Hello World!";
|
| +
|
| + // Translate and draw the text:
|
| + canvas->save();
|
| + canvas->translate(SkIntToScalar(50), SkIntToScalar(100));
|
| + canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntToScalar(0), paint);
|
| + canvas->restore();
|
| + fContext->flush();
|
| + INHERITED::present();
|
| + }
|
| +
|
| + bool setUpBackend() {
|
| + this->setColorType(kN32_SkColorType);
|
| + this->setVisibleP(true);
|
| + this->setClipToBounds(false);
|
| +
|
| + bool result = attach(kNativeGL_BackEndType, 0 /*msaa*/, &fAttachmentInfo);
|
| + if (false == result) {
|
| + SkDebugf("Not possible to create backend.\n");
|
| + detach();
|
| + return false;
|
| + }
|
| +
|
| + fInterface = GrGLCreateNativeInterface();
|
| +
|
| + SkASSERT(NULL != fInterface);
|
| +
|
| + fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInterface);
|
| + SkASSERT(NULL != fContext);
|
| +
|
| + this->setUpRenderTarget();
|
| + return true;
|
| + }
|
| +
|
| + void setUpRenderTarget() {
|
| + SkSafeUnref(fRenderTarget);
|
| + fRenderTarget = this->renderTarget(fAttachmentInfo, fInterface, fContext);
|
| + }
|
| +
|
| +
|
| +private:
|
| + typedef SkOSWindow INHERITED;
|
| +
|
| + SkScalar fRotationAngle;
|
| + SkString fName;
|
| + DeviceType fType;
|
| + SkSurface* fSurface;
|
| + GrContext* fContext;
|
| + GrRenderTarget* fRenderTarget;
|
| + AttachmentInfo fAttachmentInfo;
|
| + const GrGLInterface* fInterface;
|
| +
|
| +
|
| +};
|
| +
|
| +SkOSWindow* create_sk_window(void* hwnd, int , char** ) {
|
| + return new ExampleWindow(hwnd);
|
| +}
|
| +
|
|
|