Index: content/browser/android/resource_manager_impl.cc |
diff --git a/content/browser/android/resource_manager_impl.cc b/content/browser/android/resource_manager_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a45537d7cb15f1c59843e3882be935bcb753ac87 |
--- /dev/null |
+++ b/content/browser/android/resource_manager_impl.cc |
@@ -0,0 +1,137 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/android/resource_manager_impl.h" |
+ |
+#include "content/browser/android/ui_resource_android_impl.h" |
+#include "content/public/browser/android/ui_resource_provider.h" |
+#include "jni/ResourceManager_jni.h" |
+#include "ui/gfx/android/java_bitmap.h" |
+ |
+namespace content { |
+ |
+ResourceManager::Resource::Resource() { |
+} |
+ |
+ResourceManager::Resource::~Resource() { |
+} |
+ |
+gfx::Rect ResourceManager::Resource::Border(const gfx::Size& bounds) { |
+ return Border(bounds, gfx::InsetsF(1.f, 1.f, 1.f, 1.f)); |
+} |
+ |
+gfx::Rect ResourceManager::Resource::Border(const gfx::Size& bounds, |
+ const gfx::InsetsF& scale) { |
+ // Calculate whether or not we need to scale down the border if the bounds of |
+ // the layer are going to be smaller than the aperture padding. |
+ float x_scale = std::min((float)bounds.width() / size.width(), 1.f); |
+ float y_scale = std::min((float)bounds.height() / size.height(), 1.f); |
+ |
+ float left_scale = std::min(x_scale * scale.left(), 1.f); |
+ float right_scale = std::min(x_scale * scale.right(), 1.f); |
+ float top_scale = std::min(y_scale * scale.top(), 1.f); |
+ float bottom_scale = std::min(y_scale * scale.bottom(), 1.f); |
+ |
+ return gfx::Rect(aperture.x() * left_scale, aperture.y() * top_scale, |
David Trainor- moved to gerrit
2014/11/18 18:53:53
New line for the second parameter?
Jaekyun Seok (inactive)
2014/11/18 23:34:02
This is a result from "git cl format".
|
+ (size.width() - aperture.width()) * right_scale, |
+ (size.height() - aperture.height()) * bottom_scale); |
+} |
+ |
+// static |
+ResourceManagerImpl* ResourceManagerImpl::FromJavaObject(jobject jobj) { |
+ return reinterpret_cast<ResourceManagerImpl*>( |
+ Java_ResourceManager_getNativePtr(base::android::AttachCurrentThread(), |
+ jobj)); |
+} |
+ |
+ResourceManagerImpl::ResourceManagerImpl( |
+ content::UIResourceProvider* ui_resource_provider) |
+ : ui_resource_provider_(ui_resource_provider) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ java_obj_.Reset(env, Java_ResourceManager_create( |
+ env, base::android::GetApplicationContext(), |
+ reinterpret_cast<intptr_t>(this)).obj()); |
+ DCHECK(!java_obj_.is_null()); |
+} |
+ |
+ResourceManagerImpl::~ResourceManagerImpl() { |
+ Java_ResourceManager_destroy(base::android::AttachCurrentThread(), |
+ java_obj_.obj()); |
+} |
+ |
+base::android::ScopedJavaLocalRef<jobject> ResourceManagerImpl::GetJavaObject( |
+ JNIEnv* env) { |
+ return base::android::ScopedJavaLocalRef<jobject>(java_obj_); |
+} |
+ |
+ResourceManager::Resource* ResourceManagerImpl::GetResource( |
+ ResourceKind res_type, |
+ int res_id) { |
+ DCHECK_GE(res_type, RESOURCE_KIND_FIRST); |
+ DCHECK_LE(res_type, RESOURCE_KIND_LAST); |
+ |
+ Resource* resource = resources_[res_type].Lookup(res_id); |
+ |
+ if (!resource || res_type == RESOURCE_KIND_DYNAMIC || |
+ res_type == RESOURCE_KIND_DYNAMIC_BITMAP) { |
+ Java_ResourceManager_resourceRequested(base::android::AttachCurrentThread(), |
+ java_obj_.obj(), res_type, res_id); |
+ resource = resources_[res_type].Lookup(res_id); |
+ } |
+ |
+ return resource; |
+} |
+ |
+void ResourceManagerImpl::PreloadResource(ResourceKind res_type, int res_id) { |
+ DCHECK_GE(res_type, RESOURCE_KIND_FIRST); |
+ DCHECK_LE(res_type, RESOURCE_KIND_LAST); |
+ |
+ // Don't send out a query if the resource is already loaded. |
+ if (resources_[res_type].Lookup(res_id)) |
+ return; |
+ |
+ Java_ResourceManager_preloadResource(base::android::AttachCurrentThread(), |
+ java_obj_.obj(), res_type, res_id); |
+} |
+ |
+void ResourceManagerImpl::OnResourceReady(JNIEnv* env, |
+ jobject jobj, |
+ jint res_type, |
+ jint res_id, |
+ jobject bitmap, |
+ jint padding_left, |
+ jint padding_top, |
+ jint padding_right, |
+ jint padding_bottom, |
+ jint aperture_left, |
+ jint aperture_top, |
+ jint aperture_right, |
+ jint aperture_bottom) { |
+ DCHECK_GE(res_type, RESOURCE_KIND_FIRST); |
+ DCHECK_LE(res_type, RESOURCE_KIND_LAST); |
+ |
+ Resource* resource = resources_[res_type].Lookup(res_id); |
+ if (!resource) { |
+ resource = new Resource(); |
+ resources_[res_type].AddWithID(resource, res_id); |
+ } |
+ |
+ gfx::JavaBitmap jbitmap(bitmap); |
+ resource->size = jbitmap.size(); |
+ resource->padding.SetRect(padding_left, padding_top, |
+ padding_right - padding_left, |
+ padding_bottom - padding_top); |
+ resource->aperture.SetRect(aperture_left, aperture_top, |
+ aperture_right - aperture_left, |
+ aperture_bottom - aperture_top); |
+ resource->ui_resource = UIResourceAndroidImpl::CreateFromJavaBitmap( |
+ ui_resource_provider_, jbitmap); |
+} |
+ |
+// static |
+bool ResourceManagerImpl::RegisterResourceManager(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+} // namespace content |