Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: ui/android/resources/ui_resource_provider.cc

Issue 1371523003: Android: Don't destroy LayerTreeHost when Surface goes away (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/android/resources/ui_resource_provider.h" 5 #include "ui/android/resources/ui_resource_provider.h"
6 6
7 #include "cc/resources/ui_resource_client.h" 7 #include "cc/resources/ui_resource_client.h"
8 #include "cc/trees/layer_tree_host.h" 8 #include "cc/trees/layer_tree_host.h"
9 #include "ui/android/resources/ui_resource_client_android.h" 9 #include "ui/android/resources/ui_resource_client_android.h"
10 10
11 namespace ui { 11 namespace ui {
12 12
13 UIResourceProvider::UIResourceProvider() 13 UIResourceProvider::UIResourceProvider(cc::LayerTreeHost* host)
14 : host_(NULL), supports_etc1_npot_(false) { 14 : host_(host), supports_etc1_npot_(false) {
15 } 15 }
16 16
17 UIResourceProvider::~UIResourceProvider() { 17 UIResourceProvider::~UIResourceProvider() {
18 SetLayerTreeHost(NULL); 18 OnUIResourcesEvicted();
19 } 19 }
20 20
21 void UIResourceProvider::SetLayerTreeHost(cc::LayerTreeHost* host) { 21 void UIResourceProvider::OnUIResourcesEvicted() {
22 if (host_ == host) 22 // OnWasEvicted() might cause DeleteUIResource() to get called.
23 return; 23 UIResourceClientMap client_map(ui_resource_client_map_);
24 host_ = host;
25 UIResourcesAreInvalid();
26 }
27
28 void UIResourceProvider::UIResourcesAreInvalid() {
29 UIResourceClientMap client_map;
30 client_map.swap(ui_resource_client_map_);
31 for (UIResourceClientMap::iterator iter = client_map.begin(); 24 for (UIResourceClientMap::iterator iter = client_map.begin();
32 iter != client_map.end(); iter++) { 25 iter != client_map.end(); iter++) {
33 iter->second->UIResourceIsInvalid(); 26 iter->second->OnWasEvicted();
34 } 27 }
35 } 28 }
36 29
37 cc::UIResourceId UIResourceProvider::CreateUIResource( 30 cc::UIResourceId UIResourceProvider::CreateUIResource(
38 ui::UIResourceClientAndroid* client) { 31 ui::UIResourceClientAndroid* client) {
39 if (!host_)
40 return 0;
41 cc::UIResourceId id = host_->CreateUIResource(client); 32 cc::UIResourceId id = host_->CreateUIResource(client);
42 DCHECK(ui_resource_client_map_.find(id) == ui_resource_client_map_.end()); 33 DCHECK(ui_resource_client_map_.find(id) == ui_resource_client_map_.end());
43 34
44 ui_resource_client_map_[id] = client; 35 ui_resource_client_map_[id] = client;
45 return id; 36 return id;
46 } 37 }
47 38
48 void UIResourceProvider::DeleteUIResource(cc::UIResourceId ui_resource_id) { 39 void UIResourceProvider::DeleteUIResource(cc::UIResourceId ui_resource_id) {
49 UIResourceClientMap::iterator iter = 40 UIResourceClientMap::iterator iter =
50 ui_resource_client_map_.find(ui_resource_id); 41 ui_resource_client_map_.find(ui_resource_id);
51 DCHECK(iter != ui_resource_client_map_.end()); 42 DCHECK(iter != ui_resource_client_map_.end());
52 43
53 ui_resource_client_map_.erase(iter); 44 ui_resource_client_map_.erase(iter);
54
55 if (!host_)
56 return;
57 host_->DeleteUIResource(ui_resource_id); 45 host_->DeleteUIResource(ui_resource_id);
58 } 46 }
59 47
60 bool UIResourceProvider::SupportsETC1NonPowerOfTwo() const { 48 bool UIResourceProvider::SupportsETC1NonPowerOfTwo() const {
61 return supports_etc1_npot_; 49 return supports_etc1_npot_;
62 } 50 }
63 51
64 } // namespace ui 52 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698