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 "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "ui/android/resources/resource_manager.h" | 9 #include "ui/android/resources/resource_manager.h" |
10 #include "ui/android/ui_android_export.h" | 10 #include "ui/android/ui_android_export.h" |
11 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 class UI_ANDROID_EXPORT ResourceManagerImpl : public ResourceManager { | 15 class UI_ANDROID_EXPORT ResourceManagerImpl : public ResourceManager { |
16 public: | 16 public: |
17 static ResourceManagerImpl* FromJavaObject(jobject jobj); | 17 static ResourceManagerImpl* FromJavaObject(jobject jobj); |
18 | 18 |
19 ResourceManagerImpl(); | 19 ResourceManagerImpl(); |
20 ~ResourceManagerImpl() override; | 20 ~ResourceManagerImpl() override; |
21 | 21 |
22 void Init(cc::LayerTreeHost* host); | 22 void Init(cc::LayerTreeHost* host); |
23 | 23 |
24 // ResourceManager implementation. | 24 // ResourceManager implementation. |
25 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; | 25 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; |
26 Resource* GetResource(AndroidResourceType res_type, int res_id) override; | 26 Resource* GetResource(AndroidResourceType res_type, int res_id) override; |
27 void PreloadResource(AndroidResourceType res_type, int res_id) override; | 27 void PreloadResource(AndroidResourceType res_type, int res_id) override; |
| 28 CrushedSpriteResource* GetCrushedSpriteResource( |
| 29 int bitmap_res_id, int metadata_res_id) override; |
28 | 30 |
29 // Called from Java | 31 // Called from Java |
30 // ---------------------------------------------------------- | 32 // ---------------------------------------------------------- |
31 void OnResourceReady(JNIEnv* env, | 33 void OnResourceReady(JNIEnv* env, |
32 jobject jobj, | 34 jobject jobj, |
33 jint res_type, | 35 jint res_type, |
34 jint res_id, | 36 jint res_id, |
35 jobject bitmap, | 37 jobject bitmap, |
36 jint padding_left, | 38 jint padding_left, |
37 jint padding_top, | 39 jint padding_top, |
38 jint padding_right, | 40 jint padding_right, |
39 jint padding_bottom, | 41 jint padding_bottom, |
40 jint aperture_left, | 42 jint aperture_left, |
41 jint aperture_top, | 43 jint aperture_top, |
42 jint aperture_right, | 44 jint aperture_right, |
43 jint aperture_bottom); | 45 jint aperture_bottom); |
| 46 void OnCrushedSpriteResourceReady(JNIEnv* env, |
| 47 jobject jobj, |
| 48 jint bitmap_res_id, |
| 49 jobject bitmap, |
| 50 jobjectArray frame_rects, |
| 51 jint sprite_width, |
| 52 jint sprite_height); |
| 53 void OnCrushedSpriteResourceReloaded(JNIEnv* env, |
| 54 jobject jobj, |
| 55 jint bitmap_res_id, |
| 56 jobject bitmap); |
44 | 57 |
45 static bool RegisterResourceManager(JNIEnv* env); | 58 static bool RegisterResourceManager(JNIEnv* env); |
46 | 59 |
| 60 // Helper method for processing crushed sprite metadata; public for testing. |
| 61 CrushedSpriteResource::SrcDstRects ProcessCrushedSpriteFrameRects( |
| 62 std::vector<std::vector<int>> frame_rects_vector); |
| 63 |
47 private: | 64 private: |
48 friend class TestResourceManagerImpl; | 65 friend class TestResourceManagerImpl; |
49 | 66 |
50 // Start loading the resource. virtual for testing. | 67 // Start loading the resource. virtual for testing. |
51 virtual void PreloadResourceFromJava(AndroidResourceType res_type, | 68 virtual void PreloadResourceFromJava(AndroidResourceType res_type, |
52 int res_id); | 69 int res_id); |
53 virtual void RequestResourceFromJava(AndroidResourceType res_type, | 70 virtual void RequestResourceFromJava(AndroidResourceType res_type, |
54 int res_id); | 71 int res_id); |
| 72 virtual void RequestCrushedSpriteResourceFromJava(int bitmap_res_id, |
| 73 int metadata_res_id, |
| 74 bool reloading); |
55 | 75 |
56 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; | 76 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; |
| 77 typedef IDMap<CrushedSpriteResource, IDMapOwnPointer> |
| 78 CrushedSpriteResourceMap; |
57 | 79 |
58 cc::LayerTreeHost* host_; | 80 cc::LayerTreeHost* host_; |
59 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; | 81 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; |
| 82 CrushedSpriteResourceMap crushed_sprite_resources_; |
60 | 83 |
61 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | 84 base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
62 | 85 |
63 DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl); | 86 DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl); |
64 }; | 87 }; |
65 | 88 |
66 } // namespace ui | 89 } // namespace ui |
67 | 90 |
68 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ | 91 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_ |
OLD | NEW |