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

Side by Side Diff: experimental/nanomsg/picture_demo.cpp

Issue 1831053002: Relocate SK_SUPPORT_LEGACY_PICTURE_PTR (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: picture_demo.cpp fix 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 | « no previous file | gyp/skia_for_android_framework_defines.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
1 #include "nanomsg/src/nn.h" 8 #include "nanomsg/src/nn.h"
2 #include "nanomsg/src/pipeline.h" 9 #include "nanomsg/src/pipeline.h"
3 #include "nanomsg/src/reqrep.h" 10 #include "nanomsg/src/reqrep.h"
4 11
5 #include "SkCanvas.h" 12 #include "SkCanvas.h"
6 #include "SkCommandLineFlags.h" 13 #include "SkCommandLineFlags.h"
7 #include "SkData.h" 14 #include "SkData.h"
8 #include "SkForceLinking.h" 15 #include "SkForceLinking.h"
9 #include "SkGraphics.h" 16 #include "SkGraphics.h"
10 #include "SkImageEncoder.h" 17 #include "SkImageEncoder.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 }; 53 };
47 54
48 struct nn_msghdr msg; 55 struct nn_msghdr msg;
49 sk_bzero(&msg, sizeof(msg)); 56 sk_bzero(&msg, sizeof(msg));
50 msg.msg_iov = iov; 57 msg.msg_iov = iov;
51 msg.msg_iovlen = SK_ARRAY_COUNT(iov); 58 msg.msg_iovlen = SK_ARRAY_COUNT(iov);
52 59
53 nn_sendmsg(socket, &msg, 0/*flags*/); 60 nn_sendmsg(socket, &msg, 0/*flags*/);
54 } 61 }
55 62
56 static SkPicture* recv_picture(int socket, PictureHeader* header) { 63 static sk_sp<SkPicture> recv_picture(int socket, PictureHeader* header) {
57 static const size_t hSize = sizeof(*header); // It's easy to slip up and us e sizeof(header). 64 static const size_t hSize = sizeof(*header); // It's easy to slip up and us e sizeof(header).
58 65
59 void* msg; 66 void* msg;
60 int size = nn_recv(socket, &msg, NN_MSG, 0/*flags*/); 67 int size = nn_recv(socket, &msg, NN_MSG, 0/*flags*/);
61 SkDebugf("%d bytes", size); 68 SkDebugf("%d bytes", size);
62 69
63 // msg is first a fixed-size header, then an .skp. 70 // msg is first a fixed-size header, then an .skp.
64 memcpy(header, msg, hSize); 71 memcpy(header, msg, hSize);
65 SkMemoryStream stream((uint8_t*)msg + hSize, size - hSize); 72 SkMemoryStream stream((uint8_t*)msg + hSize, size - hSize);
66 SkPicture* pic = SkPicture::CreateFromStream(&stream); 73 sk_sp<SkPicture> pic = SkPicture::MakeFromStream(&stream);
67 74
68 SkDebugf(" from proccess %d:", header->pid); 75 SkDebugf(" from proccess %d:", header->pid);
69 76
70 nn_freemsg(msg); 77 nn_freemsg(msg);
71 return pic; 78 return pic;
72 } 79 }
73 80
74 static void client(const char* skpPath, const char* dataEndpoint) { 81 static void client(const char* skpPath, const char* dataEndpoint) {
75 // Read the .skp. 82 // Read the .skp.
76 SkAutoTUnref<const SkData> skp(SkData::NewFromFileName(skpPath)); 83 SkAutoTUnref<const SkData> skp(SkData::NewFromFileName(skpPath));
77 if (!skp) { 84 if (!skp) {
78 SkDebugf("Couldn't read %s\n", skpPath); 85 SkDebugf("Couldn't read %s\n", skpPath);
79 exit(1); 86 exit(1);
80 } 87 }
81 SkMemoryStream stream(skp->data(), skp->size()); 88 SkMemoryStream stream(skp->data(), skp->size());
82 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&stream)); 89 sk_sp<SkPicture> picture(SkPicture::MakeFromStream(&stream));
83 90
84 PictureHeader header; 91 PictureHeader header;
85 SkRandom rand(picture->cullRect().width() * picture->cullRect().height()); 92 SkRandom rand(picture->cullRect().width() * picture->cullRect().height());
86 SkScalar r = rand.nextRangeScalar(0, picture->cullRect().width()), 93 SkScalar r = rand.nextRangeScalar(0, picture->cullRect().width()),
87 b = rand.nextRangeScalar(0, picture->cullRect().height()), 94 b = rand.nextRangeScalar(0, picture->cullRect().height()),
88 l = rand.nextRangeScalar(0, r), 95 l = rand.nextRangeScalar(0, r),
89 t = rand.nextRangeScalar(0, b); 96 t = rand.nextRangeScalar(0, b);
90 header.clip.setLTRB(l,t,r,b); 97 header.clip.setLTRB(l,t,r,b);
91 header.matrix.setTranslate(-l, -t); 98 header.matrix.setTranslate(-l, -t);
92 header.matrix.postRotate(rand.nextRangeScalar(-25, 25)); 99 header.matrix.postRotate(rand.nextRangeScalar(-25, 25));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 while (true) { 143 while (true) {
137 int ready = poll_in(data, control); 144 int ready = poll_in(data, control);
138 145
139 // If we got any message on the control socket, we can stop. 146 // If we got any message on the control socket, we can stop.
140 if (ready == control) { 147 if (ready == control) {
141 break; 148 break;
142 } 149 }
143 150
144 // We should have an .skp waiting for us on data socket. 151 // We should have an .skp waiting for us on data socket.
145 PictureHeader header; 152 PictureHeader header;
146 SkAutoTUnref<SkPicture> picture(recv_picture(data, &header)); 153 sk_sp<SkPicture> picture(recv_picture(data, &header));
147 154
148 SkPaint paint; 155 SkPaint paint;
149 paint.setAlpha(header.alpha); 156 paint.setAlpha(header.alpha);
150 paint.setXfermodeMode(header.xfermode); 157 paint.setXfermodeMode(header.xfermode);
151 158
152 canvas->saveLayer(NULL, &paint); 159 canvas->saveLayer(NULL, &paint);
153 canvas->concat(header.matrix); 160 canvas->concat(header.matrix);
154 canvas->clipRect(header.clip); 161 canvas->clipRect(header.clip);
155 picture->playback(canvas); 162 picture->playback(canvas);
156 canvas->restore(); 163 canvas->restore();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 205
199 server(FLAGS_data[0], FLAGS_control[0], &canvas); 206 server(FLAGS_data[0], FLAGS_control[0], &canvas);
200 canvas.flush(); 207 canvas.flush();
201 208
202 SkImageEncoder::EncodeFile(FLAGS_png[0], bitmap, SkImageEncoder::kPNG_Ty pe, 100); 209 SkImageEncoder::EncodeFile(FLAGS_png[0], bitmap, SkImageEncoder::kPNG_Ty pe, 100);
203 SkDebugf("Wrote %s.\n", FLAGS_png[0]); 210 SkDebugf("Wrote %s.\n", FLAGS_png[0]);
204 } 211 }
205 212
206 return 0; 213 return 0;
207 } 214 }
OLDNEW
« no previous file with comments | « no previous file | gyp/skia_for_android_framework_defines.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698