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
3 // found in the LICENSE file.
5 #ifndef UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_
6 #define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_
8 #include "base/android/jni_android.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/resources/ui_resource_client.h"
11 #include "ui/android/resources/ui_resource_android.h"
12 #include "ui/android/ui_android_export.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h"
18 class UIResourceAndroid
;
19 class UIResourceProvider
;
21 // A Java counterpart will be generated for this enum.
22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.resources
23 enum AndroidResourceType
{
24 ANDROID_RESOURCE_TYPE_STATIC
= 0,
25 ANDROID_RESOURCE_TYPE_DYNAMIC
,
26 ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP
,
27 ANDROID_RESOURCE_TYPE_SYSTEM
,
29 ANDROID_RESOURCE_TYPE_COUNT
,
30 ANDROID_RESOURCE_TYPE_FIRST
= ANDROID_RESOURCE_TYPE_STATIC
,
31 ANDROID_RESOURCE_TYPE_LAST
= ANDROID_RESOURCE_TYPE_SYSTEM
,
34 // The ResourceManager serves as a cache for resources obtained through Android
35 // APIs and consumed by the compositor.
36 class UI_ANDROID_EXPORT ResourceManager
{
42 gfx::Rect
Border(const gfx::Size
& bounds
) const;
43 gfx::Rect
Border(const gfx::Size
& bounds
, const gfx::InsetsF
& scale
) const;
45 scoped_ptr
<UIResourceAndroid
> ui_resource
;
51 // Obtain a handle to the Java ResourceManager counterpart.
52 virtual base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject() = 0;
54 // Return a handle to the resource specified by |res_type| and |res_id|.
55 // If the resource has not been loaded, loading will be performed
56 // synchronously, blocking until the load completes.
57 // If load fails, a null handle will be returned and it is up to the caller
58 // to react appropriately.
59 virtual Resource
* GetResource(AndroidResourceType res_type
, int res_id
) = 0;
61 // Trigger asynchronous loading of the resource specified by |res_type| and
62 // |res_id|, if it has not yet been loaded.
63 virtual void PreloadResource(AndroidResourceType res_type
, int res_id
) = 0;
65 // Convenience wrapper method.
66 cc::UIResourceId
GetUIResourceId(AndroidResourceType res_type
, int res_id
) {
67 Resource
* resource
= GetResource(res_type
, res_id
);
68 return resource
&& resource
->ui_resource
? resource
->ui_resource
->id() : 0;
72 virtual ~ResourceManager() {}
77 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_