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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 BitmapContentLayerUpdater::~BitmapContentLayerUpdater() {} | 48 BitmapContentLayerUpdater::~BitmapContentLayerUpdater() {} |
49 | 49 |
50 scoped_ptr<LayerUpdater::Resource> BitmapContentLayerUpdater::CreateResource( | 50 scoped_ptr<LayerUpdater::Resource> BitmapContentLayerUpdater::CreateResource( |
51 PrioritizedResourceManager* manager) { | 51 PrioritizedResourceManager* manager) { |
52 return scoped_ptr<LayerUpdater::Resource>( | 52 return scoped_ptr<LayerUpdater::Resource>( |
53 new Resource(this, PrioritizedResource::Create(manager))); | 53 new Resource(this, PrioritizedResource::Create(manager))); |
54 } | 54 } |
55 | 55 |
56 void BitmapContentLayerUpdater::PrepareToUpdate( | 56 void BitmapContentLayerUpdater::PrepareToUpdate( |
57 gfx::Rect content_rect, | 57 gfx::Rect content_rect, |
| 58 gfx::Rect paint_rect, |
58 gfx::Size tile_size, | 59 gfx::Size tile_size, |
59 float contents_width_scale, | 60 float contents_width_scale, |
60 float contents_height_scale, | 61 float contents_height_scale, |
61 gfx::Rect* resulting_opaque_rect) { | 62 gfx::Rect* resulting_opaque_rect) { |
62 devtools_instrumentation::ScopedLayerTask paint_layer( | 63 devtools_instrumentation::ScopedLayerTask paint_layer( |
63 devtools_instrumentation::kPaintLayer, layer_id_); | 64 devtools_instrumentation::kPaintLayer, layer_id_); |
64 if (canvas_size_.width() < content_rect.size().width() || | 65 if (canvas_size_.width() < content_rect.size().width() || |
65 canvas_size_.height() < content_rect.size().height()) { | 66 canvas_size_.height() < content_rect.size().height()) { |
66 devtools_instrumentation::ScopedLayerTask paint_setup( | 67 devtools_instrumentation::ScopedLayerTask paint_setup( |
67 devtools_instrumentation::kPaintSetup, layer_id_); | 68 devtools_instrumentation::kPaintSetup, layer_id_); |
68 canvas_size_ = content_rect.size(); | 69 canvas_size_ = content_rect.size(); |
69 bitmap_backing_.setConfig( | 70 bitmap_backing_.setConfig( |
70 SkBitmap::kARGB_8888_Config, | 71 SkBitmap::kARGB_8888_Config, |
71 canvas_size_.width(), canvas_size_.height(), | 72 canvas_size_.width(), canvas_size_.height(), |
72 0, layer_is_opaque_ ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 73 0, layer_is_opaque_ ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
73 bitmap_backing_.allocPixels(); | 74 bitmap_backing_.allocPixels(); |
74 canvas_ = skia::AdoptRef(new SkCanvas(bitmap_backing_)); | 75 canvas_ = skia::AdoptRef(new SkCanvas(bitmap_backing_)); |
75 } | 76 } |
76 | 77 |
77 base::TimeTicks start_time = | 78 base::TimeTicks start_time = |
78 rendering_stats_instrumentation_->StartRecording(); | 79 rendering_stats_instrumentation_->StartRecording(); |
79 PaintContents(canvas_.get(), | 80 PaintContents(canvas_.get(), |
80 content_rect, | 81 content_rect, |
| 82 paint_rect, |
81 contents_width_scale, | 83 contents_width_scale, |
82 contents_height_scale, | 84 contents_height_scale, |
83 resulting_opaque_rect); | 85 resulting_opaque_rect); |
84 base::TimeDelta duration = | 86 base::TimeDelta duration = |
85 rendering_stats_instrumentation_->EndRecording(start_time); | 87 rendering_stats_instrumentation_->EndRecording(start_time); |
86 rendering_stats_instrumentation_->AddPaint( | 88 rendering_stats_instrumentation_->AddPaint( |
87 duration, | 89 duration, |
88 content_rect.width() * content_rect.height()); | 90 content_rect.width() * content_rect.height()); |
89 } | 91 } |
90 | 92 |
91 void BitmapContentLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue, | 93 void BitmapContentLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue, |
92 PrioritizedResource* texture, | 94 PrioritizedResource* texture, |
93 gfx::Rect source_rect, | 95 gfx::Rect source_rect, |
94 gfx::Vector2d dest_offset, | 96 gfx::Vector2d dest_offset, |
95 bool partial_update) { | 97 bool partial_update) { |
96 CHECK(canvas_); | 98 CHECK(canvas_); |
97 gfx::Rect canvas_rect = content_rect(); | 99 gfx::Rect canvas_rect = paint_rect(); |
98 canvas_rect.set_size(canvas_size_); | 100 canvas_rect.set_size(canvas_size_); |
99 ResourceUpdate upload = ResourceUpdate::CreateFromCanvas( | 101 ResourceUpdate upload = ResourceUpdate::CreateFromCanvas( |
100 texture, canvas_, canvas_rect, source_rect, dest_offset); | 102 texture, canvas_, canvas_rect, source_rect, dest_offset); |
101 if (partial_update) | 103 if (partial_update) |
102 queue->AppendPartialUpload(upload); | 104 queue->AppendPartialUpload(upload); |
103 else | 105 else |
104 queue->AppendFullUpload(upload); | 106 queue->AppendFullUpload(upload); |
105 } | 107 } |
106 | 108 |
107 void BitmapContentLayerUpdater::ReduceMemoryUsage() { | 109 void BitmapContentLayerUpdater::ReduceMemoryUsage() { |
108 canvas_.clear(); | 110 canvas_.clear(); |
109 canvas_size_ = gfx::Size(); | 111 canvas_size_ = gfx::Size(); |
110 } | 112 } |
111 | 113 |
112 void BitmapContentLayerUpdater::SetOpaque(bool opaque) { | 114 void BitmapContentLayerUpdater::SetOpaque(bool opaque) { |
113 if (opaque != layer_is_opaque_) { | 115 if (opaque != layer_is_opaque_) { |
114 canvas_.clear(); | 116 canvas_.clear(); |
115 canvas_size_ = gfx::Size(); | 117 canvas_size_ = gfx::Size(); |
116 } | 118 } |
117 | 119 |
118 ContentLayerUpdater::SetOpaque(opaque); | 120 ContentLayerUpdater::SetOpaque(opaque); |
119 } | 121 } |
120 | 122 |
121 } // namespace cc | 123 } // namespace cc |
OLD | NEW |