| 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_impl.h" | 5 #include "ui/android/resources/resource_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "cc/resources/scoped_ui_resource.h" | 9 #include "cc/resources/scoped_ui_resource.h" |
| 10 #include "jni/ResourceManager_jni.h" | 10 #include "jni/ResourceManager_jni.h" |
| 11 #include "ui/android/resources/ui_resource_provider.h" | 11 #include "ui/android/resources/ui_resource_provider.h" |
| 12 #include "ui/android/window_android.h" |
| 12 #include "ui/gfx/android/java_bitmap.h" | 13 #include "ui/gfx/android/java_bitmap.h" |
| 13 | 14 |
| 14 namespace ui { | 15 namespace ui { |
| 15 | 16 |
| 16 // static | 17 // static |
| 17 ResourceManagerImpl* ResourceManagerImpl::FromJavaObject(jobject jobj) { | 18 ResourceManagerImpl* ResourceManagerImpl::FromJavaObject(jobject jobj) { |
| 18 return reinterpret_cast<ResourceManagerImpl*>( | 19 return reinterpret_cast<ResourceManagerImpl*>( |
| 19 Java_ResourceManager_getNativePtr(base::android::AttachCurrentThread(), | 20 Java_ResourceManager_getNativePtr(base::android::AttachCurrentThread(), |
| 20 jobj)); | 21 jobj)); |
| 21 } | 22 } |
| 22 | 23 |
| 23 ResourceManagerImpl::ResourceManagerImpl() : host_(nullptr) { | 24 ResourceManagerImpl::ResourceManagerImpl(gfx::NativeWindow native_window) |
| 25 : ResourceManagerImpl(native_window->GetJavaDisplayContext().obj()) {} |
| 26 |
| 27 ResourceManagerImpl::ResourceManagerImpl(jobject context) : host_(nullptr) { |
| 24 JNIEnv* env = base::android::AttachCurrentThread(); | 28 JNIEnv* env = base::android::AttachCurrentThread(); |
| 25 java_obj_.Reset(env, Java_ResourceManager_create( | 29 java_obj_.Reset(env, Java_ResourceManager_create( |
| 26 env, base::android::GetApplicationContext(), | 30 env, context, reinterpret_cast<intptr_t>(this)) |
| 27 reinterpret_cast<intptr_t>(this)).obj()); | 31 .obj()); |
| 28 DCHECK(!java_obj_.is_null()); | 32 DCHECK(!java_obj_.is_null()); |
| 29 } | 33 } |
| 30 | 34 |
| 31 ResourceManagerImpl::~ResourceManagerImpl() { | 35 ResourceManagerImpl::~ResourceManagerImpl() { |
| 32 Java_ResourceManager_destroy(base::android::AttachCurrentThread(), | 36 Java_ResourceManager_destroy(base::android::AttachCurrentThread(), |
| 33 java_obj_.obj()); | 37 java_obj_.obj()); |
| 34 } | 38 } |
| 35 | 39 |
| 36 void ResourceManagerImpl::Init(cc::LayerTreeHost* host) { | 40 void ResourceManagerImpl::Init(cc::LayerTreeHost* host) { |
| 37 DCHECK(!host_); | 41 DCHECK(!host_); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 void ResourceManagerImpl::RequestResourceFromJava(AndroidResourceType res_type, | 134 void ResourceManagerImpl::RequestResourceFromJava(AndroidResourceType res_type, |
| 131 int res_id) { | 135 int res_id) { |
| 132 TRACE_EVENT2("ui", "ResourceManagerImpl::RequestResourceFromJava", | 136 TRACE_EVENT2("ui", "ResourceManagerImpl::RequestResourceFromJava", |
| 133 "resource_type", res_type, | 137 "resource_type", res_type, |
| 134 "resource_id", res_id); | 138 "resource_id", res_id); |
| 135 Java_ResourceManager_resourceRequested(base::android::AttachCurrentThread(), | 139 Java_ResourceManager_resourceRequested(base::android::AttachCurrentThread(), |
| 136 java_obj_.obj(), res_type, res_id); | 140 java_obj_.obj(), res_type, res_id); |
| 137 } | 141 } |
| 138 | 142 |
| 139 } // namespace ui | 143 } // namespace ui |
| OLD | NEW |