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/insets_f.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/size.h"
19 class UIResourceAndroid
;
20 class UIResourceProvider
;
22 // A Java counterpart will be generated for this enum.
23 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.resources
24 enum AndroidResourceType
{
25 ANDROID_RESOURCE_TYPE_STATIC
= 0,
26 ANDROID_RESOURCE_TYPE_DYNAMIC
,
27 ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP
,
28 ANDROID_RESOURCE_TYPE_SYSTEM
,
30 ANDROID_RESOURCE_TYPE_COUNT
,
31 ANDROID_RESOURCE_TYPE_FIRST
= ANDROID_RESOURCE_TYPE_STATIC
,
32 ANDROID_RESOURCE_TYPE_LAST
= ANDROID_RESOURCE_TYPE_SYSTEM
,
35 // The ResourceManager serves as a cache for resources obtained through Android
36 // APIs and consumed by the compositor.
37 class UI_ANDROID_EXPORT ResourceManager
{
43 gfx::Rect
Border(const gfx::Size
& bounds
) const;
44 gfx::Rect
Border(const gfx::Size
& bounds
, const gfx::InsetsF
& scale
) const;
46 scoped_ptr
<UIResourceAndroid
> ui_resource
;
52 // Obtain a handle to the Java ResourceManager counterpart.
53 virtual base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject() = 0;
55 // Return a handle to the resource specified by |res_type| and |res_id|.
56 // If the resource has not been loaded, loading will be performed
57 // synchronously, blocking until the load completes.
58 // If load fails, a null handle will be returned and it is up to the caller
59 // to react appropriately.
60 virtual Resource
* GetResource(AndroidResourceType res_type
, int res_id
) = 0;
62 // Trigger asynchronous loading of the resource specified by |res_type| and
63 // |res_id|, if it has not yet been loaded.
64 virtual void PreloadResource(AndroidResourceType res_type
, int res_id
) = 0;
66 // Convenience wrapper method.
67 cc::UIResourceId
GetUIResourceId(AndroidResourceType res_type
, int res_id
) {
68 Resource
* resource
= GetResource(res_type
, res_id
);
69 return resource
&& resource
->ui_resource
? resource
->ui_resource
->id() : 0;
73 virtual ~ResourceManager() {}
78 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_