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

Side by Side Diff: cmake/example.cpp

Issue 1803783002: Reland of "Finish conversion to sk_sp<SkShader> (patchset #2 id:20001 of https://codereview.chromiu… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update cmake example 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/TileBench.cpp ('k') | example/HelloWorld.cpp » ('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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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} };
69 SkColor colors[] = { 0xFF00FF00, 0xFFFF00FF }; 69 SkColor colors[] = { 0xFF00FF00, 0xFFFF00FF };
70 std::shared_ptr<SkShader> shader = adopt(
71 SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kR epeat_TileMode));
72
73 // Our text will draw with this paint: size 24, antialiased, with the shader . 70 // Our text will draw with this paint: size 24, antialiased, with the shader .
74 SkPaint paint; 71 SkPaint paint;
75 paint.setTextSize(24); 72 paint.setTextSize(24);
76 paint.setAntiAlias(true); 73 paint.setAntiAlias(true);
77 paint.setShader(shader.get()); 74 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShad er::kRepeat_TileMode));
78 75
79 // Draw to the surface via its SkCanvas. 76 // Draw to the surface via its SkCanvas.
80 SkCanvas* canvas = surface->getCanvas(); // We don't manage this pointer's lifetime. 77 SkCanvas* canvas = surface->getCanvas(); // We don't manage this pointer's lifetime.
81 static const char* msg = "Hello world!"; 78 static const char* msg = "Hello world!";
82 canvas->clear(SK_ColorWHITE); 79 canvas->clear(SK_ColorWHITE);
83 canvas->drawText(msg, strlen(msg), 90,120, paint); 80 canvas->drawText(msg, strlen(msg), 90,120, paint);
84 81
85 // Grab a snapshot of the surface as an immutable SkImage. 82 // Grab a snapshot of the surface as an immutable SkImage.
86 std::shared_ptr<SkImage> image = adopt(surface->newImageSnapshot()); 83 std::shared_ptr<SkImage> image = adopt(surface->newImageSnapshot());
87 // Encode that image as a .png into a blob in memory. 84 // Encode that image as a .png into a blob in memory.
88 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));
89 86
90 // 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.
91 static const char* path = "example.png"; 88 static const char* path = "example.png";
92 std::ofstream(path, std::ios::out | std::ios::binary) 89 std::ofstream(path, std::ios::out | std::ios::binary)
93 .write((const char*)png->data(), png->size()); 90 .write((const char*)png->data(), png->size());
94 std::cout << "Wrote " << path << std::endl; 91 std::cout << "Wrote " << path << std::endl;
95 92
96 return 0; 93 return 0;
97 } 94 }
OLDNEW
« no previous file with comments | « bench/TileBench.cpp ('k') | example/HelloWorld.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698