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
3 // found in the LICENSE file.
5 #include "ui/android/resources/ui_resource_provider.h"
7 #include "cc/resources/ui_resource_client.h"
8 #include "cc/trees/layer_tree_host.h"
9 #include "ui/android/resources/ui_resource_client_android.h"
13 UIResourceProvider::UIResourceProvider()
14 : host_(NULL
), supports_etc1_npot_(false) {
17 UIResourceProvider::~UIResourceProvider() {
18 SetLayerTreeHost(NULL
);
21 void UIResourceProvider::SetLayerTreeHost(cc::LayerTreeHost
* host
) {
25 UIResourcesAreInvalid();
28 void UIResourceProvider::UIResourcesAreInvalid() {
29 UIResourceClientMap client_map
;
30 client_map
.swap(ui_resource_client_map_
);
31 for (UIResourceClientMap::iterator iter
= client_map
.begin();
32 iter
!= client_map
.end(); iter
++) {
33 iter
->second
->UIResourceIsInvalid();
37 cc::UIResourceId
UIResourceProvider::CreateUIResource(
38 ui::UIResourceClientAndroid
* client
) {
41 cc::UIResourceId id
= host_
->CreateUIResource(client
);
42 DCHECK(ui_resource_client_map_
.find(id
) == ui_resource_client_map_
.end());
44 ui_resource_client_map_
[id
] = client
;
48 void UIResourceProvider::DeleteUIResource(cc::UIResourceId ui_resource_id
) {
49 UIResourceClientMap::iterator iter
=
50 ui_resource_client_map_
.find(ui_resource_id
);
51 DCHECK(iter
!= ui_resource_client_map_
.end());
53 ui_resource_client_map_
.erase(iter
);
57 host_
->DeleteUIResource(ui_resource_id
);
60 bool UIResourceProvider::SupportsETC1NonPowerOfTwo() const {
61 return supports_etc1_npot_
;