| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/compositor_impl_android.h" | 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 : root_layer_(cc::Layer::Create()), | 119 : root_layer_(cc::Layer::Create()), |
| 120 has_transparent_background_(false), | 120 has_transparent_background_(false), |
| 121 window_(NULL), | 121 window_(NULL), |
| 122 surface_id_(0), | 122 surface_id_(0), |
| 123 client_(client), | 123 client_(client), |
| 124 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 124 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 125 DCHECK(client); | 125 DCHECK(client); |
| 126 } | 126 } |
| 127 | 127 |
| 128 CompositorImpl::~CompositorImpl() { | 128 CompositorImpl::~CompositorImpl() { |
| 129 // Clean-up any surface references. |
| 130 SetSurface(NULL); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void CompositorImpl::Composite() { | 133 void CompositorImpl::Composite() { |
| 132 if (host_.get()) | 134 if (host_.get()) |
| 133 host_->Composite(base::TimeTicks::Now()); | 135 host_->Composite(base::TimeTicks::Now()); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 138 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
| 137 root_layer_->RemoveAllChildren(); | 139 root_layer_->RemoveAllChildren(); |
| 138 root_layer_->AddChild(root_layer); | 140 root_layer_->AddChild(root_layer); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 156 tracker->SetSurfaceHandle( | 158 tracker->SetSurfaceHandle( |
| 157 surface_id_, | 159 surface_id_, |
| 158 gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_DIRECT)); | 160 gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_DIRECT)); |
| 159 SetVisible(true); | 161 SetVisible(true); |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 void CompositorImpl::SetSurface(jobject surface) { | 165 void CompositorImpl::SetSurface(jobject surface) { |
| 164 JNIEnv* env = base::android::AttachCurrentThread(); | 166 JNIEnv* env = base::android::AttachCurrentThread(); |
| 165 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); | 167 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); |
| 166 if (surface) { | 168 |
| 167 ANativeWindow* window = ANativeWindow_fromSurface(env, surface); | 169 // First, cleanup any existing surface references. |
| 170 if (surface_id_) { |
| 171 DCHECK(g_surface_map.Get().find(surface_id_) != |
| 172 g_surface_map.Get().end()); |
| 173 base::AutoLock lock(g_surface_map_lock.Get()); |
| 174 g_surface_map.Get().erase(surface_id_); |
| 175 } |
| 176 SetWindowSurface(NULL); |
| 177 |
| 178 // Now, set the new surface if we have one. |
| 179 ANativeWindow* window = NULL; |
| 180 if (surface) |
| 181 window = ANativeWindow_fromSurface(env, surface); |
| 182 if (window) { |
| 168 SetWindowSurface(window); | 183 SetWindowSurface(window); |
| 169 ANativeWindow_release(window); | 184 ANativeWindow_release(window); |
| 170 { | 185 { |
| 171 base::AutoLock lock(g_surface_map_lock.Get()); | 186 base::AutoLock lock(g_surface_map_lock.Get()); |
| 172 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); | 187 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); |
| 173 } | 188 } |
| 174 } else { | |
| 175 { | |
| 176 base::AutoLock lock(g_surface_map_lock.Get()); | |
| 177 g_surface_map.Get().erase(surface_id_); | |
| 178 } | |
| 179 SetWindowSurface(NULL); | |
| 180 } | 189 } |
| 181 } | 190 } |
| 182 | 191 |
| 183 void CompositorImpl::SetVisible(bool visible) { | 192 void CompositorImpl::SetVisible(bool visible) { |
| 184 if (!visible) { | 193 if (!visible) { |
| 185 host_.reset(); | 194 host_.reset(); |
| 186 } else if (!host_.get()) { | 195 } else if (!host_.get()) { |
| 187 cc::LayerTreeSettings settings; | 196 cc::LayerTreeSettings settings; |
| 188 settings.refresh_rate = 60.0; | 197 settings.refresh_rate = 60.0; |
| 189 settings.impl_side_painting = false; | 198 settings.impl_side_painting = false; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 455 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 447 return GL_UNSIGNED_BYTE; | 456 return GL_UNSIGNED_BYTE; |
| 448 break; | 457 break; |
| 449 case ANDROID_BITMAP_FORMAT_RGB_565: | 458 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 450 default: | 459 default: |
| 451 return GL_UNSIGNED_SHORT_5_6_5; | 460 return GL_UNSIGNED_SHORT_5_6_5; |
| 452 } | 461 } |
| 453 } | 462 } |
| 454 | 463 |
| 455 } // namespace content | 464 } // namespace content |
| OLD | NEW |