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

Side by Side Diff: tests/PictureTest.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on 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 | « tests/PictureShaderTest.cpp ('k') | tests/RecorderTest.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 2012 Google Inc. 2 * Copyright 2012 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 "SkBBoxHierarchy.h" 8 #include "SkBBoxHierarchy.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 canvas = recorder.beginRecording(100, 100); 73 canvas = recorder.beginRecording(100, 100);
74 { 74 {
75 SkPaint paint; 75 SkPaint paint;
76 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad er 76 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad er
77 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here . 77 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here .
78 SkBitmap bitmap; 78 SkBitmap bitmap;
79 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); 79 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
80 bitmap.eraseColor(SK_ColorBLUE); 80 bitmap.eraseColor(SK_ColorBLUE);
81 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN; 81 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
82 SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp _TileMode, 82 paint.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_Tile Mode,
83 SkShader::kClamp_TileMod e); 83 SkShader::kClamp_TileMode));
84 paint.setShader(shader)->unref(); 84 REPORTER_ASSERT(reporter, paint.getShader()->isABitmap());
85 REPORTER_ASSERT(reporter, shader->isABitmap());
86 85
87 canvas->drawRect(SkRect::MakeWH(10, 10), paint); 86 canvas->drawRect(SkRect::MakeWH(10, 10), paint);
88 } 87 }
89 picture.reset(recorder.endRecording()); 88 picture.reset(recorder.endRecording());
90 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps()); 89 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
91 } 90 }
92 91
93 92
94 #ifdef SK_DEBUG 93 #ifdef SK_DEBUG
95 // Ensure that deleting an empty SkPicture does not assert. Asserts only fire 94 // Ensure that deleting an empty SkPicture does not assert. Asserts only fire
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 rec.beginRecording(100, 100); 1381 rec.beginRecording(100, 100);
1383 REPORTER_ASSERT(r, rec.getRecordingCanvas()); 1382 REPORTER_ASSERT(r, rec.getRecordingCanvas());
1384 rec.endRecording()->unref(); 1383 rec.endRecording()->unref();
1385 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); 1384 REPORTER_ASSERT(r, !rec.getRecordingCanvas());
1386 } 1385 }
1387 } 1386 }
1388 1387
1389 DEF_TEST(MiniRecorderLeftHanging, r) { 1388 DEF_TEST(MiniRecorderLeftHanging, r) {
1390 // Any shader or other ref-counted effect will do just fine here. 1389 // Any shader or other ref-counted effect will do just fine here.
1391 SkPaint paint; 1390 SkPaint paint;
1392 paint.setShader(SkShader::CreateColorShader(SK_ColorRED))->unref(); 1391 paint.setShader(SkShader::MakeColorShader(SK_ColorRED));
1393 1392
1394 SkMiniRecorder rec; 1393 SkMiniRecorder rec;
1395 REPORTER_ASSERT(r, rec.drawRect(SkRect::MakeWH(20,30), paint)); 1394 REPORTER_ASSERT(r, rec.drawRect(SkRect::MakeWH(20,30), paint));
1396 // Don't call rec.detachPicture(). Test succeeds by not asserting or leakin g the shader. 1395 // Don't call rec.detachPicture(). Test succeeds by not asserting or leakin g the shader.
1397 } 1396 }
1398 1397
1399 DEF_TEST(Picture_preserveCullRect, r) { 1398 DEF_TEST(Picture_preserveCullRect, r) {
1400 SkPictureRecorder recorder; 1399 SkPictureRecorder recorder;
1401 1400
1402 SkCanvas* c = recorder.beginRecording(SkRect::MakeLTRB(1, 2, 3, 4)); 1401 SkCanvas* c = recorder.beginRecording(SkRect::MakeLTRB(1, 2, 3, 4));
1403 c->clear(SK_ColorCYAN); 1402 c->clear(SK_ColorCYAN);
1404 1403
1405 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1404 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1406 SkDynamicMemoryWStream wstream; 1405 SkDynamicMemoryWStream wstream;
1407 picture->serialize(&wstream); 1406 picture->serialize(&wstream);
1408 1407
1409 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); 1408 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream());
1410 SkAutoTUnref<SkPicture> deserializedPicture(SkPicture::CreateFromStream(rstr eam)); 1409 SkAutoTUnref<SkPicture> deserializedPicture(SkPicture::CreateFromStream(rstr eam));
1411 1410
1412 REPORTER_ASSERT(r, SkToBool(deserializedPicture)); 1411 REPORTER_ASSERT(r, SkToBool(deserializedPicture));
1413 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); 1412 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1);
1414 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2); 1413 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2);
1415 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3); 1414 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3);
1416 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4); 1415 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4);
1417 } 1416 }
OLDNEW
« no previous file with comments | « tests/PictureShaderTest.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698