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

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

Issue 195583003: Add initial GpuMemoryBufferSurfaceTexture implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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 #include <map> 9 #include <map>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
20 #include "cc/base/switches.h" 21 #include "cc/base/switches.h"
21 #include "cc/input/input_handler.h" 22 #include "cc/input/input_handler.h"
22 #include "cc/layers/layer.h" 23 #include "cc/layers/layer.h"
23 #include "cc/output/compositor_frame.h" 24 #include "cc/output/compositor_frame.h"
24 #include "cc/output/context_provider.h" 25 #include "cc/output/context_provider.h"
(...skipping 11 matching lines...) Expand all
36 #include "content/common/gpu/gpu_process_launch_causes.h" 37 #include "content/common/gpu/gpu_process_launch_causes.h"
37 #include "content/public/browser/android/compositor_client.h" 38 #include "content/public/browser/android/compositor_client.h"
38 #include "gpu/command_buffer/client/gles2_interface.h" 39 #include "gpu/command_buffer/client/gles2_interface.h"
39 #include "third_party/khronos/GLES2/gl2.h" 40 #include "third_party/khronos/GLES2/gl2.h"
40 #include "third_party/khronos/GLES2/gl2ext.h" 41 #include "third_party/khronos/GLES2/gl2ext.h"
41 #include "third_party/skia/include/core/SkMallocPixelRef.h" 42 #include "third_party/skia/include/core/SkMallocPixelRef.h"
42 #include "ui/base/android/window_android.h" 43 #include "ui/base/android/window_android.h"
43 #include "ui/gfx/android/device_display_info.h" 44 #include "ui/gfx/android/device_display_info.h"
44 #include "ui/gfx/android/java_bitmap.h" 45 #include "ui/gfx/android/java_bitmap.h"
45 #include "ui/gfx/frame_time.h" 46 #include "ui/gfx/frame_time.h"
47 #include "ui/gl/android/scoped_java_surface.h"
48 #include "ui/gl/android/surface_texture.h"
49 #include "ui/gl/android/surface_texture_tracker.h"
46 #include "webkit/common/gpu/context_provider_in_process.h" 50 #include "webkit/common/gpu/context_provider_in_process.h"
47 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 51 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
48 52
49 namespace gfx { 53 namespace gfx {
50 class JavaBitmap; 54 class JavaBitmap;
51 } 55 }
52 56
53 namespace { 57 namespace {
54 58
55 // Used for drawing directly to the screen. Bypasses resizing and swaps. 59 // Used for drawing directly to the screen. Bypasses resizing and swaps.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 128
125 protected: 129 protected:
126 TransientUIResource(cc::LayerTreeHost* host, 130 TransientUIResource(cc::LayerTreeHost* host,
127 const cc::UIResourceBitmap& bitmap) 131 const cc::UIResourceBitmap& bitmap)
128 : cc::ScopedUIResource(host, bitmap), retrieved_(false) {} 132 : cc::ScopedUIResource(host, bitmap), retrieved_(false) {}
129 133
130 private: 134 private:
131 bool retrieved_; 135 bool retrieved_;
132 }; 136 };
133 137
138 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker {
139 public:
140 SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) {
141 gfx::SurfaceTextureTracker::InitInstance(this);
142 }
143
144 virtual ~SurfaceTextureTrackerImpl() {
145 gfx::SurfaceTextureTracker::InitInstance(NULL);
146 }
147
148 // Overridden from gfx::SurfaceTextureTracker:
149 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture(
150 int surface_texture_id) OVERRIDE {
151 base::AutoLock lock(surface_textures_lock_);
152 scoped_ptr<SurfaceTextureInfo> info =
153 surface_textures_.take_and_erase(surface_texture_id);
154 return info ? info->surface_texture : NULL;
155 }
156
157 int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture) {
158 int surface_texture_id = next_surface_texture_id_++;
159 base::AutoLock lock(surface_textures_lock_);
160 DCHECK(surface_textures_.find(surface_texture_id) ==
161 surface_textures_.end());
162 surface_textures_.set(
163 surface_texture_id,
164 make_scoped_ptr(new SurfaceTextureInfo(surface_texture)));
165 return surface_texture_id;
166 }
167
168 jobject GetSurface(int surface_texture_id) const {
reveman 2014/03/11 22:59:36 This should probably take a renderer_id to prevent
reveman 2014/03/13 21:36:00 Done.
169 base::AutoLock lock(surface_textures_lock_);
170 SurfaceTextureMap::const_iterator it =
171 surface_textures_.find(surface_texture_id);
172 return it == surface_textures_.end()
173 ? NULL
174 : it->second->surface.j_surface().obj();
175 }
176
177 private:
178 struct SurfaceTextureInfo {
179 explicit SurfaceTextureInfo(gfx::SurfaceTexture* surface_texture)
180 : surface_texture(surface_texture), surface(surface_texture) {}
181
182 scoped_refptr<gfx::SurfaceTexture> surface_texture;
183 gfx::ScopedJavaSurface surface;
184 };
185
186 typedef base::ScopedPtrHashMap<int, SurfaceTextureInfo> SurfaceTextureMap;
187 SurfaceTextureMap surface_textures_;
188 mutable base::Lock surface_textures_lock_;
189 int next_surface_texture_id_;
190 };
191 base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker =
epennerAtGoogle 2014/03/12 00:45:06 Hold on, I thought the gfx::SurfaceTextureTracker
reveman 2014/03/12 16:07:06 gfx::SurfaceTextureTracker is just an interface an
epennerAtGoogle 2014/03/12 19:46:28 I think if this doesn't have to be a lazy-instance
reveman 2014/03/12 21:19:11 LazyInstance seems like a good match as we should
epennerAtGoogle 2014/03/12 23:10:14 Ah, your other comment cleared up why we can't cre
192 LAZY_INSTANCE_INITIALIZER;
193
134 static bool g_initialized = false; 194 static bool g_initialized = false;
135 195
136 } // anonymous namespace 196 } // anonymous namespace
137 197
138 namespace content { 198 namespace content {
139 199
140 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> > 200 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> >
141 SurfaceMap; 201 SurfaceMap;
142 static base::LazyInstance<SurfaceMap> 202 static base::LazyInstance<SurfaceMap>
143 g_surface_map = LAZY_INSTANCE_INITIALIZER; 203 g_surface_map = LAZY_INSTANCE_INITIALIZER;
(...skipping 20 matching lines...) Expand all
164 jobject CompositorImpl::GetSurface(int surface_id) { 224 jobject CompositorImpl::GetSurface(int surface_id) {
165 base::AutoLock lock(g_surface_map_lock.Get()); 225 base::AutoLock lock(g_surface_map_lock.Get());
166 SurfaceMap* surfaces = g_surface_map.Pointer(); 226 SurfaceMap* surfaces = g_surface_map.Pointer();
167 SurfaceMap::iterator it = surfaces->find(surface_id); 227 SurfaceMap::iterator it = surfaces->find(surface_id);
168 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj(); 228 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj();
169 229
170 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id; 230 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id;
171 return jsurface; 231 return jsurface;
172 } 232 }
173 233
234 // static
235 jobject CompositorImpl::GetSurfaceTextureSurface(int surface_texture_id) {
236 jobject jsurface =
237 g_surface_texture_tracker.Pointer()->GetSurface(surface_texture_id);
epennerAtGoogle 2014/03/12 00:45:06 Could CompositorImpl just own this and avoid a glo
reveman 2014/03/12 16:07:06 We need some thread-safe code here to allow the Ja
epennerAtGoogle 2014/03/12 19:46:28 Ahh okay if we've already gone the global route a
238
239 LOG_IF(WARNING, !jsurface) << "No surface for surface texture id "
240 << surface_texture_id;
241 return jsurface;
242 }
243
244 // static
245 int CompositorImpl::AllocateSurfaceTexture() {
246 const int kDummyTextureId = 0;
247 scoped_refptr<gfx::SurfaceTexture> surface_texture =
248 make_scoped_refptr(new gfx::SurfaceTexture(kDummyTextureId));
epennerAtGoogle 2014/03/12 00:45:06 What thread will this happen on? I believe it has
reveman 2014/03/12 16:07:06 On the IO thread. Having looked at the SurfaceTex
epennerAtGoogle 2014/03/12 19:46:28 I think you might be right on the creation part. U
reveman 2014/03/12 21:19:11 I'll probably switch this over to a real texture i
249 return g_surface_texture_tracker.Pointer()->AddSurfaceTexture(
250 surface_texture.get());
251 }
252
174 CompositorImpl::CompositorImpl(CompositorClient* client, 253 CompositorImpl::CompositorImpl(CompositorClient* client,
175 gfx::NativeWindow root_window) 254 gfx::NativeWindow root_window)
176 : root_layer_(cc::Layer::Create()), 255 : root_layer_(cc::Layer::Create()),
177 has_transparent_background_(false), 256 has_transparent_background_(false),
178 device_scale_factor_(1), 257 device_scale_factor_(1),
179 window_(NULL), 258 window_(NULL),
180 surface_id_(0), 259 surface_id_(0),
181 client_(client), 260 client_(client),
182 root_window_(root_window) { 261 root_window_(root_window) {
183 DCHECK(client); 262 DCHECK(client);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 void CompositorImpl::DidAbortSwapBuffers() { 539 void CompositorImpl::DidAbortSwapBuffers() {
461 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); 540 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers");
462 client_->OnSwapBuffersCompleted(); 541 client_->OnSwapBuffersCompleted();
463 } 542 }
464 543
465 void CompositorImpl::DidCommit() { 544 void CompositorImpl::DidCommit() {
466 root_window_->OnCompositingDidCommit(); 545 root_window_->OnCompositingDidCommit();
467 } 546 }
468 547
469 } // namespace content 548 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698