Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / layers / content_layer.cc
blob53c7120c09b11bc1addbb4525290dfe6d27f78f3
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"
17 namespace cc {
19 ContentLayerPainter::ContentLayerPainter(ContentLayerClient* client)
20 : client_(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,
30 content_rect,
31 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED);
34 scoped_refptr<ContentLayer> ContentLayer::Create(ContentLayerClient* client) {
35 return make_scoped_refptr(new ContentLayer(client));
38 ContentLayer::ContentLayer(ContentLayerClient* client)
39 : TiledLayer(), client_(client) {
42 ContentLayer::~ContentLayer() {}
44 void ContentLayer::ClearClient() {
45 client_ = nullptr;
46 UpdateDrawsContent(HasDrawableContent());
49 bool ContentLayer::HasDrawableContent() const {
50 return client_ && TiledLayer::HasDrawableContent();
53 void ContentLayer::SetLayerTreeHost(LayerTreeHost* host) {
54 TiledLayer::SetLayerTreeHost(host);
56 if (!updater_.get())
57 return;
60 void ContentLayer::SetTexturePriorities(
61 const PriorityCalculator& priority_calc) {
62 // Update the tile data before creating all the layer's tiles.
63 UpdateTileSizeAndTilingOption();
65 TiledLayer::SetTexturePriorities(priority_calc);
68 bool ContentLayer::Update(ResourceUpdateQueue* queue,
69 const OcclusionTracker<Layer>* occlusion) {
71 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
72 true);
74 CreateUpdaterIfNeeded();
77 bool updated = TiledLayer::Update(queue, occlusion);
78 return updated;
81 bool ContentLayer::NeedMoreUpdates() {
82 return NeedsIdlePaint();
85 LayerUpdater* ContentLayer::Updater() const {
86 return updater_.get();
89 void ContentLayer::CreateUpdaterIfNeeded() {
90 if (updater_.get())
91 return;
92 scoped_ptr<LayerPainter> painter = ContentLayerPainter::Create(client_);
93 if (layer_tree_host()->settings().per_tile_painting_enabled) {
94 updater_ = BitmapSkPictureContentLayerUpdater::Create(
95 painter.Pass(),
96 rendering_stats_instrumentation(),
97 id());
98 } else {
99 updater_ = BitmapContentLayerUpdater::Create(
100 painter.Pass(),
101 id());
103 updater_->SetOpaque(contents_opaque());
104 if (client_)
105 updater_->SetFillsBoundsCompletely(client_->FillsBoundsCompletely());
106 updater_->SetBackgroundColor(background_color());
108 SetTextureFormat(
109 layer_tree_host()->GetRendererCapabilities().best_texture_format);
112 void ContentLayer::SetContentsOpaque(bool opaque) {
113 Layer::SetContentsOpaque(opaque);
114 if (updater_.get())
115 updater_->SetOpaque(opaque);
118 bool ContentLayer::SupportsLCDText() const {
119 return true;
122 skia::RefPtr<SkPicture> ContentLayer::GetPicture() const {
123 if (!DrawsContent())
124 return skia::RefPtr<SkPicture>();
126 int width = bounds().width();
127 int height = bounds().height();
129 SkPictureRecorder recorder;
130 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0);
131 client_->PaintContents(canvas,
132 gfx::Rect(width, height),
133 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED);
134 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
135 return picture;
138 void ContentLayer::OnOutputSurfaceCreated() {
139 SetTextureFormat(
140 layer_tree_host()->GetRendererCapabilities().best_texture_format);
141 TiledLayer::OnOutputSurfaceCreated();
144 } // namespace cc