Have SkPicture::willPlayBackBitmaps() count SkImages too.
New unit test fails at head but passes with this patch. BUG=skia:4225 Review URL: https://codereview.chromium.org/1319723002
This commit is contained in:
parent
bcf33d5c06
commit
a16af21b17
@ -7,7 +7,7 @@
|
||||
|
||||
// Some shared code used by both SkBigPicture and SkMiniPicture.
|
||||
// SkTextHunter -- SkRecord visitor that returns true when the op draws text.
|
||||
// SkBitmapHunter -- SkRecord visitor that returns true when the op draws a bitmap.
|
||||
// SkBitmapHunter -- SkRecord visitor that returns true when the op draws a bitmap or image.
|
||||
// SkPathCounter -- SkRecord visitor that counts paths that draw slowly on the GPU.
|
||||
|
||||
#include "SkPathEffect.h"
|
||||
@ -26,18 +26,25 @@ struct SkTextHunter {
|
||||
};
|
||||
|
||||
|
||||
// N.B. This name is slightly historical: hunting season is now open for SkImages too.
|
||||
struct SkBitmapHunter {
|
||||
// Helpers. These create HasMember_bitmap and HasMember_paint.
|
||||
// Helpers. These let us detect the presence of struct members with particular names.
|
||||
SK_CREATE_MEMBER_DETECTOR(bitmap);
|
||||
SK_CREATE_MEMBER_DETECTOR(image);
|
||||
SK_CREATE_MEMBER_DETECTOR(paint);
|
||||
|
||||
template <typename T>
|
||||
struct HasMember_bitmap_or_image {
|
||||
static const bool value = HasMember_bitmap<T>::value || HasMember_image<T>::value;
|
||||
};
|
||||
|
||||
// Some ops have a paint, some have an optional paint. Either way, get back a pointer.
|
||||
static const SkPaint* AsPtr(const SkPaint& p) { return &p; }
|
||||
static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; }
|
||||
|
||||
// Main entry for visitor:
|
||||
// If the op is a DrawPicture, recurse.
|
||||
// If the op has a bitmap directly, return true.
|
||||
// If the op has a bitmap or image directly, return true.
|
||||
// If the op has a paint and the paint has a bitmap, return true.
|
||||
// Otherwise, return false.
|
||||
bool operator()(const SkRecords::DrawPicture& op) { return op.picture->willPlayBackBitmaps(); }
|
||||
@ -47,11 +54,15 @@ struct SkBitmapHunter {
|
||||
|
||||
// If the op has a bitmap, of course we're going to play back bitmaps.
|
||||
template <typename T>
|
||||
static SK_WHEN(HasMember_bitmap<T>, bool) CheckBitmap(const T&) { return true; }
|
||||
static SK_WHEN(HasMember_bitmap_or_image<T>, bool) CheckBitmap(const T&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If not, look for one in its paint (if it has a paint).
|
||||
template <typename T>
|
||||
static SK_WHEN(!HasMember_bitmap<T>, bool) CheckBitmap(const T& r) { return CheckPaint(r); }
|
||||
static SK_WHEN(!HasMember_bitmap_or_image<T>, bool) CheckBitmap(const T& r) {
|
||||
return CheckPaint(r);
|
||||
}
|
||||
|
||||
// If we have a paint, dig down into the effects looking for a bitmap.
|
||||
template <typename T>
|
||||
|
@ -48,6 +48,21 @@ static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) {
|
||||
}
|
||||
}
|
||||
|
||||
// For a while willPlayBackBitmaps() ignored SkImages and just looked for SkBitmaps.
|
||||
static void test_images_are_found_by_willPlayBackBitmaps(skiatest::Reporter* reporter) {
|
||||
// We just need _some_ SkImage.
|
||||
SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(SkBitmap()));
|
||||
|
||||
SkPictureRecorder recorder;
|
||||
{
|
||||
auto canvas = recorder.beginRecording(100,100);
|
||||
canvas->drawImage(image, 0,0);
|
||||
}
|
||||
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
|
||||
|
||||
REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
|
||||
}
|
||||
|
||||
/* Hit a few SkPicture::Analysis cases not handled elsewhere. */
|
||||
static void test_analysis(skiatest::Reporter* reporter) {
|
||||
SkPictureRecorder recorder;
|
||||
@ -1149,6 +1164,7 @@ DEF_TEST(Picture, reporter) {
|
||||
test_gpu_veto(reporter);
|
||||
#endif
|
||||
test_has_text(reporter);
|
||||
test_images_are_found_by_willPlayBackBitmaps(reporter);
|
||||
test_analysis(reporter);
|
||||
test_bitmap_with_encoded_data(reporter);
|
||||
test_clip_bound_opt(reporter);
|
||||
|
Loading…
Reference in New Issue
Block a user