Add a way to hint the compositor (flutter/engine#2816)

The code that draws the picture knows more about the picture (and the future)
than we do. This patch gives them a way to hint us about what's going to
happen with the picture in the future.
This commit is contained in:
Adam Barth
2016-07-22 11:07:14 -07:00
committed by GitHub
parent b889a043f6
commit c53f3f5c36
4 changed files with 27 additions and 24 deletions

View File

@@ -13,16 +13,13 @@ namespace flow {
// TODO(abarth): Make this configurable by developers.
const bool kDebugCheckerboardRasterizedLayers = false;
PictureLayer::PictureLayer() {
}
PictureLayer::PictureLayer() {}
PictureLayer::~PictureLayer() {
}
PictureLayer::~PictureLayer() {}
void PictureLayer::Preroll(PrerollContext* context,
const SkMatrix& matrix) {
void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
image_ = context->raster_cache.GetPrerolledImage(
context->gr_context, picture_.get(), matrix);
context->gr_context, picture_.get(), matrix, is_complex_, will_change_);
context->child_paint_bounds =
picture_->cullRect().makeOffset(offset_.x(), offset_.y());
}

View File

@@ -15,9 +15,11 @@ class PictureLayer : public Layer {
~PictureLayer() override;
void set_offset(const SkPoint& offset) { offset_ = offset; }
void set_picture(sk_sp<SkPicture> picture) { picture_ = std::move(picture); }
void set_is_complex(bool value) { is_complex_ = value; }
void set_will_change(bool value) { will_change_ = value; }
SkPicture* picture() const { return picture_.get(); }
void Preroll(PrerollContext* frame, const SkMatrix& matrix) override;
@@ -26,6 +28,8 @@ class PictureLayer : public Layer {
private:
SkPoint offset_;
sk_sp<SkPicture> picture_;
bool is_complex_ = false;
bool will_change_ = false;
// If we rasterized the picture separately, image_ holds the pixels.
sk_sp<SkImage> image_;

View File

@@ -27,30 +27,29 @@ static bool isWorthRasterizing(SkPicture* picture) {
#endif
RasterCache::RasterCache() {
}
RasterCache::RasterCache() {}
RasterCache::~RasterCache() {
}
RasterCache::~RasterCache() {}
RasterCache::Entry::Entry() {
physical_size.setEmpty();
}
RasterCache::Entry::~Entry() {
}
RasterCache::Entry::~Entry() {}
sk_sp<SkImage> RasterCache::GetPrerolledImage(GrContext* context,
SkPicture* picture,
const SkMatrix& ctm) {
SkPicture* picture,
const SkMatrix& ctm,
bool is_complex,
bool will_change) {
#if ENABLE_RASTER_CACHE
SkScalar scaleX = ctm.getScaleX();
SkScalar scaleY = ctm.getScaleY();
SkRect rect = picture->cullRect();
SkISize physical_size = SkISize::Make(rect.width() * scaleX,
rect.height() * scaleY);
SkISize physical_size =
SkISize::Make(rect.width() * scaleX, rect.height() * scaleY);
if (physical_size.isEmpty())
return nullptr;
@@ -74,10 +73,10 @@ sk_sp<SkImage> RasterCache::GetPrerolledImage(GrContext* context,
// Saturate at the threshhold.
entry.access_count = kRasterThreshold;
if (!entry.image && isWorthRasterizing(picture)) {
TRACE_EVENT2("flutter", "Rasterize picture layer",
"width", physical_size.width(),
"height", physical_size.height());
if (!entry.image && !will_change &&
(is_complex || isWorthRasterizing(picture))) {
TRACE_EVENT2("flutter", "Rasterize picture layer", "width",
physical_size.width(), "height", physical_size.height());
SkImageInfo info = SkImageInfo::MakeN32Premul(physical_size);
sk_sp<SkSurface> surface =
SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info);

View File

@@ -21,8 +21,11 @@ class RasterCache {
RasterCache();
~RasterCache();
sk_sp<SkImage> GetPrerolledImage(
GrContext* context, SkPicture* picture, const SkMatrix& ctm);
sk_sp<SkImage> GetPrerolledImage(GrContext* context,
SkPicture* picture,
const SkMatrix& ctm,
bool is_complex,
bool will_change);
void SweepAfterFrame();
void Clear();