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/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 void Init(cc::UIResourceManager* ui_resource_manager); | 35 void Init(cc::UIResourceManager* ui_resource_manager); |
36 | 36 |
37 // ResourceManager implementation. | 37 // ResourceManager implementation. |
38 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; | 38 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; |
39 Resource* GetResource(AndroidResourceType res_type, int res_id) override; | 39 Resource* GetResource(AndroidResourceType res_type, int res_id) override; |
40 Resource* GetStaticResourceWithTint( | 40 Resource* GetStaticResourceWithTint( |
41 int res_id, SkColor tint_color) override; | 41 int res_id, SkColor tint_color) override; |
42 void RemoveUnusedTints(const std::unordered_set<int>& used_tints) override; | 42 void RemoveUnusedTints(const std::unordered_set<int>& used_tints) override; |
43 void PreloadResource(AndroidResourceType res_type, int res_id) override; | 43 void PreloadResource(AndroidResourceType res_type, int res_id) override; |
44 CrushedSpriteResource* GetCrushedSpriteResource( | |
45 int bitmap_res_id, int metadata_res_id) override; | |
46 | 44 |
47 // Called from Java | 45 // Called from Java |
48 // ---------------------------------------------------------- | 46 // ---------------------------------------------------------- |
49 void OnResourceReady(JNIEnv* env, | 47 void OnResourceReady(JNIEnv* env, |
50 const base::android::JavaRef<jobject>& jobj, | 48 const base::android::JavaRef<jobject>& jobj, |
51 jint res_type, | 49 jint res_type, |
52 jint res_id, | 50 jint res_id, |
53 const base::android::JavaRef<jobject>& bitmap, | 51 const base::android::JavaRef<jobject>& bitmap, |
54 jlong native_resource); | 52 jlong native_resource); |
55 void OnCrushedSpriteResourceReady( | |
56 JNIEnv* env, | |
57 const base::android::JavaRef<jobject>& jobj, | |
58 jint bitmap_res_id, | |
59 const base::android::JavaRef<jobject>& bitmap, | |
60 const base::android::JavaRef<jobjectArray>& frame_rects, | |
61 jint unscaled_sprite_width, | |
62 jint unscaled_sprite_height, | |
63 jfloat scaled_sprite_width, | |
64 jfloat scaled_sprite_height); | |
65 void OnCrushedSpriteResourceReloaded( | |
66 JNIEnv* env, | |
67 const base::android::JavaRef<jobject>& jobj, | |
68 jint bitmap_res_id, | |
69 const base::android::JavaRef<jobject>& bitmap); | |
70 void RemoveResource( | 53 void RemoveResource( |
71 JNIEnv* env, | 54 JNIEnv* env, |
72 const base::android::JavaRef<jobject>& jobj, | 55 const base::android::JavaRef<jobject>& jobj, |
73 jint res_type, | 56 jint res_type, |
74 jint res_id); | 57 jint res_id); |
75 void ClearTintedResourceCache(JNIEnv* env, | 58 void ClearTintedResourceCache(JNIEnv* env, |
76 const base::android::JavaRef<jobject>& jobj); | 59 const base::android::JavaRef<jobject>& jobj); |
77 | 60 |
78 static bool RegisterResourceManager(JNIEnv* env); | 61 static bool RegisterResourceManager(JNIEnv* env); |
79 | 62 |
80 // Helper method for processing crushed sprite metadata; public for testing. | |
81 CrushedSpriteResource::SrcDstRects ProcessCrushedSpriteFrameRects( | |
82 std::vector<std::vector<int>> frame_rects_vector); | |
83 | |
84 // base::trace_event::MemoryDumpProvider implementation. | 63 // base::trace_event::MemoryDumpProvider implementation. |
85 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 64 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
86 base::trace_event::ProcessMemoryDump* pmd) override; | 65 base::trace_event::ProcessMemoryDump* pmd) override; |
87 | 66 |
88 private: | 67 private: |
89 friend class TestResourceManagerImpl; | 68 friend class TestResourceManagerImpl; |
90 | 69 |
91 // Start loading the resource. virtual for testing. | 70 // Start loading the resource. virtual for testing. |
92 virtual void PreloadResourceFromJava(AndroidResourceType res_type, | 71 virtual void PreloadResourceFromJava(AndroidResourceType res_type, |
93 int res_id); | 72 int res_id); |
94 virtual void RequestResourceFromJava(AndroidResourceType res_type, | 73 virtual void RequestResourceFromJava(AndroidResourceType res_type, |
95 int res_id); | 74 int res_id); |
96 virtual void RequestCrushedSpriteResourceFromJava(int bitmap_res_id, | |
97 int metadata_res_id, | |
98 bool reloading); | |
99 | 75 |
100 using ResourceMap = std::unordered_map<int, std::unique_ptr<Resource>>; | 76 using ResourceMap = std::unordered_map<int, std::unique_ptr<Resource>>; |
101 using CrushedSpriteResourceMap = | |
102 std::unordered_map<int, std::unique_ptr<CrushedSpriteResource>>; | |
103 using TintedResourceMap = | 77 using TintedResourceMap = |
104 std::unordered_map<SkColor, std::unique_ptr<ResourceMap>>; | 78 std::unordered_map<SkColor, std::unique_ptr<ResourceMap>>; |
105 | 79 |
106 cc::UIResourceManager* ui_resource_manager_; | 80 cc::UIResourceManager* ui_resource_manager_; |
107 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; | 81 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; |
108 CrushedSpriteResourceMap crushed_sprite_resources_; | |
109 TintedResourceMap tinted_resources_; | 82 TintedResourceMap tinted_resources_; |
110 | 83 |
111 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | 84 base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
112 | 85 |
113 DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl); | 86 DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl); |
114 }; | 87 }; |
115 | 88 |
116 } // namespace ui | 89 } // namespace ui |
117 | 90 |
118 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ | 91 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ |
OLD | NEW |