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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 : ContentLayerUpdater(painter.Pass(), stats_instrumentation, layer_id) {} | 47 : ContentLayerUpdater(painter.Pass(), stats_instrumentation, layer_id) {} |
48 | 48 |
49 BitmapContentLayerUpdater::~BitmapContentLayerUpdater() {} | 49 BitmapContentLayerUpdater::~BitmapContentLayerUpdater() {} |
50 | 50 |
51 scoped_ptr<LayerUpdater::Resource> BitmapContentLayerUpdater::CreateResource( | 51 scoped_ptr<LayerUpdater::Resource> BitmapContentLayerUpdater::CreateResource( |
52 PrioritizedResourceManager* manager) { | 52 PrioritizedResourceManager* manager) { |
53 return scoped_ptr<LayerUpdater::Resource>( | 53 return scoped_ptr<LayerUpdater::Resource>( |
54 new Resource(this, PrioritizedResource::Create(manager))); | 54 new Resource(this, PrioritizedResource::Create(manager))); |
55 } | 55 } |
56 | 56 |
57 void BitmapContentLayerUpdater::PrepareToUpdate(const gfx::Rect& content_rect, | 57 void BitmapContentLayerUpdater::PrepareToUpdate(const gfx::Size& content_size, |
| 58 const gfx::Rect& paint_rect, |
58 const gfx::Size& tile_size, | 59 const 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 if (canvas_size_ != content_rect.size()) { | 62 if (canvas_size_ != paint_rect.size()) { |
62 devtools_instrumentation::ScopedLayerTask paint_setup( | 63 devtools_instrumentation::ScopedLayerTask paint_setup( |
63 devtools_instrumentation::kPaintSetup, layer_id_); | 64 devtools_instrumentation::kPaintSetup, layer_id_); |
64 canvas_size_ = content_rect.size(); | 65 canvas_size_ = paint_rect.size(); |
65 bitmap_backing_.allocN32Pixels( | 66 bitmap_backing_.allocN32Pixels( |
66 canvas_size_.width(), canvas_size_.height(), layer_is_opaque_); | 67 canvas_size_.width(), canvas_size_.height(), layer_is_opaque_); |
67 // TODO(danak): Remove when skia does the check for us: crbug.com/360384 | 68 // TODO(danak): Remove when skia does the check for us: crbug.com/360384 |
68 canvas_ = skia::AdoptRef(new SkCanvas(bitmap_backing_)); | 69 canvas_ = skia::AdoptRef(new SkCanvas(bitmap_backing_)); |
69 DCHECK_EQ(content_rect.width(), canvas_->getBaseLayerSize().width()); | 70 DCHECK_EQ(paint_rect.width(), canvas_->getBaseLayerSize().width()); |
70 DCHECK_EQ(content_rect.height(), canvas_->getBaseLayerSize().height()); | 71 DCHECK_EQ(paint_rect.height(), canvas_->getBaseLayerSize().height()); |
71 } | 72 } |
72 | 73 |
73 base::TimeTicks start_time = | 74 base::TimeTicks start_time = |
74 rendering_stats_instrumentation_->StartRecording(); | 75 rendering_stats_instrumentation_->StartRecording(); |
75 PaintContents( | 76 PaintContents(canvas_.get(), |
76 canvas_.get(), content_rect, contents_width_scale, contents_height_scale); | 77 content_size, |
| 78 paint_rect, |
| 79 contents_width_scale, |
| 80 contents_height_scale); |
77 base::TimeDelta duration = | 81 base::TimeDelta duration = |
78 rendering_stats_instrumentation_->EndRecording(start_time); | 82 rendering_stats_instrumentation_->EndRecording(start_time); |
79 rendering_stats_instrumentation_->AddPaint( | 83 rendering_stats_instrumentation_->AddPaint( |
80 duration, | 84 duration, paint_rect.width() * paint_rect.height()); |
81 content_rect.width() * content_rect.height()); | |
82 } | 85 } |
83 | 86 |
84 void BitmapContentLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue, | 87 void BitmapContentLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue, |
85 PrioritizedResource* texture, | 88 PrioritizedResource* texture, |
86 const gfx::Rect& source_rect, | 89 const gfx::Rect& source_rect, |
87 const gfx::Vector2d& dest_offset, | 90 const gfx::Vector2d& dest_offset, |
88 bool partial_update) { | 91 bool partial_update) { |
89 CHECK(canvas_); | 92 CHECK(canvas_); |
90 ResourceUpdate upload = ResourceUpdate::Create(texture, | 93 ResourceUpdate upload = ResourceUpdate::Create( |
91 &bitmap_backing_, | 94 texture, &bitmap_backing_, paint_rect(), source_rect, dest_offset); |
92 content_rect(), | |
93 source_rect, | |
94 dest_offset); | |
95 if (partial_update) | 95 if (partial_update) |
96 queue->AppendPartialUpload(upload); | 96 queue->AppendPartialUpload(upload); |
97 else | 97 else |
98 queue->AppendFullUpload(upload); | 98 queue->AppendFullUpload(upload); |
99 } | 99 } |
100 | 100 |
101 void BitmapContentLayerUpdater::ReduceMemoryUsage() { | 101 void BitmapContentLayerUpdater::ReduceMemoryUsage() { |
102 canvas_.clear(); | 102 canvas_.clear(); |
103 canvas_size_ = gfx::Size(); | 103 canvas_size_ = gfx::Size(); |
104 } | 104 } |
105 | 105 |
106 void BitmapContentLayerUpdater::SetOpaque(bool opaque) { | 106 void BitmapContentLayerUpdater::SetOpaque(bool opaque) { |
107 if (opaque != layer_is_opaque_) { | 107 if (opaque != layer_is_opaque_) { |
108 canvas_.clear(); | 108 canvas_.clear(); |
109 canvas_size_ = gfx::Size(); | 109 canvas_size_ = gfx::Size(); |
110 } | 110 } |
111 | 111 |
112 ContentLayerUpdater::SetOpaque(opaque); | 112 ContentLayerUpdater::SetOpaque(opaque); |
113 } | 113 } |
114 | 114 |
115 } // namespace cc | 115 } // namespace cc |
OLD | NEW |