| 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 #include "ui/android/resources/resource_manager.h" | 5 #include "ui/android/resources/resource_manager.h" |
| 6 | 6 |
| 7 #include "content/public/browser/android/ui_resource_provider.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "jni/ResourceManager_jni.h" | 8 #include "jni/ResourceManager_jni.h" |
| 9 #include "ui/android/resources/ui_resource_android.h" | 9 #include "ui/android/resources/ui_resource_android.h" |
| 10 #include "ui/android/resources/ui_resource_provider.h" |
| 10 #include "ui/gfx/android/java_bitmap.h" | 11 #include "ui/gfx/android/java_bitmap.h" |
| 11 #include "ui/gfx/geometry/insets_f.h" | 12 #include "ui/gfx/geometry/insets_f.h" |
| 12 | 13 |
| 13 namespace ui { | 14 namespace ui { |
| 14 | 15 |
| 15 ResourceManager::Resource::Resource() { | 16 ResourceManager::Resource::Resource() { |
| 16 } | 17 } |
| 17 | 18 |
| 18 ResourceManager::Resource::~Resource() { | 19 ResourceManager::Resource::~Resource() { |
| 19 } | 20 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 (size.width() - aperture.width()) * right_scale, | 39 (size.width() - aperture.width()) * right_scale, |
| 39 (size.height() - aperture.height()) * bottom_scale); | 40 (size.height() - aperture.height()) * bottom_scale); |
| 40 } | 41 } |
| 41 | 42 |
| 42 // static | 43 // static |
| 43 ResourceManager* ResourceManager::FromJavaObject(jobject jobj) { | 44 ResourceManager* ResourceManager::FromJavaObject(jobject jobj) { |
| 44 return reinterpret_cast<ResourceManager*>(Java_ResourceManager_getNativePtr( | 45 return reinterpret_cast<ResourceManager*>(Java_ResourceManager_getNativePtr( |
| 45 base::android::AttachCurrentThread(), jobj)); | 46 base::android::AttachCurrentThread(), jobj)); |
| 46 } | 47 } |
| 47 | 48 |
| 48 ResourceManager::ResourceManager( | 49 ResourceManager::ResourceManager(ui::UIResourceProvider* ui_resource_provider) |
| 49 content::UIResourceProvider* ui_resource_provider) | |
| 50 : ui_resource_provider_(ui_resource_provider) { | 50 : ui_resource_provider_(ui_resource_provider) { |
| 51 JNIEnv* env = base::android::AttachCurrentThread(); | 51 JNIEnv* env = base::android::AttachCurrentThread(); |
| 52 java_obj_.Reset(env, Java_ResourceManager_create( | 52 java_obj_.Reset(env, Java_ResourceManager_create( |
| 53 env, base::android::GetApplicationContext(), | 53 env, base::android::GetApplicationContext(), |
| 54 reinterpret_cast<intptr_t>(this)).obj()); | 54 reinterpret_cast<intptr_t>(this)).obj()); |
| 55 DCHECK(!java_obj_.is_null()); | 55 DCHECK(!java_obj_.is_null()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 ResourceManager::~ResourceManager() { | 58 ResourceManager::~ResourceManager() { |
| 59 Java_ResourceManager_destroy(base::android::AttachCurrentThread(), | 59 Java_ResourceManager_destroy(base::android::AttachCurrentThread(), |
| 60 java_obj_.obj()); | 60 java_obj_.obj()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 base::android::ScopedJavaLocalRef<jobject> ResourceManager::GetJavaObject( | 63 base::android::ScopedJavaLocalRef<jobject> ResourceManager::GetJavaObject( |
| 64 JNIEnv* env) { | 64 JNIEnv* env) { |
| 65 return base::android::ScopedJavaLocalRef<jobject>(java_obj_); | 65 return base::android::ScopedJavaLocalRef<jobject>(java_obj_); |
| 66 } | 66 } |
| 67 | 67 |
| 68 cc::UIResourceId ResourceManager::GetUIResourceId(AndroidResourceType res_type, |
| 69 int res_id) { |
| 70 ui::ResourceManager::Resource* resource = GetResource(res_type, res_id); |
| 71 if (!resource->ui_resource) |
| 72 return 0; |
| 73 return resource->ui_resource->id(); |
| 74 } |
| 75 |
| 68 ResourceManager::Resource* ResourceManager::GetResource( | 76 ResourceManager::Resource* ResourceManager::GetResource( |
| 69 AndroidResourceType res_type, | 77 AndroidResourceType res_type, |
| 70 int res_id) { | 78 int res_id) { |
| 71 DCHECK_GE(res_type, ANDROID_RESOURCE_TYPE_FIRST); | 79 DCHECK_GE(res_type, ANDROID_RESOURCE_TYPE_FIRST); |
| 72 DCHECK_LE(res_type, ANDROID_RESOURCE_TYPE_LAST); | 80 DCHECK_LE(res_type, ANDROID_RESOURCE_TYPE_LAST); |
| 73 | 81 |
| 74 Resource* resource = resources_[res_type].Lookup(res_id); | 82 Resource* resource = resources_[res_type].Lookup(res_id); |
| 75 | 83 |
| 76 if (!resource || res_type == ANDROID_RESOURCE_TYPE_DYNAMIC || | 84 if (!resource || res_type == ANDROID_RESOURCE_TYPE_DYNAMIC || |
| 77 res_type == ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP) { | 85 res_type == ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP) { |
| 78 Java_ResourceManager_resourceRequested(base::android::AttachCurrentThread(), | 86 RequestResourceFromJava(res_type, res_id); |
| 79 java_obj_.obj(), res_type, res_id); | |
| 80 resource = resources_[res_type].Lookup(res_id); | 87 resource = resources_[res_type].Lookup(res_id); |
| 81 } | 88 } |
| 82 | 89 |
| 83 return resource; | 90 return resource; |
| 84 } | 91 } |
| 85 | 92 |
| 86 void ResourceManager::PreloadResource(AndroidResourceType res_type, | 93 void ResourceManager::PreloadResource(AndroidResourceType res_type, |
| 87 int res_id) { | 94 int res_id) { |
| 88 DCHECK_GE(res_type, ANDROID_RESOURCE_TYPE_FIRST); | 95 DCHECK_GE(res_type, ANDROID_RESOURCE_TYPE_FIRST); |
| 89 DCHECK_LE(res_type, ANDROID_RESOURCE_TYPE_LAST); | 96 DCHECK_LE(res_type, ANDROID_RESOURCE_TYPE_LAST); |
| 90 | 97 |
| 91 // Don't send out a query if the resource is already loaded. | 98 // Don't send out a query if the resource is already loaded. |
| 92 if (resources_[res_type].Lookup(res_id)) | 99 if (resources_[res_type].Lookup(res_id)) |
| 93 return; | 100 return; |
| 94 | 101 |
| 95 Java_ResourceManager_preloadResource(base::android::AttachCurrentThread(), | 102 PreloadResourceFromJava(res_type, res_id); |
| 96 java_obj_.obj(), res_type, res_id); | |
| 97 } | 103 } |
| 98 | 104 |
| 99 void ResourceManager::OnResourceReady(JNIEnv* env, | 105 void ResourceManager::OnResourceReady(JNIEnv* env, |
| 100 jobject jobj, | 106 jobject jobj, |
| 101 jint res_type, | 107 jint res_type, |
| 102 jint res_id, | 108 jint res_id, |
| 103 jobject bitmap, | 109 jobject bitmap, |
| 104 jint padding_left, | 110 jint padding_left, |
| 105 jint padding_top, | 111 jint padding_top, |
| 106 jint padding_right, | 112 jint padding_right, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 128 aperture_bottom - aperture_top); | 134 aperture_bottom - aperture_top); |
| 129 resource->ui_resource = | 135 resource->ui_resource = |
| 130 UIResourceAndroid::CreateFromJavaBitmap(ui_resource_provider_, jbitmap); | 136 UIResourceAndroid::CreateFromJavaBitmap(ui_resource_provider_, jbitmap); |
| 131 } | 137 } |
| 132 | 138 |
| 133 // static | 139 // static |
| 134 bool ResourceManager::RegisterResourceManager(JNIEnv* env) { | 140 bool ResourceManager::RegisterResourceManager(JNIEnv* env) { |
| 135 return RegisterNativesImpl(env); | 141 return RegisterNativesImpl(env); |
| 136 } | 142 } |
| 137 | 143 |
| 144 void ResourceManager::PreloadResourceFromJava(AndroidResourceType res_type, |
| 145 int res_id) { |
| 146 Java_ResourceManager_preloadResource(base::android::AttachCurrentThread(), |
| 147 java_obj_.obj(), res_type, res_id); |
| 148 } |
| 149 |
| 150 void ResourceManager::RequestResourceFromJava(AndroidResourceType res_type, |
| 151 int res_id) { |
| 152 Java_ResourceManager_resourceRequested(base::android::AttachCurrentThread(), |
| 153 java_obj_.obj(), res_type, res_id); |
| 154 } |
| 155 |
| 138 } // namespace ui | 156 } // namespace ui |
| OLD | NEW |