Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 634643002: content: Out-of-process GPU service support for SurfaceTexture backed GpuMemoryBuffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one last build fix Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 30 matching lines...) Expand all
41 #include "content/common/host_shared_bitmap_manager.h" 41 #include "content/common/host_shared_bitmap_manager.h"
42 #include "content/public/browser/android/compositor_client.h" 42 #include "content/public/browser/android/compositor_client.h"
43 #include "gpu/command_buffer/client/context_support.h" 43 #include "gpu/command_buffer/client/context_support.h"
44 #include "gpu/command_buffer/client/gles2_interface.h" 44 #include "gpu/command_buffer/client/gles2_interface.h"
45 #include "third_party/khronos/GLES2/gl2.h" 45 #include "third_party/khronos/GLES2/gl2.h"
46 #include "third_party/khronos/GLES2/gl2ext.h" 46 #include "third_party/khronos/GLES2/gl2ext.h"
47 #include "third_party/skia/include/core/SkMallocPixelRef.h" 47 #include "third_party/skia/include/core/SkMallocPixelRef.h"
48 #include "ui/base/android/window_android.h" 48 #include "ui/base/android/window_android.h"
49 #include "ui/gfx/android/device_display_info.h" 49 #include "ui/gfx/android/device_display_info.h"
50 #include "ui/gfx/frame_time.h" 50 #include "ui/gfx/frame_time.h"
51 #include "ui/gl/android/surface_texture.h"
52 #include "ui/gl/android/surface_texture_tracker.h"
53 #include "webkit/common/gpu/context_provider_in_process.h" 51 #include "webkit/common/gpu/context_provider_in_process.h"
54 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 52 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
55 53
56 namespace content { 54 namespace content {
57 55
58 namespace { 56 namespace {
59 57
60 const unsigned int kMaxSwapBuffers = 2U; 58 const unsigned int kMaxSwapBuffers = 2U;
61 59
62 // Used to override capabilities_.adjust_deadline_for_parent to false 60 // Used to override capabilities_.adjust_deadline_for_parent to false
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 OutputSurface::OnSwapBuffersComplete(); 118 OutputSurface::OnSwapBuffersComplete();
121 } 119 }
122 120
123 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&)> 121 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&)>
124 swap_buffers_completion_callback_; 122 swap_buffers_completion_callback_;
125 123
126 scoped_refptr<base::MessageLoopProxy> main_thread_; 124 scoped_refptr<base::MessageLoopProxy> main_thread_;
127 base::WeakPtr<CompositorImpl> compositor_impl_; 125 base::WeakPtr<CompositorImpl> compositor_impl_;
128 }; 126 };
129 127
130 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker {
131 public:
132 SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) {
133 thread_checker_.DetachFromThread();
134 }
135
136 // Overridden from gfx::SurfaceTextureTracker:
137 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture(
138 int primary_id,
139 int secondary_id) override {
140 base::AutoLock lock(surface_textures_lock_);
141 SurfaceTextureMapKey key(primary_id, secondary_id);
142 SurfaceTextureMap::iterator it = surface_textures_.find(key);
143 if (it == surface_textures_.end())
144 return scoped_refptr<gfx::SurfaceTexture>();
145 scoped_refptr<gfx::SurfaceTexture> surface_texture = it->second;
146 surface_textures_.erase(it);
147 return surface_texture;
148 }
149
150 int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture,
151 int child_process_id) {
152 DCHECK(thread_checker_.CalledOnValidThread());
153 int surface_texture_id = next_surface_texture_id_++;
154 if (next_surface_texture_id_ == INT_MAX)
155 next_surface_texture_id_ = 1;
156
157 base::AutoLock lock(surface_textures_lock_);
158 SurfaceTextureMapKey key(surface_texture_id, child_process_id);
159 DCHECK(surface_textures_.find(key) == surface_textures_.end());
160 surface_textures_[key] = surface_texture;
161 RegisterChildProcessSurfaceTexture(
162 surface_texture_id,
163 child_process_id,
164 surface_texture->j_surface_texture().obj());
165 return surface_texture_id;
166 }
167
168 void RemoveAllSurfaceTextures(int child_process_id) {
169 DCHECK(thread_checker_.CalledOnValidThread());
170 base::AutoLock lock(surface_textures_lock_);
171 SurfaceTextureMap::iterator it = surface_textures_.begin();
172 while (it != surface_textures_.end()) {
173 if (it->first.second == child_process_id) {
174 UnregisterChildProcessSurfaceTexture(it->first.first, it->first.second);
175 surface_textures_.erase(it++);
176 } else {
177 ++it;
178 }
179 }
180 }
181
182 private:
183 typedef std::pair<int, int> SurfaceTextureMapKey;
184 typedef base::hash_map<SurfaceTextureMapKey,
185 scoped_refptr<gfx::SurfaceTexture> >
186 SurfaceTextureMap;
187 SurfaceTextureMap surface_textures_;
188 mutable base::Lock surface_textures_lock_;
189 int next_surface_texture_id_;
190 base::ThreadChecker thread_checker_;
191 };
192 base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker =
193 LAZY_INSTANCE_INITIALIZER;
194
195 static bool g_initialized = false; 128 static bool g_initialized = false;
196 129
197 } // anonymous namespace 130 } // anonymous namespace
198 131
199 // static 132 // static
200 Compositor* Compositor::Create(CompositorClient* client, 133 Compositor* Compositor::Create(CompositorClient* client,
201 gfx::NativeWindow root_window) { 134 gfx::NativeWindow root_window) {
202 return client ? new CompositorImpl(client, root_window) : NULL; 135 return client ? new CompositorImpl(client, root_window) : NULL;
203 } 136 }
204 137
205 // static 138 // static
206 void Compositor::Initialize() { 139 void Compositor::Initialize() {
207 DCHECK(!CompositorImpl::IsInitialized()); 140 DCHECK(!CompositorImpl::IsInitialized());
208 // SurfaceTextureTracker instance must be set before we create a GPU thread
209 // that could be using it to initialize GLImage instances.
210 gfx::SurfaceTextureTracker::InitInstance(g_surface_texture_tracker.Pointer());
211 g_initialized = true; 141 g_initialized = true;
212 } 142 }
213 143
214 // static 144 // static
215 bool CompositorImpl::IsInitialized() { 145 bool CompositorImpl::IsInitialized() {
216 return g_initialized; 146 return g_initialized;
217 } 147 }
218 148
219 // static
220 int CompositorImpl::CreateSurfaceTexture(int child_process_id) {
221 // Note: this needs to be 0 as the surface texture implemenation will take
222 // ownership of the texture and call glDeleteTextures when the GPU service
223 // attaches the surface texture to a real texture id. glDeleteTextures
224 // silently ignores 0.
225 const int kDummyTextureId = 0;
226 scoped_refptr<gfx::SurfaceTexture> surface_texture =
227 gfx::SurfaceTexture::Create(kDummyTextureId);
228 return g_surface_texture_tracker.Pointer()->AddSurfaceTexture(
229 surface_texture.get(), child_process_id);
230 }
231
232 // static
233 void CompositorImpl::DestroyAllSurfaceTextures(int child_process_id) {
234 g_surface_texture_tracker.Pointer()->RemoveAllSurfaceTextures(
235 child_process_id);
236 }
237
238 CompositorImpl::CompositorImpl(CompositorClient* client, 149 CompositorImpl::CompositorImpl(CompositorClient* client,
239 gfx::NativeWindow root_window) 150 gfx::NativeWindow root_window)
240 : root_layer_(cc::Layer::Create()), 151 : root_layer_(cc::Layer::Create()),
241 has_transparent_background_(false), 152 has_transparent_background_(false),
242 device_scale_factor_(1), 153 device_scale_factor_(1),
243 window_(NULL), 154 window_(NULL),
244 surface_id_(0), 155 surface_id_(0),
245 client_(client), 156 client_(client),
246 root_window_(root_window), 157 root_window_(root_window),
247 did_post_swapbuffers_(false), 158 did_post_swapbuffers_(false),
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 } 623 }
713 624
714 void CompositorImpl::SetNeedsAnimate() { 625 void CompositorImpl::SetNeedsAnimate() {
715 if (!host_) 626 if (!host_)
716 return; 627 return;
717 628
718 host_->SetNeedsAnimate(); 629 host_->SetNeedsAnimate();
719 } 630 }
720 631
721 } // namespace content 632 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/compositor_impl_android.h ('k') | content/browser/renderer_host/render_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698