Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Unified Diff: experimental/example.cpp

Issue 1129903005: Figure out how to write a different HelloWorld. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make it work Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/example.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
+
« no previous file with comments | « no previous file | gyp/example.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698