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

Side by Side Diff: tests/SerializationTest.cpp

Issue 513983002: Try out scalar picture sizes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT again Created 6 years, 3 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 | « tests/PictureTest.cpp ('k') | tools/PictureRenderer.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 2013 Google Inc. 2 * Copyright 2013 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 "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 canvas.clear(0x00000000); 256 canvas.clear(0x00000000);
257 SkPaint paint; 257 SkPaint paint;
258 paint.setImageFilter(deserializedFilter); 258 paint.setImageFilter(deserializedFilter);
259 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24))); 259 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24)));
260 canvas.drawBitmap(bitmap, 0, 0, &paint); 260 canvas.drawBitmap(bitmap, 0, 0, &paint);
261 } 261 }
262 } 262 }
263 263
264 static SkBitmap draw_picture(SkPicture& picture) { 264 static SkBitmap draw_picture(SkPicture& picture) {
265 SkBitmap bitmap; 265 SkBitmap bitmap;
266 bitmap.allocN32Pixels(picture.width(), picture.height()); 266 bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()),
267 SkScalarCeilToInt(picture.cullRect().height()));
267 SkCanvas canvas(bitmap); 268 SkCanvas canvas(bitmap);
268 picture.draw(&canvas); 269 picture.draw(&canvas);
269 return bitmap; 270 return bitmap;
270 } 271 }
271 272
272 static void compare_bitmaps(skiatest::Reporter* reporter, 273 static void compare_bitmaps(skiatest::Reporter* reporter,
273 const SkBitmap& b1, const SkBitmap& b2) { 274 const SkBitmap& b1, const SkBitmap& b2) {
274 REPORTER_ASSERT(reporter, b1.width() == b2.width()); 275 REPORTER_ASSERT(reporter, b1.width() == b2.width());
275 REPORTER_ASSERT(reporter, b1.height() == b2.height()); 276 REPORTER_ASSERT(reporter, b1.height() == b2.height());
276 SkAutoLockPixels autoLockPixels1(b1); 277 SkAutoLockPixels autoLockPixels1(b1);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 309
309 // Create a paint with the typeface we loaded. 310 // Create a paint with the typeface we loaded.
310 SkPaint paint; 311 SkPaint paint;
311 paint.setColor(SK_ColorGRAY); 312 paint.setColor(SK_ColorGRAY);
312 paint.setTextSize(SkIntToScalar(30)); 313 paint.setTextSize(SkIntToScalar(30));
313 SkSafeUnref(paint.setTypeface(typeface)); 314 SkSafeUnref(paint.setTypeface(typeface));
314 315
315 // Paint some text. 316 // Paint some text.
316 SkPictureRecorder recorder; 317 SkPictureRecorder recorder;
317 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); 318 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize);
318 SkCanvas* canvas = recorder.beginRecording(canvasRect.width(), canvasRect.he ight(), NULL, 0); 319 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()) ,
320 SkIntToScalar(canvasRect.height() ),
321 NULL, 0);
319 canvas->drawColor(SK_ColorWHITE); 322 canvas->drawColor(SK_ColorWHITE);
320 canvas->drawText("A", 1, 24, 32, paint); 323 canvas->drawText("A", 1, 24, 32, paint);
321 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 324 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
322 325
323 // Serlialize picture and create its clone from stream. 326 // Serlialize picture and create its clone from stream.
324 SkDynamicMemoryWStream stream; 327 SkDynamicMemoryWStream stream;
325 picture->serialize(&stream); 328 picture->serialize(&stream);
326 SkAutoTUnref<SkStream> inputStream(stream.detachAsStream()); 329 SkAutoTUnref<SkStream> inputStream(stream.detachAsStream());
327 SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStrea m.get())); 330 SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStrea m.get()));
328 331
(...skipping 28 matching lines...) Expand all
357 canvas.drawRect(SkRect::MakeXYWH(f, 0, f, f), lightPaint); 360 canvas.drawRect(SkRect::MakeXYWH(f, 0, f, f), lightPaint);
358 canvas.drawRect(SkRect::MakeXYWH(0, f, f, f), lightPaint); 361 canvas.drawRect(SkRect::MakeXYWH(0, f, f, f), lightPaint);
359 canvas.drawRect(SkRect::MakeXYWH(f, f, f, f), darkPaint); 362 canvas.drawRect(SkRect::MakeXYWH(f, f, f, f), darkPaint);
360 canvas.restore(); 363 canvas.restore();
361 } 364 }
362 } 365 }
363 366
364 return success; 367 return success;
365 } 368 }
366 369
367 static bool drawSomething(SkCanvas* canvas) { 370 static bool draw_something(SkCanvas* canvas) {
368 SkPaint paint; 371 SkPaint paint;
369 SkBitmap bitmap; 372 SkBitmap bitmap;
370 bool success = make_checkerboard_bitmap(bitmap); 373 bool success = make_checkerboard_bitmap(bitmap);
371 374
372 canvas->save(); 375 canvas->save();
373 canvas->scale(0.5f, 0.5f); 376 canvas->scale(0.5f, 0.5f);
374 canvas->drawBitmap(bitmap, 0, 0, NULL); 377 canvas->drawBitmap(bitmap, 0, 0, NULL);
375 canvas->restore(); 378 canvas->restore();
376 379
377 const char beforeStr[] = "before circle"; 380 const char beforeStr[] = "before circle";
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 invalidBitmap.setInfo(info); 474 invalidBitmap.setInfo(info);
472 475
473 // The deserialization should succeed, and the rendering shouldn't crash , 476 // The deserialization should succeed, and the rendering shouldn't crash ,
474 // even when the device fails to initialize, due to its size 477 // even when the device fails to initialize, due to its size
475 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); 478 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter);
476 } 479 }
477 480
478 // Test simple SkPicture serialization 481 // Test simple SkPicture serialization
479 { 482 {
480 SkPictureRecorder recorder; 483 SkPictureRecorder recorder;
481 bool didDraw = drawSomething(recorder.beginRecording(kBitmapSize, kBitma pSize, NULL, 0)); 484 bool didDraw = draw_something(recorder.beginRecording(SkIntToScalar(kBit mapSize),
485 SkIntToScalar(kBit mapSize),
486 NULL, 0));
482 REPORTER_ASSERT(reporter, didDraw); 487 REPORTER_ASSERT(reporter, didDraw);
483 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 488 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
484 489
485 // Serialize picture 490 // Serialize picture
486 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); 491 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
487 pict->flatten(writer); 492 pict->flatten(writer);
488 size_t size = writer.bytesWritten(); 493 size_t size = writer.bytesWritten();
489 SkAutoTMalloc<unsigned char> data(size); 494 SkAutoTMalloc<unsigned char> data(size);
490 writer.writeToMemory(static_cast<void*>(data.get())); 495 writer.writeToMemory(static_cast<void*>(data.get()));
491 496
492 // Deserialize picture 497 // Deserialize picture
493 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); 498 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size);
494 SkAutoTUnref<SkPicture> readPict( 499 SkAutoTUnref<SkPicture> readPict(
495 SkPicture::CreateFromBuffer(reader)); 500 SkPicture::CreateFromBuffer(reader));
496 REPORTER_ASSERT(reporter, NULL != readPict.get()); 501 REPORTER_ASSERT(reporter, NULL != readPict.get());
497 } 502 }
498 503
499 TestPictureTypefaceSerialization(reporter); 504 TestPictureTypefaceSerialization(reporter);
500 } 505 }
OLDNEW
« no previous file with comments | « tests/PictureTest.cpp ('k') | tools/PictureRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698