diff options
author | mtklein <mtklein@chromium.org> | 2015-05-07 13:41:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-07 13:41:07 -0700 |
commit | c92c129ff85b05a714bd1bf921c02d5e14651f8b (patch) | |
tree | ea2f915b36a5f6abb746827a4a6f650d5ff13310 /src/core/SkPictureCommon.h | |
parent | 2fbd4068bde6a9fb50341c0bdfbb8bf18b70d015 (diff) |
Sketch splitting SkPicture into an interface and SkBigPicture.
Adds small pictures for drawRect(), drawTextBlob(), and drawPath().
These cover about 89% of draw calls from Blink SKPs,
and about 25% of draw calls from our GMs.
SkPicture handles:
- serialization and deserialization
- unique IDs
Everything else is left to the subclasses:
- playback(), cullRect()
- hasBitmap(), hasText(), suitableForGPU(), etc.
- LayerInfo / AccelData if applicable.
The time to record a 1-op picture improves a good chunk
(2 mallocs to 1), and the time to record a 0-op picture
greatly improves (2 mallocs to none):
picture_overhead_draw: 450ns -> 350ns
picture_overhead_nodraw: 300ns -> 90ns
BUG=skia:
Review URL: https://codereview.chromium.org/1112523006
Diffstat (limited to 'src/core/SkPictureCommon.h')
-rw-r--r-- | src/core/SkPictureCommon.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/core/SkPictureCommon.h b/src/core/SkPictureCommon.h new file mode 100644 index 0000000000..e98723467d --- /dev/null +++ b/src/core/SkPictureCommon.h @@ -0,0 +1,70 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +// Some shared code used by both SkBigPicture and SkMiniPicture. + +#include "SkRecords.h" +#include "SkTLogic.h" + +struct SkTextHunter { + // Most ops never have text. Some always do. Subpictures know themeselves. + template <typename T> bool operator()(const T&) { return false; } + bool operator()(const SkRecords::DrawPosText&) { return true; } + bool operator()(const SkRecords::DrawPosTextH&) { return true; } + bool operator()(const SkRecords::DrawText&) { return true; } + bool operator()(const SkRecords::DrawTextBlob&) { return true; } + bool operator()(const SkRecords::DrawTextOnPath&) { return true; } + bool operator()(const SkRecords::DrawPicture& op) { return op.picture->hasText(); } +}; + + +struct SkBitmapHunter { + // Helpers. These create HasMember_bitmap and HasMember_paint. + SK_CREATE_MEMBER_DETECTOR(bitmap); + SK_CREATE_MEMBER_DETECTOR(paint); + + // 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 paint and the paint has a bitmap, return true. + // Otherwise, return false. + bool operator()(const SkRecords::DrawPicture& op) { return op.picture->willPlayBackBitmaps(); } + + template <typename T> + bool operator()(const T& r) { return CheckBitmap(r); } + + // 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; } + + // 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); } + + // If we have a paint, dig down into the effects looking for a bitmap. + template <typename T> + static SK_WHEN(HasMember_paint<T>, bool) CheckPaint(const T& r) { + const SkPaint* paint = AsPtr(r.paint); + if (paint) { + const SkShader* shader = paint->getShader(); + if (shader && + shader->asABitmap(nullptr, nullptr, nullptr) == SkShader::kDefault_BitmapType) { + return true; + } + } + return false; + } + + // If we don't have a paint, that non-paint has no bitmap. + template <typename T> + static SK_WHEN(!HasMember_paint<T>, bool) CheckPaint(const T&) { return false; } +}; + |