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

Side by Side Diff: experimental/example.cpp

Issue 1134113006: dm changes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: dm subset mode 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
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 void draw(SkCanvas* canvas) override {
64 // Clear background
65 canvas->drawColor(SK_ColorWHITE);
66
67 SkPaint paint;
68 // Draw a message with a nice black paint.
69 paint.setFlags(SkPaint::kAntiAlias_Flag);
70 paint.setColor(SK_ColorBLACK);
71 paint.setTextSize(SkIntToScalar(20));
72
73 static const char message[] = "Hello World!";
74
75 // Translate and draw the text:
76 canvas->save();
77 canvas->translate(SkIntToScalar(50), SkIntToScalar(100));
78 canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntToScal ar(0), paint);
79 canvas->restore();
80 }
81
82 bool setUpBackend() {
83 this->setColorType(kN32_SkColorType);
84 this->setVisibleP(true);
85 this->setClipToBounds(false);
86
87 bool result = attach(kNativeGL_BackEndType, 0 /*msaa*/, &fAttachmentInfo );
88 if (false == result) {
89 SkDebugf("Not possible to create backend.\n");
90 detach();
91 return false;
92 }
93
94 fInterface = GrGLCreateNativeInterface();
95
96 SkASSERT(NULL != fInterface);
97
98 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face);
99 SkASSERT(NULL != fContext);
100
101 this->setUpRenderTarget();
102 return true;
103 }
104
105 void setUpRenderTarget() {
106 SkSafeUnref(fRenderTarget);
107 fRenderTarget = this->renderTarget(fAttachmentInfo, fInterface, fContext );
108 }
109
110
111 private:
112 typedef SkOSWindow INHERITED;
113
114 SkScalar fRotationAngle;
115 SkString fName;
116 DeviceType fType;
117 SkSurface* fSurface;
118 GrContext* fContext;
119 GrRenderTarget* fRenderTarget;
120 AttachmentInfo fAttachmentInfo;
121 const GrGLInterface* fInterface;
122
123
124 };
125
126 SkOSWindow* create_sk_window(void* hwnd, int , char** ) {
127 return new ExampleWindow(hwnd);
128 }
129
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698