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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/example.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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
11 #include "SkSurface.h"
12 #include "SkWindow.h"
13
14 #include "gl/GrGLInterface.h"
15 #include "SkApplication.h"
16 #include "SkCanvas.h"
17 #include "SkGradientShader.h"
18 #include "SkGraphics.h"
19 #include "SkGr.h"
20 #include "SkString.h"
21
22 class SkCanvas;
23
24 void application_init() {
25 SkGraphics::Init();
26 SkEvent::Init();
27 }
28
29 void application_term() {
30 SkEvent::Term();
31 SkGraphics::Term();
32 }
33
34 class ExampleWindow : public SkOSWindow {
35 public:
36 enum DeviceType {
37 kRaster_DeviceType,
38 kGPU_DeviceType,
39 };
40
41 ExampleWindow(void* hwnd) : INHERITED(hwnd) {
42 fType = kGPU_DeviceType;
43 fRenderTarget = NULL;
44 fRotationAngle = 0;
45 fName = "Example";
46 this->setUpBackend();
47 }
48
49 ~ExampleWindow() {
50 SkSafeUnref(fContext);
51 fContext = NULL;
52
53 SkSafeUnref(fInterface);
54 fInterface = NULL;
55
56 SkSafeUnref(fRenderTarget);
57 fRenderTarget = NULL;
58
59 INHERITED::detach();
60 }
61
62 protected:
63 SkSurface* createSurface() override {
64 SkSurfaceProps props(INHERITED::getSurfaceProps());
65 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
66 }
67
68 void draw(SkCanvas* canvas) override {
69 // Clear background
70 canvas->drawColor(SK_ColorWHITE);
71 SkPaint paint;
72 // Draw a message with a nice black paint.
73 paint.setFlags(SkPaint::kAntiAlias_Flag);
74 paint.setColor(SK_ColorBLACK);
75 paint.setTextSize(SkIntToScalar(20));
76
77 static const char message[] = "Hello World!";
78
79 // Translate and draw the text:
80 canvas->save();
81 canvas->translate(SkIntToScalar(50), SkIntToScalar(100));
82 canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntToScal ar(0), paint);
83 canvas->restore();
84 fContext->flush();
85 INHERITED::present();
86 }
87
88 bool setUpBackend() {
89 this->setColorType(kN32_SkColorType);
90 this->setVisibleP(true);
91 this->setClipToBounds(false);
92
93 bool result = attach(kNativeGL_BackEndType, 0 /*msaa*/, &fAttachmentInfo );
94 if (false == result) {
95 SkDebugf("Not possible to create backend.\n");
96 detach();
97 return false;
98 }
99
100 fInterface = GrGLCreateNativeInterface();
101
102 SkASSERT(NULL != fInterface);
103
104 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face);
105 SkASSERT(NULL != fContext);
106
107 this->setUpRenderTarget();
108 return true;
109 }
110
111 void setUpRenderTarget() {
112 SkSafeUnref(fRenderTarget);
113 fRenderTarget = this->renderTarget(fAttachmentInfo, fInterface, fContext );
114 }
115
116
117 private:
118 typedef SkOSWindow INHERITED;
119
120 SkScalar fRotationAngle;
121 SkString fName;
122 DeviceType fType;
123 SkSurface* fSurface;
124 GrContext* fContext;
125 GrRenderTarget* fRenderTarget;
126 AttachmentInfo fAttachmentInfo;
127 const GrGLInterface* fInterface;
128
129
130 };
131
132 SkOSWindow* create_sk_window(void* hwnd, int , char** ) {
133 return new ExampleWindow(hwnd);
134 }
135
OLDNEW
« 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