| 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_H_ | 5 #ifndef UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
| 6 #define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ | 6 #define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 public: | 41 public: |
| 42 Resource(); | 42 Resource(); |
| 43 ~Resource(); | 43 ~Resource(); |
| 44 gfx::Rect Border(const gfx::Size& bounds) const; | 44 gfx::Rect Border(const gfx::Size& bounds) const; |
| 45 gfx::Rect Border(const gfx::Size& bounds, const gfx::InsetsF& scale) const; | 45 gfx::Rect Border(const gfx::Size& bounds, const gfx::InsetsF& scale) const; |
| 46 | 46 |
| 47 std::unique_ptr<cc::ScopedUIResource> ui_resource; | 47 std::unique_ptr<cc::ScopedUIResource> ui_resource; |
| 48 gfx::Size size; | 48 gfx::Size size; |
| 49 gfx::Rect padding; | 49 gfx::Rect padding; |
| 50 gfx::Rect aperture; | 50 gfx::Rect aperture; |
| 51 // The tint of the resource if applicable, 0 if no tint. |
| 52 int tint; |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 // Obtain a handle to the Java ResourceManager counterpart. | 55 // Obtain a handle to the Java ResourceManager counterpart. |
| 54 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaObject() = 0; | 56 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaObject() = 0; |
| 55 | 57 |
| 56 // Return a handle to the resource specified by |res_type| and |res_id|. | 58 // Return a handle to the resource specified by |res_type| and |res_id|. |
| 57 // If the resource has not been loaded, loading will be performed | 59 // If the resource has not been loaded, loading will be performed |
| 58 // synchronously, blocking until the load completes. | 60 // synchronously, blocking until the load completes. |
| 59 // If load fails, a null handle will be returned and it is up to the caller | 61 // If load fails, a null handle will be returned and it is up to the caller |
| 60 // to react appropriately. | 62 // to react appropriately. |
| 61 virtual Resource* GetResource(AndroidResourceType res_type, int res_id) = 0; | 63 virtual Resource* GetResource(AndroidResourceType res_type, int res_id) = 0; |
| 62 | 64 |
| 65 // Return a handle to a static resource specified by |res_id| that has a tint |
| 66 // of |tint_color| applied to it. |default_color| is used if the cache becomes |
| 67 // too large. |
| 68 virtual Resource* GetStaticResourceWithTint( |
| 69 int res_id, int tint_color, int default_color) = 0; |
| 70 |
| 63 // Trigger asynchronous loading of the resource specified by |res_type| and | 71 // Trigger asynchronous loading of the resource specified by |res_type| and |
| 64 // |res_id|, if it has not yet been loaded. | 72 // |res_id|, if it has not yet been loaded. |
| 65 virtual void PreloadResource(AndroidResourceType res_type, int res_id) = 0; | 73 virtual void PreloadResource(AndroidResourceType res_type, int res_id) = 0; |
| 66 | 74 |
| 67 // Return a handle to the CrushedSpriteResource specified by |bitmap_res_id| | 75 // Return a handle to the CrushedSpriteResource specified by |bitmap_res_id| |
| 68 // and |metadata_res_id|. If the resource has not been loaded, loading will be | 76 // and |metadata_res_id|. If the resource has not been loaded, loading will be |
| 69 // performed synchronously, blocking until the load completes. If load fails, | 77 // performed synchronously, blocking until the load completes. If load fails, |
| 70 // a null handle will be returned and it is up to the caller to react | 78 // a null handle will be returned and it is up to the caller to react |
| 71 // appropriately. | 79 // appropriately. |
| 72 virtual CrushedSpriteResource* GetCrushedSpriteResource( | 80 virtual CrushedSpriteResource* GetCrushedSpriteResource( |
| 73 int bitmap_res_id, int metadata_res_id) = 0; | 81 int bitmap_res_id, int metadata_res_id) = 0; |
| 74 | 82 |
| 75 // Convenience wrapper method. | 83 // Convenience wrapper method. |
| 76 cc::UIResourceId GetUIResourceId(AndroidResourceType res_type, int res_id) { | 84 cc::UIResourceId GetUIResourceId(AndroidResourceType res_type, int res_id) { |
| 77 Resource* resource = GetResource(res_type, res_id); | 85 Resource* resource = GetResource(res_type, res_id); |
| 78 return resource && resource->ui_resource ? resource->ui_resource->id() : 0; | 86 return resource && resource->ui_resource ? resource->ui_resource->id() : 0; |
| 79 } | 87 } |
| 80 | 88 |
| 81 protected: | 89 protected: |
| 82 virtual ~ResourceManager() {} | 90 virtual ~ResourceManager() {} |
| 83 }; | 91 }; |
| 84 | 92 |
| 85 } // namespace ui | 93 } // namespace ui |
| 86 | 94 |
| 87 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ | 95 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
| OLD | NEW |