Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / layers / content_layer.cc
blob295577303c3ad2432671eca80d0400a4b2688b55
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, 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() {
46 client_ = nullptr;
47 UpdateDrawsContent(HasDrawableContent());
50 bool ContentLayer::HasDrawableContent() const {
51 return client_ && TiledLayer::HasDrawableContent();
54 void ContentLayer::SetLayerTreeHost(LayerTreeHost* host) {
55 TiledLayer::SetLayerTreeHost(host);
57 if (!updater_.get())
58 return;
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_,
73 true);
75 CreateUpdaterIfNeeded();
78 bool updated = TiledLayer::Update(queue, occlusion);
79 return updated;
82 bool ContentLayer::NeedMoreUpdates() {
83 return NeedsIdlePaint();
86 LayerUpdater* ContentLayer::Updater() const {
87 return updater_.get();
90 void ContentLayer::CreateUpdaterIfNeeded() {
91 if (updater_.get())
92 return;
93 scoped_ptr<LayerPainter> painter = ContentLayerPainter::Create(client_);
94 if (layer_tree_host()->settings().per_tile_painting_enabled) {
95 updater_ = BitmapSkPictureContentLayerUpdater::Create(
96 painter.Pass(),
97 rendering_stats_instrumentation(),
98 id());
99 } else {
100 updater_ = BitmapContentLayerUpdater::Create(
101 painter.Pass(),
102 id());
104 updater_->SetOpaque(contents_opaque());
105 if (client_)
106 updater_->SetFillsBoundsCompletely(client_->FillsBoundsCompletely());
107 updater_->SetBackgroundColor(background_color());
109 SetTextureFormat(
110 layer_tree_host()->GetRendererCapabilities().best_texture_format);
113 void ContentLayer::SetContentsOpaque(bool opaque) {
114 Layer::SetContentsOpaque(opaque);
115 if (updater_.get())
116 updater_->SetOpaque(opaque);
119 skia::RefPtr<SkPicture> ContentLayer::GetPicture() const {
120 if (!DrawsContent())
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());
132 return picture;
135 void ContentLayer::OnOutputSurfaceCreated() {
136 SetTextureFormat(
137 layer_tree_host()->GetRendererCapabilities().best_texture_format);
138 TiledLayer::OnOutputSurfaceCreated();
141 } // namespace cc