1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/content_layer.h"
7 #include "base/auto_reset.h"
8 #include "base/metrics/histogram.h"
9 #include "base/time/time.h"
10 #include "cc/layers/content_layer_client.h"
11 #include "cc/resources/bitmap_content_layer_updater.h"
12 #include "cc/resources/bitmap_skpicture_content_layer_updater.h"
13 #include "cc/resources/layer_painter.h"
14 #include "cc/trees/layer_tree_host.h"
15 #include "third_party/skia/include/core/SkPictureRecorder.h"
19 ContentLayerPainter::ContentLayerPainter(ContentLayerClient
* client
)
22 scoped_ptr
<ContentLayerPainter
> ContentLayerPainter::Create(
23 ContentLayerClient
* client
) {
24 return make_scoped_ptr(new ContentLayerPainter(client
));
27 void ContentLayerPainter::Paint(SkCanvas
* canvas
,
28 const gfx::Rect
& content_rect
) {
29 client_
->PaintContents(canvas
, content_rect
,
30 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL
);
33 scoped_refptr
<ContentLayer
> ContentLayer::Create(ContentLayerClient
* client
) {
34 return make_scoped_refptr(new ContentLayer(client
));
37 ContentLayer::ContentLayer(ContentLayerClient
* client
)
38 : TiledLayer(), client_(client
) {
41 ContentLayer::~ContentLayer() {}
43 void ContentLayer::ClearClient() {
45 UpdateDrawsContent(HasDrawableContent());
48 bool ContentLayer::HasDrawableContent() const {
49 return client_
&& TiledLayer::HasDrawableContent();
52 void ContentLayer::SetLayerTreeHost(LayerTreeHost
* host
) {
53 TiledLayer::SetLayerTreeHost(host
);
59 void ContentLayer::SetTexturePriorities(
60 const PriorityCalculator
& priority_calc
) {
61 // Update the tile data before creating all the layer's tiles.
62 UpdateTileSizeAndTilingOption();
64 TiledLayer::SetTexturePriorities(priority_calc
);
67 bool ContentLayer::Update(ResourceUpdateQueue
* queue
,
68 const OcclusionTracker
<Layer
>* occlusion
) {
70 base::AutoReset
<bool> ignore_set_needs_commit(&ignore_set_needs_commit_
,
73 CreateUpdaterIfNeeded();
76 bool updated
= TiledLayer::Update(queue
, occlusion
);
80 bool ContentLayer::NeedMoreUpdates() {
81 return NeedsIdlePaint();
84 LayerUpdater
* ContentLayer::Updater() const {
85 return updater_
.get();
88 void ContentLayer::CreateUpdaterIfNeeded() {
91 scoped_ptr
<LayerPainter
> painter
= ContentLayerPainter::Create(client_
);
92 if (layer_tree_host()->settings().per_tile_painting_enabled
) {
93 updater_
= BitmapSkPictureContentLayerUpdater::Create(
95 rendering_stats_instrumentation(),
98 updater_
= BitmapContentLayerUpdater::Create(
102 updater_
->SetOpaque(contents_opaque());
104 updater_
->SetFillsBoundsCompletely(client_
->FillsBoundsCompletely());
105 updater_
->SetBackgroundColor(background_color());
108 layer_tree_host()->GetRendererCapabilities().best_texture_format
);
111 void ContentLayer::SetContentsOpaque(bool opaque
) {
112 Layer::SetContentsOpaque(opaque
);
114 updater_
->SetOpaque(opaque
);
117 skia::RefPtr
<SkPicture
> ContentLayer::GetPicture() const {
119 return skia::RefPtr
<SkPicture
>();
121 int width
= bounds().width();
122 int height
= bounds().height();
124 SkPictureRecorder recorder
;
125 SkCanvas
* canvas
= recorder
.beginRecording(width
, height
, nullptr, 0);
126 client_
->PaintContents(canvas
, gfx::Rect(width
, height
),
127 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL
);
128 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(recorder
.endRecording());
132 void ContentLayer::OnOutputSurfaceCreated() {
134 layer_tree_host()->GetRendererCapabilities().best_texture_format
);
135 TiledLayer::OnOutputSurfaceCreated();