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(const LayerSettings
& settings
,
34 ContentLayerClient
* client
) {
35 return make_scoped_refptr(new ContentLayer(settings
, client
));
38 ContentLayer::ContentLayer(const LayerSettings
& settings
,
39 ContentLayerClient
* client
)
40 : TiledLayer(settings
), client_(client
) {
43 ContentLayer::~ContentLayer() {}
45 void ContentLayer::ClearClient() {
47 UpdateDrawsContent(HasDrawableContent());
50 bool ContentLayer::HasDrawableContent() const {
51 return client_
&& TiledLayer::HasDrawableContent();
54 void ContentLayer::SetLayerTreeHost(LayerTreeHost
* host
) {
55 TiledLayer::SetLayerTreeHost(host
);
61 void ContentLayer::SetTexturePriorities(
62 const PriorityCalculator
& priority_calc
) {
63 // Update the tile data before creating all the layer's tiles.
64 UpdateTileSizeAndTilingOption();
66 TiledLayer::SetTexturePriorities(priority_calc
);
69 bool ContentLayer::Update(ResourceUpdateQueue
* queue
,
70 const OcclusionTracker
<Layer
>* occlusion
) {
72 base::AutoReset
<bool> ignore_set_needs_commit(&ignore_set_needs_commit_
,
75 CreateUpdaterIfNeeded();
78 bool updated
= TiledLayer::Update(queue
, occlusion
);
82 bool ContentLayer::NeedMoreUpdates() {
83 return NeedsIdlePaint();
86 LayerUpdater
* ContentLayer::Updater() const {
87 return updater_
.get();
90 void ContentLayer::CreateUpdaterIfNeeded() {
93 scoped_ptr
<LayerPainter
> painter
= ContentLayerPainter::Create(client_
);
94 if (layer_tree_host()->settings().per_tile_painting_enabled
) {
95 updater_
= BitmapSkPictureContentLayerUpdater::Create(
97 rendering_stats_instrumentation(),
100 updater_
= BitmapContentLayerUpdater::Create(
104 updater_
->SetOpaque(contents_opaque());
106 updater_
->SetFillsBoundsCompletely(client_
->FillsBoundsCompletely());
107 updater_
->SetBackgroundColor(background_color());
110 layer_tree_host()->GetRendererCapabilities().best_texture_format
);
113 void ContentLayer::SetContentsOpaque(bool opaque
) {
114 Layer::SetContentsOpaque(opaque
);
116 updater_
->SetOpaque(opaque
);
119 skia::RefPtr
<SkPicture
> ContentLayer::GetPicture() const {
121 return skia::RefPtr
<SkPicture
>();
123 int width
= bounds().width();
124 int height
= bounds().height();
126 SkPictureRecorder recorder
;
127 SkCanvas
* canvas
= recorder
.beginRecording(width
, height
, nullptr, 0);
128 client_
->PaintContents(canvas
, gfx::Rect(width
, height
),
129 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL
);
130 skia::RefPtr
<SkPicture
> picture
=
131 skia::AdoptRef(recorder
.endRecordingAsPicture());
135 void ContentLayer::OnOutputSurfaceCreated() {
137 layer_tree_host()->GetRendererCapabilities().best_texture_format
);
138 TiledLayer::OnOutputSurfaceCreated();