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
,
30 client_
->PaintContents(canvas
,
33 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED
);
36 scoped_refptr
<ContentLayer
> ContentLayer::Create(ContentLayerClient
* client
) {
37 return make_scoped_refptr(new ContentLayer(client
));
40 ContentLayer::ContentLayer(ContentLayerClient
* client
)
43 can_use_lcd_text_last_frame_(can_use_lcd_text()) {
46 ContentLayer::~ContentLayer() {}
48 bool ContentLayer::DrawsContent() const {
49 return TiledLayer::DrawsContent() && client_
;
52 void ContentLayer::SetLayerTreeHost(LayerTreeHost
* host
) {
53 TiledLayer::SetLayerTreeHost(host
);
59 updater_
->set_rendering_stats_instrumentation(
60 host
->rendering_stats_instrumentation());
62 updater_
->set_rendering_stats_instrumentation(NULL
);
66 void ContentLayer::SetTexturePriorities(
67 const PriorityCalculator
& priority_calc
) {
68 // Update the tile data before creating all the layer's tiles.
69 UpdateTileSizeAndTilingOption();
71 TiledLayer::SetTexturePriorities(priority_calc
);
74 bool ContentLayer::Update(ResourceUpdateQueue
* queue
,
75 const OcclusionTracker
<Layer
>* occlusion
) {
77 base::AutoReset
<bool> ignore_set_needs_commit(&ignore_set_needs_commit_
,
80 CreateUpdaterIfNeeded();
81 UpdateCanUseLCDText();
84 bool updated
= TiledLayer::Update(queue
, occlusion
);
88 bool ContentLayer::NeedMoreUpdates() {
89 return NeedsIdlePaint();
92 LayerUpdater
* ContentLayer::Updater() const {
93 return updater_
.get();
96 void ContentLayer::CreateUpdaterIfNeeded() {
99 scoped_ptr
<LayerPainter
> painter
=
100 ContentLayerPainter::Create(client_
).PassAs
<LayerPainter
>();
101 if (layer_tree_host()->settings().per_tile_painting_enabled
) {
102 updater_
= BitmapSkPictureContentLayerUpdater::Create(
104 rendering_stats_instrumentation(),
107 updater_
= BitmapContentLayerUpdater::Create(
109 rendering_stats_instrumentation(),
112 updater_
->SetOpaque(contents_opaque());
114 updater_
->SetFillsBoundsCompletely(client_
->FillsBoundsCompletely());
117 layer_tree_host()->GetRendererCapabilities().best_texture_format
);
120 void ContentLayer::SetContentsOpaque(bool opaque
) {
121 Layer::SetContentsOpaque(opaque
);
123 updater_
->SetOpaque(opaque
);
126 void ContentLayer::UpdateCanUseLCDText() {
127 if (can_use_lcd_text_last_frame_
== can_use_lcd_text())
130 can_use_lcd_text_last_frame_
= can_use_lcd_text();
132 client_
->DidChangeLayerCanUseLCDText();
135 bool ContentLayer::SupportsLCDText() const {
139 skia::RefPtr
<SkPicture
> ContentLayer::GetPicture() const {
141 return skia::RefPtr
<SkPicture
>();
143 int width
= bounds().width();
144 int height
= bounds().height();
147 SkPictureRecorder recorder
;
148 SkCanvas
* canvas
= recorder
.beginRecording(width
, height
, NULL
, 0);
149 client_
->PaintContents(canvas
,
150 gfx::Rect(width
, height
),
152 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED
);
153 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(recorder
.endRecording());
157 void ContentLayer::OnOutputSurfaceCreated() {
159 layer_tree_host()->GetRendererCapabilities().best_texture_format
);
160 TiledLayer::OnOutputSurfaceCreated();