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

Side by Side Diff: cmake/example.cpp

Issue 1817383002: switch surface to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « bench/nanobench.cpp ('k') | dm/DMGpuSupport.h » ('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 #include "../include/core/SkCanvas.h" 8 #include "../include/core/SkCanvas.h"
9 #include "../include/core/SkData.h" 9 #include "../include/core/SkData.h"
10 #include "../include/core/SkSurface.h" 10 #include "../include/core/SkSurface.h"
(...skipping 29 matching lines...) Expand all
40 #endif 40 #endif
41 41
42 // Most pointers returned by Skia are derived from SkRefCnt, 42 // Most pointers returned by Skia are derived from SkRefCnt,
43 // meaning we need to call ->unref() on them when done rather than delete them. 43 // meaning we need to call ->unref() on them when done rather than delete them.
44 template <typename T> std::shared_ptr<T> adopt(T* ptr) { 44 template <typename T> std::shared_ptr<T> adopt(T* ptr) {
45 return std::shared_ptr<T>(ptr, [](T* p) { p->unref(); }); 45 return std::shared_ptr<T>(ptr, [](T* p) { p->unref(); });
46 } 46 }
47 47
48 static std::shared_ptr<SkSurface> create_raster_surface(int w, int h) { 48 static std::shared_ptr<SkSurface> create_raster_surface(int w, int h) {
49 std::cout << "Using raster surface" << std::endl; 49 std::cout << "Using raster surface" << std::endl;
50 return adopt(SkSurface::NewRasterN32Premul(w, h)); 50 return adopt(SkSurface::MakeRasterN32Premul(w, h).release());
51 } 51 }
52 52
53 static std::shared_ptr<SkSurface> create_opengl_surface(int w, int h) { 53 static std::shared_ptr<SkSurface> create_opengl_surface(int w, int h) {
54 std::cout << "Using opengl surface" << std::endl; 54 std::cout << "Using opengl surface" << std::endl;
55 std::shared_ptr<GrContext> grContext = adopt(GrContext::Create(kOpenGL_GrBac kend, 0)); 55 std::shared_ptr<GrContext> grContext = adopt(GrContext::Create(kOpenGL_GrBac kend, 0));
56 return adopt(SkSurface::NewRenderTarget(grContext.get(), 56 return adopt(SkSurface::MakeRenderTarget(grContext.get(),
57 SkBudgeted::kNo, 57 SkBudgeted::kNo,
58 SkImageInfo::MakeN32Premul(w,h))); 58 SkImageInfo::MakeN32Premul(w,h)).rel ease());
59 } 59 }
60 60
61 int main(int, char**) { 61 int main(int, char**) {
62 bool gl_ok = setup_gl_context(); 62 bool gl_ok = setup_gl_context();
63 srand(time(nullptr)); 63 srand(time(nullptr));
64 std::shared_ptr<SkSurface> surface = (gl_ok && rand() % 2) ? create_opengl_s urface(320, 240) 64 std::shared_ptr<SkSurface> surface = (gl_ok && rand() % 2) ? create_opengl_s urface(320, 240)
65 : create_raster_s urface(320, 240); 65 : create_raster_s urface(320, 240);
66 66
67 // Create a left-to-right green-to-purple gradient shader. 67 // Create a left-to-right green-to-purple gradient shader.
68 SkPoint pts[] = { {0,0}, {320,240} }; 68 SkPoint pts[] = { {0,0}, {320,240} };
(...skipping 16 matching lines...) Expand all
85 std::shared_ptr<SkData> png = adopt(image->encode(SkImageEncoder::kPNG_Type, 100)); 85 std::shared_ptr<SkData> png = adopt(image->encode(SkImageEncoder::kPNG_Type, 100));
86 86
87 // This code is no longer Skia-specific. We just dump the .png to disk. An y way works. 87 // This code is no longer Skia-specific. We just dump the .png to disk. An y way works.
88 static const char* path = "example.png"; 88 static const char* path = "example.png";
89 std::ofstream(path, std::ios::out | std::ios::binary) 89 std::ofstream(path, std::ios::out | std::ios::binary)
90 .write((const char*)png->data(), png->size()); 90 .write((const char*)png->data(), png->size());
91 std::cout << "Wrote " << path << std::endl; 91 std::cout << "Wrote " << path << std::endl;
92 92
93 return 0; 93 return 0;
94 } 94 }
OLDNEW
« no previous file with comments | « bench/nanobench.cpp ('k') | dm/DMGpuSupport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698