| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/bitmap_content_layer_updater.h" | 5 #include "cc/resources/bitmap_content_layer_updater.h" |
| 6 | 6 |
| 7 #include "cc/debug/devtools_instrumentation.h" | 7 #include "cc/debug/devtools_instrumentation.h" |
| 8 #include "cc/debug/rendering_stats_instrumentation.h" | 8 #include "cc/debug/rendering_stats_instrumentation.h" |
| 9 #include "cc/resources/layer_painter.h" | 9 #include "cc/resources/layer_painter.h" |
| 10 #include "cc/resources/prioritized_resource.h" | 10 #include "cc/resources/prioritized_resource.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 void BitmapContentLayerUpdater::PrepareToUpdate( | 56 void BitmapContentLayerUpdater::PrepareToUpdate( |
| 57 gfx::Rect content_rect, | 57 gfx::Rect content_rect, |
| 58 gfx::Size tile_size, | 58 gfx::Size tile_size, |
| 59 float contents_width_scale, | 59 float contents_width_scale, |
| 60 float contents_height_scale, | 60 float contents_height_scale, |
| 61 gfx::Rect* resulting_opaque_rect) { | 61 gfx::Rect* resulting_opaque_rect) { |
| 62 devtools_instrumentation::ScopedLayerTask paint_layer( | 62 devtools_instrumentation::ScopedLayerTask paint_layer( |
| 63 devtools_instrumentation::kPaintLayer, layer_id_); | 63 devtools_instrumentation::kPaintLayer, layer_id_); |
| 64 if (canvas_size_ != content_rect.size()) { | 64 if (canvas_size_.width() < content_rect.size().width() || |
| 65 canvas_size_.height() < content_rect.size().height()) { |
| 65 devtools_instrumentation::ScopedLayerTask paint_setup( | 66 devtools_instrumentation::ScopedLayerTask paint_setup( |
| 66 devtools_instrumentation::kPaintSetup, layer_id_); | 67 devtools_instrumentation::kPaintSetup, layer_id_); |
| 67 canvas_size_ = content_rect.size(); | 68 canvas_size_ = content_rect.size(); |
| 68 canvas_ = skia::AdoptRef(skia::CreateBitmapCanvas( | 69 canvas_ = skia::AdoptRef(skia::CreateBitmapCanvas( |
| 69 canvas_size_.width(), canvas_size_.height(), layer_is_opaque_)); | 70 canvas_size_.width(), canvas_size_.height(), layer_is_opaque_)); |
| 70 } | 71 } |
| 71 | 72 |
| 72 base::TimeTicks start_time = | 73 base::TimeTicks start_time = |
| 73 rendering_stats_instrumentation_->StartRecording(); | 74 rendering_stats_instrumentation_->StartRecording(); |
| 74 PaintContents(canvas_.get(), | 75 PaintContents(canvas_.get(), |
| 75 content_rect.origin(), | 76 content_rect, |
| 76 contents_width_scale, | 77 contents_width_scale, |
| 77 contents_height_scale, | 78 contents_height_scale, |
| 78 resulting_opaque_rect); | 79 resulting_opaque_rect); |
| 79 base::TimeDelta duration = | 80 base::TimeDelta duration = |
| 80 rendering_stats_instrumentation_->EndRecording(start_time); | 81 rendering_stats_instrumentation_->EndRecording(start_time); |
| 81 rendering_stats_instrumentation_->AddPaint( | 82 rendering_stats_instrumentation_->AddPaint( |
| 82 duration, | 83 duration, |
| 83 content_rect.width() * content_rect.height()); | 84 content_rect.width() * content_rect.height()); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void BitmapContentLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue, | 87 void BitmapContentLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue, |
| 87 PrioritizedResource* texture, | 88 PrioritizedResource* texture, |
| 88 gfx::Rect source_rect, | 89 gfx::Rect source_rect, |
| 89 gfx::Vector2d dest_offset, | 90 gfx::Vector2d dest_offset, |
| 90 bool partial_update) { | 91 bool partial_update) { |
| 91 CHECK(canvas_); | 92 CHECK(canvas_); |
| 92 ResourceUpdate upload = | 93 gfx::Rect canvas_rect = content_rect(); |
| 93 ResourceUpdate::CreateFromCanvas(texture, | 94 canvas_rect.set_size(canvas_size_); |
| 94 canvas_, | 95 ResourceUpdate upload = ResourceUpdate::CreateFromCanvas( |
| 95 content_rect(), | 96 texture, canvas_, canvas_rect, source_rect, dest_offset); |
| 96 source_rect, | |
| 97 dest_offset); | |
| 98 if (partial_update) | 97 if (partial_update) |
| 99 queue->AppendPartialUpload(upload); | 98 queue->AppendPartialUpload(upload); |
| 100 else | 99 else |
| 101 queue->AppendFullUpload(upload); | 100 queue->AppendFullUpload(upload); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void BitmapContentLayerUpdater::ReduceMemoryUsage() { | 103 void BitmapContentLayerUpdater::ReduceMemoryUsage() { |
| 105 canvas_.clear(); | 104 canvas_.clear(); |
| 106 canvas_size_ = gfx::Size(); | 105 canvas_size_ = gfx::Size(); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void BitmapContentLayerUpdater::SetOpaque(bool opaque) { | 108 void BitmapContentLayerUpdater::SetOpaque(bool opaque) { |
| 110 if (opaque != layer_is_opaque_) { | 109 if (opaque != layer_is_opaque_) { |
| 111 canvas_.clear(); | 110 canvas_.clear(); |
| 112 canvas_size_ = gfx::Size(); | 111 canvas_size_ = gfx::Size(); |
| 113 } | 112 } |
| 114 | 113 |
| 115 ContentLayerUpdater::SetOpaque(opaque); | 114 ContentLayerUpdater::SetOpaque(opaque); |
| 116 } | 115 } |
| 117 | 116 |
| 118 } // namespace cc | 117 } // namespace cc |
| OLD | NEW |