Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 #include "content/common/gpu/client/context_provider_command_buffer.h" | 31 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 32 #include "content/common/gpu/client/gl_helper.h" | 32 #include "content/common/gpu/client/gl_helper.h" |
| 33 #include "content/common/gpu/client/gpu_channel_host.h" | 33 #include "content/common/gpu/client/gpu_channel_host.h" |
| 34 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 34 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 35 #include "content/common/gpu/gpu_process_launch_causes.h" | 35 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 36 #include "content/public/browser/android/compositor_client.h" | 36 #include "content/public/browser/android/compositor_client.h" |
| 37 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
| 38 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 38 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 39 #include "third_party/khronos/GLES2/gl2.h" | 39 #include "third_party/khronos/GLES2/gl2.h" |
| 40 #include "third_party/khronos/GLES2/gl2ext.h" | 40 #include "third_party/khronos/GLES2/gl2ext.h" |
| 41 #include "ui/base/android/window_android.h" | |
| 41 #include "ui/gfx/android/device_display_info.h" | 42 #include "ui/gfx/android/device_display_info.h" |
| 42 #include "ui/gfx/android/java_bitmap.h" | 43 #include "ui/gfx/android/java_bitmap.h" |
| 43 #include "ui/gfx/frame_time.h" | 44 #include "ui/gfx/frame_time.h" |
| 44 #include "webkit/common/gpu/context_provider_in_process.h" | 45 #include "webkit/common/gpu/context_provider_in_process.h" |
| 45 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" | 46 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" |
| 46 | 47 |
| 47 namespace gfx { | 48 namespace gfx { |
| 48 class JavaBitmap; | 49 class JavaBitmap; |
| 49 } | 50 } |
| 50 | 51 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 97 |
| 97 namespace content { | 98 namespace content { |
| 98 | 99 |
| 99 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> > | 100 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> > |
| 100 SurfaceMap; | 101 SurfaceMap; |
| 101 static base::LazyInstance<SurfaceMap> | 102 static base::LazyInstance<SurfaceMap> |
| 102 g_surface_map = LAZY_INSTANCE_INITIALIZER; | 103 g_surface_map = LAZY_INSTANCE_INITIALIZER; |
| 103 static base::LazyInstance<base::Lock> g_surface_map_lock; | 104 static base::LazyInstance<base::Lock> g_surface_map_lock; |
| 104 | 105 |
| 105 // static | 106 // static |
| 106 Compositor* Compositor::Create(CompositorClient* client) { | 107 Compositor* Compositor::Create(CompositorClient* client, |
| 107 return client ? new CompositorImpl(client) : NULL; | 108 gfx::NativeWindow root_window) { |
| 109 return client ? new CompositorImpl(client, root_window) : NULL; | |
| 108 } | 110 } |
| 109 | 111 |
| 110 // static | 112 // static |
| 111 void Compositor::Initialize() { | 113 void Compositor::Initialize() { |
| 112 DCHECK(!CompositorImpl::IsInitialized()); | 114 DCHECK(!CompositorImpl::IsInitialized()); |
| 113 g_initialized = true; | 115 g_initialized = true; |
| 114 } | 116 } |
| 115 | 117 |
| 116 // static | 118 // static |
| 117 bool CompositorImpl::IsInitialized() { | 119 bool CompositorImpl::IsInitialized() { |
| 118 return g_initialized; | 120 return g_initialized; |
| 119 } | 121 } |
| 120 | 122 |
| 121 // static | 123 // static |
| 122 jobject CompositorImpl::GetSurface(int surface_id) { | 124 jobject CompositorImpl::GetSurface(int surface_id) { |
| 123 base::AutoLock lock(g_surface_map_lock.Get()); | 125 base::AutoLock lock(g_surface_map_lock.Get()); |
| 124 SurfaceMap* surfaces = g_surface_map.Pointer(); | 126 SurfaceMap* surfaces = g_surface_map.Pointer(); |
| 125 SurfaceMap::iterator it = surfaces->find(surface_id); | 127 SurfaceMap::iterator it = surfaces->find(surface_id); |
| 126 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj(); | 128 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj(); |
| 127 | 129 |
| 128 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id; | 130 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id; |
| 129 return jsurface; | 131 return jsurface; |
| 130 } | 132 } |
| 131 | 133 |
| 132 CompositorImpl::CompositorImpl(CompositorClient* client) | 134 CompositorImpl::CompositorImpl(CompositorClient* client, |
| 135 gfx::NativeWindow root_window) | |
| 133 : root_layer_(cc::Layer::Create()), | 136 : root_layer_(cc::Layer::Create()), |
| 134 has_transparent_background_(false), | 137 has_transparent_background_(false), |
| 135 window_(NULL), | 138 window_(NULL), |
| 136 surface_id_(0), | 139 surface_id_(0), |
| 137 client_(client) { | 140 client_(client), |
| 141 root_window_(root_window) { | |
| 138 DCHECK(client); | 142 DCHECK(client); |
| 143 DCHECK(root_window); | |
| 139 ImageTransportFactoryAndroid::AddObserver(this); | 144 ImageTransportFactoryAndroid::AddObserver(this); |
| 145 root_window->AttachCompositor(); | |
| 140 } | 146 } |
| 141 | 147 |
| 142 CompositorImpl::~CompositorImpl() { | 148 CompositorImpl::~CompositorImpl() { |
| 149 root_window_->DetachCompositor(); | |
| 143 ImageTransportFactoryAndroid::RemoveObserver(this); | 150 ImageTransportFactoryAndroid::RemoveObserver(this); |
| 144 // Clean-up any surface references. | 151 // Clean-up any surface references. |
| 145 SetSurface(NULL); | 152 SetSurface(NULL); |
| 146 } | 153 } |
| 147 | 154 |
| 148 void CompositorImpl::Composite() { | 155 void CompositorImpl::Composite() { |
| 149 if (host_) | 156 if (host_) |
| 150 host_->Composite(gfx::FrameTime::Now()); | 157 host_->Composite(gfx::FrameTime::Now()); |
| 151 } | 158 } |
| 152 | 159 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 break; | 481 break; |
| 475 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 482 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 476 return GL_UNSIGNED_BYTE; | 483 return GL_UNSIGNED_BYTE; |
| 477 break; | 484 break; |
| 478 case ANDROID_BITMAP_FORMAT_RGB_565: | 485 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 479 default: | 486 default: |
| 480 return GL_UNSIGNED_SHORT_5_6_5; | 487 return GL_UNSIGNED_SHORT_5_6_5; |
| 481 } | 488 } |
| 482 } | 489 } |
| 483 | 490 |
| 491 void CompositorImpl::DidCommit() { | |
| 492 DCHECK(root_window_); | |
|
no sievers
2013/11/15 22:56:19
nit: we already DCHECK() in the constructor
powei
2013/11/18 19:29:59
Done.
| |
| 493 root_window_->OnCompositingDidCommit(); | |
| 494 } | |
| 495 | |
| 484 } // namespace content | 496 } // namespace content |
| OLD | NEW |