Implement SkRecordedDrawable::onApproximateBytesUsed

This allows recorded pictures finished as drawables to be used for glyph
drawing.

Change-Id: I717626eda2bf4e1659c8941c3217cb61c1a16cf4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/506882
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2022-02-10 12:53:13 -05:00 committed by SkCQ
parent e855b1273f
commit db4a543e45
4 changed files with 20 additions and 4 deletions

View File

@ -13,6 +13,19 @@
#include "src/core/SkRecordDraw.h"
#include "src/core/SkRecordedDrawable.h"
size_t SkRecordedDrawable::onApproximateBytesUsed() {
size_t drawablesSize = 0;
if (fDrawableList) {
for (auto&& drawable : *fDrawableList) {
drawablesSize += drawable->approximateBytesUsed();
}
}
return sizeof(*this) +
(fRecord ? fRecord->bytesUsed() : 0) +
(fBBH ? fBBH->bytesUsed() : 0) +
drawablesSize;
}
void SkRecordedDrawable::onDraw(SkCanvas* canvas) {
SkDrawable* const* drawables = nullptr;
int drawableCount = 0;

View File

@ -25,6 +25,7 @@ public:
protected:
SkRect onGetBounds() override { return fBounds; }
size_t onApproximateBytesUsed() override;
void onDraw(SkCanvas* canvas) override;

View File

@ -25,6 +25,7 @@ public:
int count() const { return fArray.count(); }
SkDrawable* const* begin() const { return fArray.begin(); }
SkDrawable* const* end() const { return fArray.end(); }
void append(SkDrawable* drawable);

View File

@ -84,6 +84,7 @@ std::tuple<SkDrawable*, size_t> SkScalerCache::prepareDrawable(SkGlyph* glyph) {
size_t delta = 0;
if (glyph->setDrawable(&fAlloc, fScalerContext.get())) {
delta = glyph->drawable()->approximateBytesUsed();
SkASSERT(delta > 0);
}
return {glyph->drawable(), delta};
}
@ -91,15 +92,15 @@ std::tuple<SkDrawable*, size_t> SkScalerCache::prepareDrawable(SkGlyph* glyph) {
std::tuple<SkDrawable*, size_t> SkScalerCache::mergeDrawable(SkGlyph* glyph,
sk_sp<SkDrawable> drawable) {
SkAutoMutexExclusive lock{fMu};
size_t drawableDelta = 0;
size_t delta = 0;
if (glyph->setDrawableHasBeenCalled()) {
SkDEBUGFAIL("Re-adding drawable to existing glyph. This should not happen.");
}
if (glyph->setDrawable(&fAlloc, std::move(drawable))) {
drawableDelta = glyph->drawable()->approximateBytesUsed();
SkASSERT(drawableDelta > 0);
delta = glyph->drawable()->approximateBytesUsed();
SkASSERT(delta > 0);
}
return {glyph->drawable(), drawableDelta};
return {glyph->drawable(), delta};
}
int SkScalerCache::countCachedGlyphs() const {