Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: ui/android/resources/resource_manager.h

Issue 2746483003: ui/android: Fix Resource meta-data sharing with ResourceManager. (Closed)
Patch Set: jni Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/android/resources/resource_factory.cc ('k') | ui/android/resources/resource_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <unordered_map> 9 #include <unordered_map>
10 #include <unordered_set> 10 #include <unordered_set>
11 11
12 #include "base/android/jni_android.h" 12 #include "base/android/jni_android.h"
13 #include "cc/resources/scoped_ui_resource.h" 13 #include "cc/resources/scoped_ui_resource.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/android/resources/crushed_sprite_resource.h" 15 #include "ui/android/resources/crushed_sprite_resource.h"
16 #include "ui/android/resources/resource.h"
16 #include "ui/android/ui_android_export.h" 17 #include "ui/android/ui_android_export.h"
17 #include "ui/gfx/geometry/insets_f.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/size.h"
20 18
21 namespace ui { 19 namespace ui {
22 20
23 // A Java counterpart will be generated for this enum. 21 // A Java counterpart will be generated for this enum.
24 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.resources 22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.resources
25 enum AndroidResourceType { 23 enum AndroidResourceType {
26 ANDROID_RESOURCE_TYPE_STATIC = 0, 24 ANDROID_RESOURCE_TYPE_STATIC = 0,
27 ANDROID_RESOURCE_TYPE_DYNAMIC, 25 ANDROID_RESOURCE_TYPE_DYNAMIC,
28 ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP, 26 ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP,
29 ANDROID_RESOURCE_TYPE_SYSTEM, 27 ANDROID_RESOURCE_TYPE_SYSTEM,
30 ANDROID_RESOURCE_TYPE_CRUSHED_SPRITE, 28 ANDROID_RESOURCE_TYPE_CRUSHED_SPRITE,
31 29
32 ANDROID_RESOURCE_TYPE_COUNT, 30 ANDROID_RESOURCE_TYPE_COUNT,
33 ANDROID_RESOURCE_TYPE_FIRST = ANDROID_RESOURCE_TYPE_STATIC, 31 ANDROID_RESOURCE_TYPE_FIRST = ANDROID_RESOURCE_TYPE_STATIC,
34 ANDROID_RESOURCE_TYPE_LAST = ANDROID_RESOURCE_TYPE_CRUSHED_SPRITE, 32 ANDROID_RESOURCE_TYPE_LAST = ANDROID_RESOURCE_TYPE_CRUSHED_SPRITE,
35 }; 33 };
36 34
37 // The ResourceManager serves as a cache for resources obtained through Android 35 // The ResourceManager serves as a cache for resources obtained through Android
38 // APIs and consumed by the compositor. 36 // APIs and consumed by the compositor.
39 class UI_ANDROID_EXPORT ResourceManager { 37 class UI_ANDROID_EXPORT ResourceManager {
40 public: 38 public:
41 struct Resource {
42 public:
43 Resource();
44 ~Resource();
45 gfx::Rect Border(const gfx::Size& bounds) const;
46 gfx::Rect Border(const gfx::Size& bounds, const gfx::InsetsF& scale) const;
47 size_t EstimateMemoryUsage() const;
48
49 std::unique_ptr<cc::ScopedUIResource> ui_resource;
50 gfx::Size size;
51 gfx::Rect padding;
52 gfx::Rect aperture;
53 };
54
55 // Obtain a handle to the Java ResourceManager counterpart. 39 // Obtain a handle to the Java ResourceManager counterpart.
56 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaObject() = 0; 40 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaObject() = 0;
57 41
58 // Return a handle to the resource specified by |res_type| and |res_id|. 42 // Return a handle to the resource specified by |res_type| and |res_id|.
59 // If the resource has not been loaded, loading will be performed 43 // If the resource has not been loaded, loading will be performed
60 // synchronously, blocking until the load completes. 44 // synchronously, blocking until the load completes.
61 // If load fails, a null handle will be returned and it is up to the caller 45 // If load fails, a null handle will be returned and it is up to the caller
62 // to react appropriately. 46 // to react appropriately.
63 virtual Resource* GetResource(AndroidResourceType res_type, int res_id) = 0; 47 virtual Resource* GetResource(AndroidResourceType res_type, int res_id) = 0;
64 48
(...skipping 15 matching lines...) Expand all
80 // and |metadata_res_id|. If the resource has not been loaded, loading will be 64 // and |metadata_res_id|. If the resource has not been loaded, loading will be
81 // performed synchronously, blocking until the load completes. If load fails, 65 // performed synchronously, blocking until the load completes. If load fails,
82 // a null handle will be returned and it is up to the caller to react 66 // a null handle will be returned and it is up to the caller to react
83 // appropriately. 67 // appropriately.
84 virtual CrushedSpriteResource* GetCrushedSpriteResource( 68 virtual CrushedSpriteResource* GetCrushedSpriteResource(
85 int bitmap_res_id, int metadata_res_id) = 0; 69 int bitmap_res_id, int metadata_res_id) = 0;
86 70
87 // Convenience wrapper method. 71 // Convenience wrapper method.
88 cc::UIResourceId GetUIResourceId(AndroidResourceType res_type, int res_id) { 72 cc::UIResourceId GetUIResourceId(AndroidResourceType res_type, int res_id) {
89 Resource* resource = GetResource(res_type, res_id); 73 Resource* resource = GetResource(res_type, res_id);
90 return resource && resource->ui_resource ? resource->ui_resource->id() : 0; 74 return resource && resource->ui_resource() ? resource->ui_resource()->id()
75 : 0;
91 } 76 }
92 77
93 protected: 78 protected:
94 virtual ~ResourceManager() {} 79 virtual ~ResourceManager() {}
95 }; 80 };
96 81
97 } // namespace ui 82 } // namespace ui
98 83
99 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ 84 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_
OLDNEW
« no previous file with comments | « ui/android/resources/resource_factory.cc ('k') | ui/android/resources/resource_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698