| OLD | NEW |
| 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 "cc/resources/ui_resource_bitmap.h" | 5 #include "cc/resources/ui_resource_bitmap.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
| 8 #include "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
| 9 #include "ui/android/resources/resource_manager_impl.h" | 9 #include "ui/android/resources/resource_manager_impl.h" |
| 10 #include "ui/android/resources/system_ui_resource_type.h" | 10 #include "ui/android/resources/system_ui_resource_type.h" |
| 11 #include "ui/android/resources/ui_resource_client_android.h" | 11 #include "ui/android/resources/ui_resource_client_android.h" |
| 12 #include "ui/android/resources/ui_resource_provider.h" | 12 #include "ui/android/resources/ui_resource_provider.h" |
| 13 #include "ui/gfx/android/java_bitmap.h" | 13 #include "ui/gfx/android/java_bitmap.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace ui { |
| 16 | 16 |
| 17 class TestResourceManagerImpl : public ResourceManagerImpl { | 17 class TestResourceManagerImpl : public ResourceManagerImpl { |
| 18 public: | 18 public: |
| 19 explicit TestResourceManagerImpl(UIResourceProvider* provider) | 19 explicit TestResourceManagerImpl(UIResourceProvider* provider) |
| 20 : ResourceManagerImpl(provider) {} | 20 : ResourceManagerImpl(provider) {} |
| 21 | 21 |
| 22 virtual ~TestResourceManagerImpl() {} | 22 ~TestResourceManagerImpl() override {} |
| 23 | 23 |
| 24 void SetResourceAsLoaded(AndroidResourceType res_type, int res_id) { | 24 void SetResourceAsLoaded(AndroidResourceType res_type, int res_id) { |
| 25 SkBitmap small_bitmap; | 25 SkBitmap small_bitmap; |
| 26 SkCanvas canvas(small_bitmap); | 26 SkCanvas canvas(small_bitmap); |
| 27 small_bitmap.allocPixels( | 27 small_bitmap.allocPixels( |
| 28 SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); | 28 SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 29 canvas.drawColor(SK_ColorWHITE); | 29 canvas.drawColor(SK_ColorWHITE); |
| 30 small_bitmap.setImmutable(); | 30 small_bitmap.setImmutable(); |
| 31 | 31 |
| 32 OnResourceReady(NULL, NULL, res_type, res_id, | 32 OnResourceReady(NULL, NULL, res_type, res_id, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 | 50 |
| 51 class MockUIResourceProvider : public ui::UIResourceProvider { | 51 class MockUIResourceProvider : public ui::UIResourceProvider { |
| 52 public: | 52 public: |
| 53 MockUIResourceProvider() | 53 MockUIResourceProvider() |
| 54 : next_ui_resource_id_(1), | 54 : next_ui_resource_id_(1), |
| 55 has_layer_tree_host_(true), | 55 has_layer_tree_host_(true), |
| 56 resource_manager_(this) {} | 56 resource_manager_(this) {} |
| 57 | 57 |
| 58 virtual ~MockUIResourceProvider() {} | 58 virtual ~MockUIResourceProvider() {} |
| 59 | 59 |
| 60 virtual cc::UIResourceId CreateUIResource( | 60 cc::UIResourceId CreateUIResource( |
| 61 ui::UIResourceClientAndroid* client) override { | 61 ui::UIResourceClientAndroid* client) override { |
| 62 if (!has_layer_tree_host_) | 62 if (!has_layer_tree_host_) |
| 63 return 0; | 63 return 0; |
| 64 cc::UIResourceId id = next_ui_resource_id_++; | 64 cc::UIResourceId id = next_ui_resource_id_++; |
| 65 client->GetBitmap(id, false); | 65 client->GetBitmap(id, false); |
| 66 ui_resource_client_map_[id] = client; | 66 ui_resource_client_map_[id] = client; |
| 67 return id; | 67 return id; |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void DeleteUIResource(cc::UIResourceId id) override { | 70 void DeleteUIResource(cc::UIResourceId id) override { |
| 71 CHECK(has_layer_tree_host_); | 71 CHECK(has_layer_tree_host_); |
| 72 ui_resource_client_map_.erase(id); | 72 ui_resource_client_map_.erase(id); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual bool SupportsETC1NonPowerOfTwo() const override { return true; } | 75 bool SupportsETC1NonPowerOfTwo() const override { return true; } |
| 76 | 76 |
| 77 void LayerTreeHostCleared() { | 77 void LayerTreeHostCleared() { |
| 78 has_layer_tree_host_ = false; | 78 has_layer_tree_host_ = false; |
| 79 UIResourceClientMap client_map = ui_resource_client_map_; | 79 UIResourceClientMap client_map = ui_resource_client_map_; |
| 80 ui_resource_client_map_.clear(); | 80 ui_resource_client_map_.clear(); |
| 81 for (UIResourceClientMap::iterator iter = client_map.begin(); | 81 for (UIResourceClientMap::iterator iter = client_map.begin(); |
| 82 iter != client_map.end(); iter++) { | 82 iter != client_map.end(); iter++) { |
| 83 iter->second->UIResourceIsInvalid(); | 83 iter->second->UIResourceIsInvalid(); |
| 84 } | 84 } |
| 85 } | 85 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 TEST_F(ResourceManagerTest, ResetLayerTreeHost) { | 153 TEST_F(ResourceManagerTest, ResetLayerTreeHost) { |
| 154 EXPECT_NE(0, GetUIResourceId(kTestResourceType)); | 154 EXPECT_NE(0, GetUIResourceId(kTestResourceType)); |
| 155 LayerTreeHostCleared(); | 155 LayerTreeHostCleared(); |
| 156 EXPECT_EQ(0, GetUIResourceId(kTestResourceType)); | 156 EXPECT_EQ(0, GetUIResourceId(kTestResourceType)); |
| 157 LayerTreeHostReturned(); | 157 LayerTreeHostReturned(); |
| 158 EXPECT_NE(0, GetUIResourceId(kTestResourceType)); | 158 EXPECT_NE(0, GetUIResourceId(kTestResourceType)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace ui | 161 } // namespace ui |
| OLD | NEW |