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

Side by Side Diff: tests/FlattenDrawableTest.cpp

Issue 1913843002: Enable flattening of SkRecordedDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Consider registering SkRecordedDrawable without the global registry Created 4 years, 8 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
« src/core/SkReadBuffer.cpp ('K') | « src/core/SkReadBuffer.cpp ('k') | no next file » | 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 2016 Google Inc. 2 * Copyright 2016 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkDrawable.h" 9 #include "SkDrawable.h"
10 #include "SkOnce.h" 10 #include "SkOnce.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // Note that we can still recognize the generic drawable as an IntDrawable 240 // Note that we can still recognize the generic drawable as an IntDrawable
241 SkDrawable* generic = rootOut->drawable(); 241 SkDrawable* generic = rootOut->drawable();
242 REPORTER_ASSERT(r, !strcmp("IntDrawable", generic->getTypeName())); 242 REPORTER_ASSERT(r, !strcmp("IntDrawable", generic->getTypeName()));
243 IntDrawable* integer = (IntDrawable*) generic; 243 IntDrawable* integer = (IntDrawable*) generic;
244 REPORTER_ASSERT(r, 1 == integer->a()); 244 REPORTER_ASSERT(r, 1 == integer->a());
245 REPORTER_ASSERT(r, 2 == integer->b()); 245 REPORTER_ASSERT(r, 2 == integer->b());
246 REPORTER_ASSERT(r, 3 == integer->c()); 246 REPORTER_ASSERT(r, 3 == integer->c());
247 REPORTER_ASSERT(r, 4 == integer->d()); 247 REPORTER_ASSERT(r, 4 == integer->d());
248 } 248 }
249 249
250 DEF_TEST(FlattenRecordedDrawable, r) {
251 register_test_drawables_once();
252
253 // Record a set of canvas draw commands
254 SkPictureRecorder recorder;
255 SkCanvas* canvas = recorder.beginRecording(1000.0f, 1000.0f);
256 canvas->drawPoint(42.0f, 17.0f, SK_ColorGREEN);
257 SkPaint paint;
258 paint.setColor(SK_ColorRED);
259 canvas->drawPaint(paint);
260 SkPaint textPaint;
261 textPaint.setColor(SK_ColorBLUE);
262 canvas->drawText("TEXT", 354.0f, 467.0f, 100.0f, textPaint);
263
264 // Draw some drawables as well
265 SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4));
266 SkAutoTUnref<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 1 1, 12, drawable));
267 canvas->drawDrawable(root, 747.0f, 242.0f);
268 SkAutoTUnref<PaintDrawable> paintDrawable(new PaintDrawable(paint));
269 canvas->drawDrawable(paintDrawable, 500.0, 500.0f);
270 SkAutoTUnref<CompoundDrawable> comDrawable(new CompoundDrawable(13, 14, 15, 16, textPaint));
271 canvas->drawDrawable(comDrawable, 10.0f, 10.0f);
272
273 // Serialize the recorded drawable
274 sk_sp<SkDrawable> recordedDrawable = recorder.finishRecordingAsDrawable();
275 SkWriteBuffer writeBuffer;
276 writeBuffer.writeFlattenable(recordedDrawable.get());
277
278 // Copy the contents of the write buffer into a read buffer
279 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten());
280 writeBuffer.writeToMemory(data->writable_data());
281 SkReadBuffer readBuffer(data->data(), data->size());
282 readBuffer.initDrawableFactories();
djsollen 2016/04/27 13:05:40 seems awkward that I need to need to register fact
msarett 2016/04/27 13:24:17 That was original approach in Patch Sets 1 and 2.
283
284 // Deserialize and verify the drawable
285 SkAutoTUnref<SkDrawable> out((SkDrawable*)
286 readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type));
287 REPORTER_ASSERT(r, out);
288 REPORTER_ASSERT(r, !strcmp("SkRecordedDrawable", out->getTypeName()));
289 }
290
250 static sk_sp<SkFlattenable> custom_create_proc(SkReadBuffer& buffer) { 291 static sk_sp<SkFlattenable> custom_create_proc(SkReadBuffer& buffer) {
251 sk_sp<SkFlattenable> drawable = IntDrawable::CreateProc(buffer); 292 sk_sp<SkFlattenable> drawable = IntDrawable::CreateProc(buffer);
252 IntDrawable* intDrawable = (IntDrawable*) drawable.get(); 293 IntDrawable* intDrawable = (IntDrawable*) drawable.get();
253 return sk_sp<IntDrawable>(new IntDrawable(intDrawable->a() + 1, intDrawable- >b() + 1, 294 return sk_sp<IntDrawable>(new IntDrawable(intDrawable->a() + 1, intDrawable- >b() + 1,
254 intDrawable->c() + 1, intDrawable- >d() + 1)); 295 intDrawable->c() + 1, intDrawable- >d() + 1));
255 } 296 }
256 297
257 DEF_TEST(FlattenCustomDrawable, r) { 298 DEF_TEST(FlattenCustomDrawable, r) {
258 // No need to register the drawables since we will be using a custom proc. 299 // No need to register the drawables since we will be using a custom proc.
259 300
(...skipping 12 matching lines...) Expand all
272 313
273 // Deserialize and verify the drawable 314 // Deserialize and verify the drawable
274 SkAutoTUnref<IntDrawable> out((IntDrawable*) 315 SkAutoTUnref<IntDrawable> out((IntDrawable*)
275 readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type)); 316 readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type));
276 REPORTER_ASSERT(r, out); 317 REPORTER_ASSERT(r, out);
277 REPORTER_ASSERT(r, 2 == out->a()); 318 REPORTER_ASSERT(r, 2 == out->a());
278 REPORTER_ASSERT(r, 3 == out->b()); 319 REPORTER_ASSERT(r, 3 == out->b());
279 REPORTER_ASSERT(r, 4 == out->c()); 320 REPORTER_ASSERT(r, 4 == out->c());
280 REPORTER_ASSERT(r, 5 == out->d()); 321 REPORTER_ASSERT(r, 5 == out->d());
281 } 322 }
OLDNEW
« src/core/SkReadBuffer.cpp ('K') | « src/core/SkReadBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698