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

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: Fix backward compatibility Created 4 years, 7 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 | « src/core/SkRecordedDrawable.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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
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
250 DEF_TEST(FlattenRecordedDrawable, r) {
251 // Record a set of canvas draw commands
252 SkPictureRecorder recorder;
253 SkCanvas* canvas = recorder.beginRecording(1000.0f, 1000.0f);
254 canvas->drawPoint(42.0f, 17.0f, SK_ColorGREEN);
255 SkPaint paint;
256 paint.setColor(SK_ColorRED);
257 canvas->drawPaint(paint);
258 SkPaint textPaint;
259 textPaint.setColor(SK_ColorBLUE);
260 canvas->drawText("TEXT", 4, 467.0f, 100.0f, textPaint);
261
262 // Draw some drawables as well
263 SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4));
264 SkAutoTUnref<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 1 1, 12, drawable));
265 canvas->drawDrawable(root, 747.0f, 242.0f);
266 SkAutoTUnref<PaintDrawable> paintDrawable(new PaintDrawable(paint));
267 canvas->drawDrawable(paintDrawable, 500.0, 500.0f);
268 SkAutoTUnref<CompoundDrawable> comDrawable(new CompoundDrawable(13, 14, 15, 16, textPaint));
269 canvas->drawDrawable(comDrawable, 10.0f, 10.0f);
270
271 // Serialize the recorded drawable
272 sk_sp<SkDrawable> recordedDrawable = recorder.finishRecordingAsDrawable();
273 SkWriteBuffer writeBuffer;
274 writeBuffer.writeFlattenable(recordedDrawable.get());
275
276 // Copy the contents of the write buffer into a read buffer
277 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten());
278 writeBuffer.writeToMemory(data->writable_data());
279 SkReadBuffer readBuffer(data->data(), data->size());
280 register_test_drawables(readBuffer);
281
282 // Deserialize and verify the drawable
283 SkAutoTUnref<SkDrawable> out((SkDrawable*)
284 readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type));
285 REPORTER_ASSERT(r, out);
286 REPORTER_ASSERT(r, !strcmp("SkRecordedDrawable", out->getTypeName()));
287 }
OLDNEW
« no previous file with comments | « src/core/SkRecordedDrawable.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698