| 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 #ifndef UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ | 5 #ifndef UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ |
| 6 #define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ | 6 #define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/id_map.h" | |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/android/resources/resource_manager.h" | 12 #include "ui/android/resources/resource_manager.h" |
| 13 #include "ui/android/ui_android_export.h" | 13 #include "ui/android/ui_android_export.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 | 18 |
| 19 class UI_ANDROID_EXPORT ResourceManagerImpl : public ResourceManager { | 19 class UI_ANDROID_EXPORT ResourceManagerImpl : public ResourceManager { |
| 20 public: | 20 public: |
| 21 static ResourceManagerImpl* FromJavaObject(jobject jobj); | 21 static ResourceManagerImpl* FromJavaObject(jobject jobj); |
| 22 | 22 |
| 23 explicit ResourceManagerImpl(gfx::NativeWindow native_window); | 23 explicit ResourceManagerImpl(gfx::NativeWindow native_window); |
| 24 ~ResourceManagerImpl() override; | 24 ~ResourceManagerImpl() override; |
| 25 | 25 |
| 26 void Init(cc::LayerTreeHost* host); | 26 void Init(cc::LayerTreeHost* host); |
| 27 | 27 |
| 28 // ResourceManager implementation. | 28 // ResourceManager implementation. |
| 29 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; | 29 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; |
| 30 Resource* GetResource(AndroidResourceType res_type, int res_id) override; | 30 Resource* GetResource(AndroidResourceType res_type, int res_id) override; |
| 31 Resource* GetStaticResourceWithTint( | 31 Resource* GetStaticResourceWithTint( |
| 32 int res_id, int tint_color) override; | 32 int res_id, SkColor tint_color) override; |
| 33 void RemoveUnusedTints(const std::unordered_set<int>& used_tints) override; | 33 void RemoveUnusedTints(const std::unordered_set<int>& used_tints) override; |
| 34 void PreloadResource(AndroidResourceType res_type, int res_id) override; | 34 void PreloadResource(AndroidResourceType res_type, int res_id) override; |
| 35 CrushedSpriteResource* GetCrushedSpriteResource( | 35 CrushedSpriteResource* GetCrushedSpriteResource( |
| 36 int bitmap_res_id, int metadata_res_id) override; | 36 int bitmap_res_id, int metadata_res_id) override; |
| 37 | 37 |
| 38 // Called from Java | 38 // Called from Java |
| 39 // ---------------------------------------------------------- | 39 // ---------------------------------------------------------- |
| 40 void OnResourceReady(JNIEnv* env, | 40 void OnResourceReady(JNIEnv* env, |
| 41 const base::android::JavaRef<jobject>& jobj, | 41 const base::android::JavaRef<jobject>& jobj, |
| 42 jint res_type, | 42 jint res_type, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 // Start loading the resource. virtual for testing. | 80 // Start loading the resource. virtual for testing. |
| 81 virtual void PreloadResourceFromJava(AndroidResourceType res_type, | 81 virtual void PreloadResourceFromJava(AndroidResourceType res_type, |
| 82 int res_id); | 82 int res_id); |
| 83 virtual void RequestResourceFromJava(AndroidResourceType res_type, | 83 virtual void RequestResourceFromJava(AndroidResourceType res_type, |
| 84 int res_id); | 84 int res_id); |
| 85 virtual void RequestCrushedSpriteResourceFromJava(int bitmap_res_id, | 85 virtual void RequestCrushedSpriteResourceFromJava(int bitmap_res_id, |
| 86 int metadata_res_id, | 86 int metadata_res_id, |
| 87 bool reloading); | 87 bool reloading); |
| 88 | 88 |
| 89 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; | 89 using ResourceMap = std::unordered_map<int, std::unique_ptr<Resource>>; |
| 90 typedef IDMap<CrushedSpriteResource, IDMapOwnPointer> | 90 using CrushedSpriteResourceMap = |
| 91 CrushedSpriteResourceMap; | 91 std::unordered_map<int, std::unique_ptr<CrushedSpriteResource>>; |
| 92 typedef std::unordered_map<int, std::unique_ptr<ResourceMap> > | 92 using TintedResourceMap = |
| 93 TintedResourceMap; | 93 std::unordered_map<SkColor, std::unique_ptr<ResourceMap>>; |
| 94 | 94 |
| 95 cc::LayerTreeHost* host_; | 95 cc::LayerTreeHost* host_; |
| 96 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; | 96 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; |
| 97 CrushedSpriteResourceMap crushed_sprite_resources_; | 97 CrushedSpriteResourceMap crushed_sprite_resources_; |
| 98 TintedResourceMap tinted_resources_; | 98 TintedResourceMap tinted_resources_; |
| 99 | 99 |
| 100 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | 100 base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl); | 102 DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 } // namespace ui | 105 } // namespace ui |
| 106 | 106 |
| 107 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ | 107 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ |
| OLD | NEW |