This source file includes following definitions.
- Create
- update_source_frame_number_
- DrawsContent
- CreateLayerImpl
- PushPropertiesTo
- SetLayerTreeHost
- SetNeedsDisplayRect
- Update
- SetIsMask
- SetHasGpuRasterizationHint
- SupportsLCDText
- GetPicture
- RunMicroBenchmark
#include "cc/layers/picture_layer.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/picture_layer_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "ui/gfx/rect_conversions.h"
namespace cc {
scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
return make_scoped_refptr(new PictureLayer(client));
}
PictureLayer::PictureLayer(ContentLayerClient* client)
: client_(client),
pile_(make_scoped_refptr(new PicturePile())),
instrumentation_object_tracker_(id()),
is_mask_(false),
has_gpu_rasterization_hint_(false),
update_source_frame_number_(-1) {}
PictureLayer::~PictureLayer() {
}
bool PictureLayer::DrawsContent() const {
return Layer::DrawsContent() && client_;
}
scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
Layer::PushPropertiesTo(base_layer);
PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
if (layer_impl->bounds().IsEmpty()) {
pile_->Resize(gfx::Size());
} else if (update_source_frame_number_ ==
layer_tree_host()->source_frame_number()) {
DCHECK_EQ(layer_impl->bounds().ToString(), pile_->size().ToString());
}
layer_impl->SetIsMask(is_mask_);
layer_impl->SetHasGpuRasterizationHint(has_gpu_rasterization_hint_);
layer_impl->invalidation_.Clear();
layer_impl->invalidation_.Swap(&pile_invalidation_);
layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get());
}
void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
Layer::SetLayerTreeHost(host);
if (host) {
pile_->SetMinContentsScale(host->settings().minimum_contents_scale);
pile_->SetTileGridSize(host->settings().default_tile_size);
pile_->set_slow_down_raster_scale_factor(
host->debug_state().slow_down_raster_scale_factor);
pile_->set_show_debug_picture_borders(
host->debug_state().show_picture_borders);
}
}
void PictureLayer::SetNeedsDisplayRect(const gfx::RectF& layer_rect) {
gfx::Rect rect = gfx::ToEnclosedRect(layer_rect);
if (!rect.IsEmpty()) {
rect.Intersect(gfx::Rect(bounds()));
pending_invalidation_.Union(rect);
}
Layer::SetNeedsDisplayRect(layer_rect);
}
bool PictureLayer::Update(ResourceUpdateQueue* queue,
const OcclusionTracker<Layer>* occlusion) {
update_source_frame_number_ = layer_tree_host()->source_frame_number();
bool updated = Layer::Update(queue, occlusion);
if (last_updated_visible_content_rect_ == visible_content_rect() &&
pile_->size() == paint_properties().bounds &&
pending_invalidation_.IsEmpty()) {
return updated;
}
TRACE_EVENT1("cc", "PictureLayer::Update",
"source_frame_number",
layer_tree_host()->source_frame_number());
pile_->Resize(paint_properties().bounds);
pending_invalidation_.Swap(&pile_invalidation_);
pending_invalidation_.Clear();
gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect(
visible_content_rect(), 1.f / contents_scale_x());
if (layer_tree_host()->settings().using_synchronous_renderer_compositor) {
visible_layer_rect = gfx::Rect(bounds());
}
DCHECK(client_);
updated |= pile_->Update(client_,
SafeOpaqueBackgroundColor(),
contents_opaque(),
client_->FillsBoundsCompletely(),
pile_invalidation_,
visible_layer_rect,
update_source_frame_number_,
rendering_stats_instrumentation());
last_updated_visible_content_rect_ = visible_content_rect();
if (updated) {
SetNeedsPushProperties();
} else {
pile_invalidation_.Clear();
}
return updated;
}
void PictureLayer::SetIsMask(bool is_mask) {
is_mask_ = is_mask;
}
void PictureLayer::SetHasGpuRasterizationHint(bool has_hint) {
DCHECK(IsPropertyChangeAllowed());
if (has_gpu_rasterization_hint_ == has_hint)
return;
has_gpu_rasterization_hint_ = has_hint;
SetNeedsCommit();
}
bool PictureLayer::SupportsLCDText() const {
return true;
}
skia::RefPtr<SkPicture> PictureLayer::GetPicture() const {
if (!DrawsContent())
return skia::RefPtr<SkPicture>();
int width = bounds().width();
int height = bounds().height();
gfx::RectF opaque;
skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
SkCanvas* canvas = picture->beginRecording(width, height);
client_->PaintContents(canvas, gfx::Rect(width, height), &opaque);
picture->endRecording();
return picture;
}
void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
benchmark->RunOnLayer(this);
}
}