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

Side by Side Diff: example/SkiaSDLExample.cpp

Issue 2210603003: Get Mac viewer working with SDL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix patch Created 4 years, 4 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/viewer.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 * 6 *
7 */ 7 */
8 8
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "SDL.h" 10 #include "SDL.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkRandom.h" 12 #include "SkRandom.h"
13 #include "SkSurface.h" 13 #include "SkSurface.h"
14 14
15 #include "gl/GrGLInterface.h" 15 #include "gl/GrGLInterface.h"
16 #include "gl/GrGLUtil.h" 16 #include "gl/GrGLUtil.h"
17 17
18 #if defined(SK_BUILD_FOR_ANDROID) 18 #if defined(SK_BUILD_FOR_ANDROID)
19 #include <GLES/gl.h> 19 #include <GLES/gl.h>
20 #elif defined(SK_BUILD_FOR_UNIX) 20 #elif defined(SK_BUILD_FOR_UNIX)
21 #include <GL/gl.h> 21 #include <GL/gl.h>
22 #elif defined(SK_BUILD_FOR_MAC) 22 #elif defined(SK_BUILD_FOR_MAC)
23 #include <gl.h> 23 #include <OpenGL/gl.h>
24 #endif 24 #endif
25 25
26 /* 26 /*
27 * This application is a simple example of how to combine SDL and Skia it demons trates: 27 * This application is a simple example of how to combine SDL and Skia it demons trates:
28 * how to setup gpu rendering to the main window 28 * how to setup gpu rendering to the main window
29 * how to perform cpu-side rendering and draw the result to the gpu-backed scr een 29 * how to perform cpu-side rendering and draw the result to the gpu-backed scr een
30 * draw simple primitives (rectangles) 30 * draw simple primitives (rectangles)
31 * draw more complex primitives (star) 31 * draw more complex primitives (star)
32 */ 32 */
33 33
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 SkCanvas* canvas = surface->getCanvas(); 218 SkCanvas* canvas = surface->getCanvas();
219 219
220 ApplicationState state; 220 ApplicationState state;
221 221
222 const char* helpMessage = "Click and drag to create rects. Press esc to qui t."; 222 const char* helpMessage = "Click and drag to create rects. Press esc to qui t.";
223 223
224 SkPaint paint; 224 SkPaint paint;
225 225
226 // create a surface for CPU rasterization 226 // create a surface for CPU rasterization
227 SkAutoTUnref<SkSurface> cpuSurface(SkSurface::NewRaster(canvas->imageInfo()) ); 227 sk_sp<SkSurface> cpuSurface(SkSurface::MakeRaster(canvas->imageInfo()));
228 228
229 SkCanvas* offscreen = cpuSurface->getCanvas(); 229 SkCanvas* offscreen = cpuSurface->getCanvas();
230 offscreen->save(); 230 offscreen->save();
231 offscreen->translate(50.0f, 50.0f); 231 offscreen->translate(50.0f, 50.0f);
232 offscreen->drawPath(create_star(), paint); 232 offscreen->drawPath(create_star(), paint);
233 offscreen->restore(); 233 offscreen->restore();
234 234
235 SkAutoTUnref<SkImage> image(cpuSurface->newImageSnapshot()); 235 sk_sp<SkImage> image = cpuSurface->makeImageSnapshot();
236 236
237 int rotation = 0; 237 int rotation = 0;
238 while (!state.fQuit) { // Our application loop 238 while (!state.fQuit) { // Our application loop
239 SkRandom rand; 239 SkRandom rand;
240 canvas->clear(SK_ColorWHITE); 240 canvas->clear(SK_ColorWHITE);
241 handle_events(&state, canvas); 241 handle_events(&state, canvas);
242 242
243 paint.setColor(SK_ColorBLACK); 243 paint.setColor(SK_ColorBLACK);
244 canvas->drawText(helpMessage, strlen(helpMessage), SkIntToScalar(100), 244 canvas->drawText(helpMessage, strlen(helpMessage), SkIntToScalar(100),
245 SkIntToScalar(100), paint); 245 SkIntToScalar(100), paint);
(...skipping 17 matching lines...) Expand all
263 SDL_GL_DeleteContext(glContext); 263 SDL_GL_DeleteContext(glContext);
264 } 264 }
265 265
266 //Destroy window 266 //Destroy window
267 SDL_DestroyWindow(window); 267 SDL_DestroyWindow(window);
268 268
269 //Quit SDL subsystems 269 //Quit SDL subsystems
270 SDL_Quit(); 270 SDL_Quit();
271 return 0; 271 return 0;
272 } 272 }
OLDNEW
« no previous file with comments | « no previous file | gyp/viewer.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698