| 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <stack> | 8 #include <stack> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 allow_partial_texture_updates(false), | 54 allow_partial_texture_updates(false), |
| 55 using_offscreen_context3d(false), | 55 using_offscreen_context3d(false), |
| 56 max_texture_size(0), | 56 max_texture_size(0), |
| 57 avoid_pow2_textures(false), | 57 avoid_pow2_textures(false), |
| 58 using_map_image(false), | 58 using_map_image(false), |
| 59 using_shared_memory_resources(false), | 59 using_shared_memory_resources(false), |
| 60 using_discard_framebuffer(false) {} | 60 using_discard_framebuffer(false) {} |
| 61 | 61 |
| 62 RendererCapabilities::~RendererCapabilities() {} | 62 RendererCapabilities::~RendererCapabilities() {} |
| 63 | 63 |
| 64 UIResourceRequest::UIResourceRequest() | 64 UIResourceRequest::UIResourceRequest(UIResourceRequestType type, |
| 65 : type(UIResourceInvalidRequest), id(0), bitmap(NULL) {} | 65 UIResourceId id) |
| 66 : type_(type), id_(id) {} |
| 67 |
| 68 UIResourceRequest::UIResourceRequest(UIResourceRequestType type, |
| 69 UIResourceId id, |
| 70 const UIResourceBitmap& bitmap) |
| 71 : type_(type), id_(id), bitmap_(new UIResourceBitmap(bitmap)) {} |
| 72 |
| 73 UIResourceRequest::UIResourceRequest(const UIResourceRequest& request) { |
| 74 (*this) = request; |
| 75 } |
| 76 |
| 77 UIResourceRequest& UIResourceRequest::operator=( |
| 78 const UIResourceRequest& request) { |
| 79 type_ = request.type_; |
| 80 id_ = request.id_; |
| 81 if (request.bitmap_) { |
| 82 bitmap_ = make_scoped_ptr(new UIResourceBitmap(*request.bitmap_.get())); |
| 83 } else { |
| 84 bitmap_.reset(); |
| 85 } |
| 86 |
| 87 return *this; |
| 88 } |
| 66 | 89 |
| 67 UIResourceRequest::~UIResourceRequest() {} | 90 UIResourceRequest::~UIResourceRequest() {} |
| 68 | 91 |
| 69 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { | 92 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { |
| 70 return s_num_layer_tree_instances > 0; | 93 return s_num_layer_tree_instances > 0; |
| 71 } | 94 } |
| 72 | 95 |
| 73 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( | 96 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( |
| 74 LayerTreeHostClient* client, | 97 LayerTreeHostClient* client, |
| 75 const LayerTreeSettings& settings, | 98 const LayerTreeSettings& settings, |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_); | 405 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_); |
| 383 ui_resource_request_queue_.clear(); | 406 ui_resource_request_queue_.clear(); |
| 384 // Process any ui resource requests in the queue. For impl-side-painting, | 407 // Process any ui resource requests in the queue. For impl-side-painting, |
| 385 // the queue is processed in LayerTreeHostImpl::ActivatePendingTree. | 408 // the queue is processed in LayerTreeHostImpl::ActivatePendingTree. |
| 386 if (!settings_.impl_side_painting) | 409 if (!settings_.impl_side_painting) |
| 387 sync_tree->ProcessUIResourceRequestQueue(); | 410 sync_tree->ProcessUIResourceRequestQueue(); |
| 388 } | 411 } |
| 389 if (overhang_ui_resource_) { | 412 if (overhang_ui_resource_) { |
| 390 host_impl->SetOverhangUIResource( | 413 host_impl->SetOverhangUIResource( |
| 391 overhang_ui_resource_->id(), | 414 overhang_ui_resource_->id(), |
| 392 overhang_ui_resource_->GetSize()); | 415 GetUIResourceSize(overhang_ui_resource_->id())); |
| 393 } | 416 } |
| 394 | 417 |
| 395 DCHECK(!sync_tree->ViewportSizeInvalid()); | 418 DCHECK(!sync_tree->ViewportSizeInvalid()); |
| 396 | 419 |
| 397 if (new_impl_tree_has_no_evicted_resources) { | 420 if (new_impl_tree_has_no_evicted_resources) { |
| 398 if (sync_tree->ContentsTexturesPurged()) | 421 if (sync_tree->ContentsTexturesPurged()) |
| 399 sync_tree->ResetContentsTexturesPurged(); | 422 sync_tree->ResetContentsTexturesPurged(); |
| 400 } | 423 } |
| 401 | 424 |
| 402 if (!settings_.impl_side_painting) { | 425 if (!settings_.impl_side_painting) { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 page_scale_factor_ = page_scale_factor; | 663 page_scale_factor_ = page_scale_factor; |
| 641 min_page_scale_factor_ = min_page_scale_factor; | 664 min_page_scale_factor_ = min_page_scale_factor; |
| 642 max_page_scale_factor_ = max_page_scale_factor; | 665 max_page_scale_factor_ = max_page_scale_factor; |
| 643 SetNeedsCommit(); | 666 SetNeedsCommit(); |
| 644 } | 667 } |
| 645 | 668 |
| 646 void LayerTreeHost::SetOverhangBitmap(const SkBitmap& bitmap) { | 669 void LayerTreeHost::SetOverhangBitmap(const SkBitmap& bitmap) { |
| 647 DCHECK(bitmap.width() && bitmap.height()); | 670 DCHECK(bitmap.width() && bitmap.height()); |
| 648 DCHECK_EQ(bitmap.bytesPerPixel(), 4); | 671 DCHECK_EQ(bitmap.bytesPerPixel(), 4); |
| 649 | 672 |
| 650 scoped_refptr<UIResourceBitmap> overhang_ui_bitmap(UIResourceBitmap::Create( | 673 SkBitmap bitmap_copy; |
| 651 new uint8_t[bitmap.width() * bitmap.height() * bitmap.bytesPerPixel()], | 674 if (bitmap.isImmutable()) { |
| 652 UIResourceBitmap::RGBA8, | 675 bitmap_copy = bitmap; |
| 653 UIResourceBitmap::REPEAT, | 676 } else { |
| 654 gfx::Size(bitmap.width(), bitmap.height()))); | 677 bitmap.copyTo(&bitmap_copy, bitmap.config()); |
| 655 bitmap.copyPixelsTo( | 678 bitmap_copy.setImmutable(); |
| 656 overhang_ui_bitmap->GetPixels(), | 679 } |
| 657 bitmap.width() * bitmap.height() * bitmap.bytesPerPixel(), | 680 |
| 658 bitmap.width() * bitmap.bytesPerPixel()); | 681 overhang_ui_resource_ = ScopedUIResource::Create( |
| 659 overhang_ui_resource_ = ScopedUIResource::Create(this, overhang_ui_bitmap); | 682 this, UIResourceBitmap(bitmap_copy, UIResourceBitmap::REPEAT)); |
| 660 } | 683 } |
| 661 | 684 |
| 662 void LayerTreeHost::SetVisible(bool visible) { | 685 void LayerTreeHost::SetVisible(bool visible) { |
| 663 if (visible_ == visible) | 686 if (visible_ == visible) |
| 664 return; | 687 return; |
| 665 visible_ = visible; | 688 visible_ = visible; |
| 666 if (!visible) | 689 if (!visible) |
| 667 ReduceMemoryUsage(); | 690 ReduceMemoryUsage(); |
| 668 proxy_->SetVisible(visible); | 691 proxy_->SetVisible(visible); |
| 669 } | 692 } |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 ++iter) { | 1178 ++iter) { |
| 1156 (*iter).second->Animate(monotonic_time); | 1179 (*iter).second->Animate(monotonic_time); |
| 1157 bool start_ready_animations = true; | 1180 bool start_ready_animations = true; |
| 1158 (*iter).second->UpdateState(start_ready_animations, NULL); | 1181 (*iter).second->UpdateState(start_ready_animations, NULL); |
| 1159 } | 1182 } |
| 1160 } | 1183 } |
| 1161 | 1184 |
| 1162 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { | 1185 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { |
| 1163 DCHECK(client); | 1186 DCHECK(client); |
| 1164 | 1187 |
| 1165 UIResourceRequest request; | 1188 UIResourceId next_id = next_ui_resource_id_++; |
| 1166 bool resource_lost = false; | 1189 DCHECK(ui_resource_client_map_.find(next_id) == |
| 1167 request.type = UIResourceRequest::UIResourceCreate; | |
| 1168 request.id = next_ui_resource_id_++; | |
| 1169 | |
| 1170 DCHECK(ui_resource_client_map_.find(request.id) == | |
| 1171 ui_resource_client_map_.end()); | 1190 ui_resource_client_map_.end()); |
| 1172 | 1191 |
| 1173 request.bitmap = client->GetBitmap(request.id, resource_lost); | 1192 bool resource_lost = false; |
| 1193 UIResourceRequest request(UIResourceRequest::UIResourceCreate, |
| 1194 next_id, |
| 1195 client->GetBitmap(next_id, resource_lost)); |
| 1174 ui_resource_request_queue_.push_back(request); | 1196 ui_resource_request_queue_.push_back(request); |
| 1175 ui_resource_client_map_[request.id] = client; | 1197 |
| 1176 return request.id; | 1198 UIResourceClientData data; |
| 1199 data.client = client; |
| 1200 data.size = request.GetBitmap().GetSize(); |
| 1201 |
| 1202 ui_resource_client_map_[request.GetId()] = data; |
| 1203 return request.GetId(); |
| 1177 } | 1204 } |
| 1178 | 1205 |
| 1179 // Deletes a UI resource. May safely be called more than once. | 1206 // Deletes a UI resource. May safely be called more than once. |
| 1180 void LayerTreeHost::DeleteUIResource(UIResourceId uid) { | 1207 void LayerTreeHost::DeleteUIResource(UIResourceId uid) { |
| 1181 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid); | 1208 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid); |
| 1182 if (iter == ui_resource_client_map_.end()) | 1209 if (iter == ui_resource_client_map_.end()) |
| 1183 return; | 1210 return; |
| 1184 | 1211 |
| 1185 UIResourceRequest request; | 1212 UIResourceRequest request(UIResourceRequest::UIResourceDelete, uid); |
| 1186 request.type = UIResourceRequest::UIResourceDelete; | |
| 1187 request.id = uid; | |
| 1188 ui_resource_request_queue_.push_back(request); | 1213 ui_resource_request_queue_.push_back(request); |
| 1189 ui_resource_client_map_.erase(uid); | 1214 ui_resource_client_map_.erase(iter); |
| 1190 } | 1215 } |
| 1191 | 1216 |
| 1192 void LayerTreeHost::RecreateUIResources() { | 1217 void LayerTreeHost::RecreateUIResources() { |
| 1193 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin(); | 1218 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin(); |
| 1194 iter != ui_resource_client_map_.end(); | 1219 iter != ui_resource_client_map_.end(); |
| 1195 ++iter) { | 1220 ++iter) { |
| 1196 UIResourceId uid = iter->first; | 1221 UIResourceId uid = iter->first; |
| 1197 UIResourceRequest request; | 1222 const UIResourceClientData& data = iter->second; |
| 1198 request.type = UIResourceRequest::UIResourceCreate; | |
| 1199 request.id = uid; | |
| 1200 bool resource_lost = true; | 1223 bool resource_lost = true; |
| 1201 request.bitmap = iter->second->GetBitmap(uid, resource_lost); | 1224 UIResourceRequest request(UIResourceRequest::UIResourceCreate, |
| 1202 DCHECK(request.bitmap.get()); | 1225 uid, |
| 1226 data.client->GetBitmap(uid, resource_lost)); |
| 1203 ui_resource_request_queue_.push_back(request); | 1227 ui_resource_request_queue_.push_back(request); |
| 1204 } | 1228 } |
| 1205 } | 1229 } |
| 1206 | 1230 |
| 1231 // Returns the size of a resource given its id. |
| 1232 gfx::Size LayerTreeHost::GetUIResourceSize(UIResourceId uid) const { |
| 1233 UIResourceClientMap::const_iterator iter = ui_resource_client_map_.find(uid); |
| 1234 if (iter == ui_resource_client_map_.end()) |
| 1235 return gfx::Size(); |
| 1236 |
| 1237 const UIResourceClientData& data = iter->second; |
| 1238 return data.size; |
| 1239 } |
| 1240 |
| 1207 void LayerTreeHost::RegisterViewportLayers( | 1241 void LayerTreeHost::RegisterViewportLayers( |
| 1208 scoped_refptr<Layer> page_scale_layer, | 1242 scoped_refptr<Layer> page_scale_layer, |
| 1209 scoped_refptr<Layer> inner_viewport_scroll_layer, | 1243 scoped_refptr<Layer> inner_viewport_scroll_layer, |
| 1210 scoped_refptr<Layer> outer_viewport_scroll_layer) { | 1244 scoped_refptr<Layer> outer_viewport_scroll_layer) { |
| 1211 page_scale_layer_ = page_scale_layer; | 1245 page_scale_layer_ = page_scale_layer; |
| 1212 inner_viewport_scroll_layer_ = inner_viewport_scroll_layer; | 1246 inner_viewport_scroll_layer_ = inner_viewport_scroll_layer; |
| 1213 outer_viewport_scroll_layer_ = outer_viewport_scroll_layer; | 1247 outer_viewport_scroll_layer_ = outer_viewport_scroll_layer; |
| 1214 } | 1248 } |
| 1215 | 1249 |
| 1216 } // namespace cc | 1250 } // namespace cc |
| OLD | NEW |