| 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 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "content/common/gpu/gpu_process_launch_causes.h" | 37 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 38 #include "content/common/host_shared_bitmap_manager.h" | 38 #include "content/common/host_shared_bitmap_manager.h" |
| 39 #include "content/public/browser/android/compositor_client.h" | 39 #include "content/public/browser/android/compositor_client.h" |
| 40 #include "gpu/command_buffer/client/gles2_interface.h" | 40 #include "gpu/command_buffer/client/gles2_interface.h" |
| 41 #include "third_party/khronos/GLES2/gl2.h" | 41 #include "third_party/khronos/GLES2/gl2.h" |
| 42 #include "third_party/khronos/GLES2/gl2ext.h" | 42 #include "third_party/khronos/GLES2/gl2ext.h" |
| 43 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 43 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 44 #include "ui/base/android/window_android.h" | 44 #include "ui/base/android/window_android.h" |
| 45 #include "ui/gfx/android/device_display_info.h" | 45 #include "ui/gfx/android/device_display_info.h" |
| 46 #include "ui/gfx/frame_time.h" | 46 #include "ui/gfx/frame_time.h" |
| 47 #include "ui/gl/android/surface_texture.h" | |
| 48 #include "ui/gl/android/surface_texture_tracker.h" | |
| 49 #include "webkit/common/gpu/context_provider_in_process.h" | 47 #include "webkit/common/gpu/context_provider_in_process.h" |
| 50 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 48 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
| 51 | 49 |
| 52 namespace { | 50 namespace { |
| 53 | 51 |
| 54 const unsigned int kMaxSwapBuffers = 2U; | 52 const unsigned int kMaxSwapBuffers = 2U; |
| 55 | 53 |
| 56 // Used to override capabilities_.adjust_deadline_for_parent to false | 54 // Used to override capabilities_.adjust_deadline_for_parent to false |
| 57 class OutputSurfaceWithoutParent : public cc::OutputSurface { | 55 class OutputSurfaceWithoutParent : public cc::OutputSurface { |
| 58 public: | 56 public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 compositor_impl_, | 90 compositor_impl_, |
| 93 context_provider_->ContextCapabilities().gpu)); | 91 context_provider_->ContextCapabilities().gpu)); |
| 94 | 92 |
| 95 return true; | 93 return true; |
| 96 } | 94 } |
| 97 | 95 |
| 98 scoped_refptr<base::MessageLoopProxy> main_thread_; | 96 scoped_refptr<base::MessageLoopProxy> main_thread_; |
| 99 base::WeakPtr<content::CompositorImpl> compositor_impl_; | 97 base::WeakPtr<content::CompositorImpl> compositor_impl_; |
| 100 }; | 98 }; |
| 101 | 99 |
| 102 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker { | |
| 103 public: | |
| 104 SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) { | |
| 105 thread_checker_.DetachFromThread(); | |
| 106 } | |
| 107 | |
| 108 // Overridden from gfx::SurfaceTextureTracker: | |
| 109 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture( | |
| 110 int primary_id, | |
| 111 int secondary_id) OVERRIDE { | |
| 112 base::AutoLock lock(surface_textures_lock_); | |
| 113 SurfaceTextureMapKey key(primary_id, secondary_id); | |
| 114 SurfaceTextureMap::iterator it = surface_textures_.find(key); | |
| 115 if (it == surface_textures_.end()) | |
| 116 return scoped_refptr<gfx::SurfaceTexture>(); | |
| 117 scoped_refptr<gfx::SurfaceTexture> surface_texture = it->second; | |
| 118 surface_textures_.erase(it); | |
| 119 return surface_texture; | |
| 120 } | |
| 121 | |
| 122 int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture, | |
| 123 int child_process_id) { | |
| 124 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 125 int surface_texture_id = next_surface_texture_id_++; | |
| 126 if (next_surface_texture_id_ == INT_MAX) | |
| 127 next_surface_texture_id_ = 1; | |
| 128 | |
| 129 base::AutoLock lock(surface_textures_lock_); | |
| 130 SurfaceTextureMapKey key(surface_texture_id, child_process_id); | |
| 131 DCHECK(surface_textures_.find(key) == surface_textures_.end()); | |
| 132 surface_textures_[key] = surface_texture; | |
| 133 content::RegisterChildProcessSurfaceTexture( | |
| 134 surface_texture_id, | |
| 135 child_process_id, | |
| 136 surface_texture->j_surface_texture().obj()); | |
| 137 return surface_texture_id; | |
| 138 } | |
| 139 | |
| 140 void RemoveAllSurfaceTextures(int child_process_id) { | |
| 141 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 142 base::AutoLock lock(surface_textures_lock_); | |
| 143 SurfaceTextureMap::iterator it = surface_textures_.begin(); | |
| 144 while (it != surface_textures_.end()) { | |
| 145 if (it->first.second == child_process_id) { | |
| 146 content::UnregisterChildProcessSurfaceTexture(it->first.first, | |
| 147 it->first.second); | |
| 148 surface_textures_.erase(it++); | |
| 149 } else { | |
| 150 ++it; | |
| 151 } | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 private: | |
| 156 typedef std::pair<int, int> SurfaceTextureMapKey; | |
| 157 typedef base::hash_map<SurfaceTextureMapKey, | |
| 158 scoped_refptr<gfx::SurfaceTexture> > | |
| 159 SurfaceTextureMap; | |
| 160 SurfaceTextureMap surface_textures_; | |
| 161 mutable base::Lock surface_textures_lock_; | |
| 162 int next_surface_texture_id_; | |
| 163 base::ThreadChecker thread_checker_; | |
| 164 }; | |
| 165 base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker = | |
| 166 LAZY_INSTANCE_INITIALIZER; | |
| 167 | |
| 168 static bool g_initialized = false; | 100 static bool g_initialized = false; |
| 169 | 101 |
| 170 } // anonymous namespace | 102 } // anonymous namespace |
| 171 | 103 |
| 172 namespace content { | 104 namespace content { |
| 173 | 105 |
| 174 // static | 106 // static |
| 175 Compositor* Compositor::Create(CompositorClient* client, | 107 Compositor* Compositor::Create(CompositorClient* client, |
| 176 gfx::NativeWindow root_window) { | 108 gfx::NativeWindow root_window) { |
| 177 return client ? new CompositorImpl(client, root_window) : NULL; | 109 return client ? new CompositorImpl(client, root_window) : NULL; |
| 178 } | 110 } |
| 179 | 111 |
| 180 // static | 112 // static |
| 181 void Compositor::Initialize() { | 113 void Compositor::Initialize() { |
| 182 DCHECK(!CompositorImpl::IsInitialized()); | 114 DCHECK(!CompositorImpl::IsInitialized()); |
| 183 // SurfaceTextureTracker instance must be set before we create a GPU thread | |
| 184 // that could be using it to initialize GLImage instances. | |
| 185 gfx::SurfaceTextureTracker::InitInstance(g_surface_texture_tracker.Pointer()); | |
| 186 g_initialized = true; | 115 g_initialized = true; |
| 187 } | 116 } |
| 188 | 117 |
| 189 // static | 118 // static |
| 190 bool CompositorImpl::IsInitialized() { | 119 bool CompositorImpl::IsInitialized() { |
| 191 return g_initialized; | 120 return g_initialized; |
| 192 } | 121 } |
| 193 | 122 |
| 194 // static | |
| 195 int CompositorImpl::CreateSurfaceTexture(int child_process_id) { | |
| 196 // Note: this needs to be 0 as the surface texture implemenation will take | |
| 197 // ownership of the texture and call glDeleteTextures when the GPU service | |
| 198 // attaches the surface texture to a real texture id. glDeleteTextures | |
| 199 // silently ignores 0. | |
| 200 const int kDummyTextureId = 0; | |
| 201 scoped_refptr<gfx::SurfaceTexture> surface_texture = | |
| 202 gfx::SurfaceTexture::Create(kDummyTextureId); | |
| 203 return g_surface_texture_tracker.Pointer()->AddSurfaceTexture( | |
| 204 surface_texture.get(), child_process_id); | |
| 205 } | |
| 206 | |
| 207 // static | |
| 208 void CompositorImpl::DestroyAllSurfaceTextures(int child_process_id) { | |
| 209 g_surface_texture_tracker.Pointer()->RemoveAllSurfaceTextures( | |
| 210 child_process_id); | |
| 211 } | |
| 212 | |
| 213 CompositorImpl::CompositorImpl(CompositorClient* client, | 123 CompositorImpl::CompositorImpl(CompositorClient* client, |
| 214 gfx::NativeWindow root_window) | 124 gfx::NativeWindow root_window) |
| 215 : root_layer_(cc::Layer::Create()), | 125 : root_layer_(cc::Layer::Create()), |
| 216 has_transparent_background_(false), | 126 has_transparent_background_(false), |
| 217 device_scale_factor_(1), | 127 device_scale_factor_(1), |
| 218 window_(NULL), | 128 window_(NULL), |
| 219 surface_id_(0), | 129 surface_id_(0), |
| 220 client_(client), | 130 client_(client), |
| 221 root_window_(root_window), | 131 root_window_(root_window), |
| 222 did_post_swapbuffers_(false), | 132 did_post_swapbuffers_(false), |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 } | 597 } |
| 688 | 598 |
| 689 void CompositorImpl::SetNeedsAnimate() { | 599 void CompositorImpl::SetNeedsAnimate() { |
| 690 if (!host_) | 600 if (!host_) |
| 691 return; | 601 return; |
| 692 | 602 |
| 693 host_->SetNeedsAnimate(); | 603 host_->SetNeedsAnimate(); |
| 694 } | 604 } |
| 695 | 605 |
| 696 } // namespace content | 606 } // namespace content |
| OLD | NEW |