| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/layers/content_layer.h" | |
| 6 | |
| 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" | |
| 16 | |
| 17 namespace cc { | |
| 18 | |
| 19 ContentLayerPainter::ContentLayerPainter(ContentLayerClient* client) | |
| 20 : client_(client) {} | |
| 21 | |
| 22 scoped_ptr<ContentLayerPainter> ContentLayerPainter::Create( | |
| 23 ContentLayerClient* client) { | |
| 24 return make_scoped_ptr(new ContentLayerPainter(client)); | |
| 25 } | |
| 26 | |
| 27 void ContentLayerPainter::Paint(SkCanvas* canvas, | |
| 28 const gfx::Rect& content_rect) { | |
| 29 client_->PaintContents(canvas, content_rect, | |
| 30 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | |
| 31 } | |
| 32 | |
| 33 scoped_refptr<ContentLayer> ContentLayer::Create(ContentLayerClient* client) { | |
| 34 return make_scoped_refptr(new ContentLayer(client)); | |
| 35 } | |
| 36 | |
| 37 ContentLayer::ContentLayer(ContentLayerClient* client) | |
| 38 : TiledLayer(), client_(client) { | |
| 39 } | |
| 40 | |
| 41 ContentLayer::~ContentLayer() {} | |
| 42 | |
| 43 void ContentLayer::ClearClient() { | |
| 44 client_ = nullptr; | |
| 45 UpdateDrawsContent(HasDrawableContent()); | |
| 46 } | |
| 47 | |
| 48 bool ContentLayer::HasDrawableContent() const { | |
| 49 return client_ && TiledLayer::HasDrawableContent(); | |
| 50 } | |
| 51 | |
| 52 void ContentLayer::SetLayerTreeHost(LayerTreeHost* host) { | |
| 53 TiledLayer::SetLayerTreeHost(host); | |
| 54 | |
| 55 if (!updater_.get()) | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 void ContentLayer::SetTexturePriorities( | |
| 60 const PriorityCalculator& priority_calc) { | |
| 61 // Update the tile data before creating all the layer's tiles. | |
| 62 UpdateTileSizeAndTilingOption(); | |
| 63 | |
| 64 TiledLayer::SetTexturePriorities(priority_calc); | |
| 65 } | |
| 66 | |
| 67 bool ContentLayer::Update(ResourceUpdateQueue* queue, | |
| 68 const OcclusionTracker<Layer>* occlusion) { | |
| 69 { | |
| 70 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | |
| 71 true); | |
| 72 | |
| 73 CreateUpdaterIfNeeded(); | |
| 74 } | |
| 75 | |
| 76 bool updated = TiledLayer::Update(queue, occlusion); | |
| 77 return updated; | |
| 78 } | |
| 79 | |
| 80 bool ContentLayer::NeedMoreUpdates() { | |
| 81 return NeedsIdlePaint(); | |
| 82 } | |
| 83 | |
| 84 LayerUpdater* ContentLayer::Updater() const { | |
| 85 return updater_.get(); | |
| 86 } | |
| 87 | |
| 88 void ContentLayer::CreateUpdaterIfNeeded() { | |
| 89 if (updater_.get()) | |
| 90 return; | |
| 91 scoped_ptr<LayerPainter> painter = ContentLayerPainter::Create(client_); | |
| 92 if (layer_tree_host()->settings().per_tile_painting_enabled) { | |
| 93 updater_ = BitmapSkPictureContentLayerUpdater::Create( | |
| 94 painter.Pass(), | |
| 95 rendering_stats_instrumentation(), | |
| 96 id()); | |
| 97 } else { | |
| 98 updater_ = BitmapContentLayerUpdater::Create( | |
| 99 painter.Pass(), | |
| 100 id()); | |
| 101 } | |
| 102 updater_->SetOpaque(contents_opaque()); | |
| 103 if (client_) | |
| 104 updater_->SetFillsBoundsCompletely(client_->FillsBoundsCompletely()); | |
| 105 updater_->SetBackgroundColor(background_color()); | |
| 106 | |
| 107 SetTextureFormat( | |
| 108 layer_tree_host()->GetRendererCapabilities().best_texture_format); | |
| 109 } | |
| 110 | |
| 111 void ContentLayer::SetContentsOpaque(bool opaque) { | |
| 112 Layer::SetContentsOpaque(opaque); | |
| 113 if (updater_.get()) | |
| 114 updater_->SetOpaque(opaque); | |
| 115 } | |
| 116 | |
| 117 skia::RefPtr<SkPicture> ContentLayer::GetPicture() const { | |
| 118 if (!DrawsContent()) | |
| 119 return skia::RefPtr<SkPicture>(); | |
| 120 | |
| 121 int width = bounds().width(); | |
| 122 int height = bounds().height(); | |
| 123 | |
| 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()); | |
| 129 return picture; | |
| 130 } | |
| 131 | |
| 132 void ContentLayer::OnOutputSurfaceCreated() { | |
| 133 SetTextureFormat( | |
| 134 layer_tree_host()->GetRendererCapabilities().best_texture_format); | |
| 135 TiledLayer::OnOutputSurfaceCreated(); | |
| 136 } | |
| 137 | |
| 138 } // namespace cc | |
| OLD | NEW |