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

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

Issue 11428091: Migrate the Android compositor to cc::Layer classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "cc/input_handler.h"
15 #include "cc/layer.h"
16 #include "cc/layer_tree_host.h"
17 #include "cc/thread_impl.h"
14 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 18 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
15 #include "content/browser/gpu/gpu_surface_tracker.h" 19 #include "content/browser/gpu/gpu_surface_tracker.h"
16 #include "content/browser/renderer_host/image_transport_factory_android.h" 20 #include "content/browser/renderer_host/image_transport_factory_android.h"
17 #include "content/common/gpu/client/gl_helper.h" 21 #include "content/common/gpu/client/gl_helper.h"
18 #include "content/common/gpu/client/gpu_channel_host.h" 22 #include "content/common/gpu/client/gpu_channel_host.h"
19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 23 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
20 #include "content/common/gpu/gpu_process_launch_causes.h" 24 #include "content/common/gpu/gpu_process_launch_causes.h"
21 #include "content/public/common/content_switches.h" 25 #include "content/public/common/content_switches.h"
22 #include "third_party/khronos/GLES2/gl2.h" 26 #include "third_party/khronos/GLES2/gl2.h"
23 #include "third_party/khronos/GLES2/gl2ext.h" 27 #include "third_party/khronos/GLES2/gl2ext.h"
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput Surface.h" 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput Surface.h"
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer. h"
27 #include "ui/gfx/android/java_bitmap.h" 30 #include "ui/gfx/android/java_bitmap.h"
28 #include "webkit/compositor_bindings/web_compositor_support_impl.h"
29 #include "webkit/glue/webthread_impl.h" 31 #include "webkit/glue/webthread_impl.h"
30 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" 32 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
31 33
32 using webkit::WebCompositorSupportImpl;
33
34 namespace gfx { 34 namespace gfx {
35 class JavaBitmap; 35 class JavaBitmap;
36 } 36 }
37 37
38 namespace { 38 namespace {
39 39
40 static bool g_initialized = false; 40 static bool g_initialized = false;
41 static base::LazyInstance<WebCompositorSupportImpl> g_compositor_support = 41 static webkit_glue::WebThreadImpl* g_impl_thread = NULL;
42 LAZY_INSTANCE_INITIALIZER;
43 static WebKit::WebThread* g_impl_thread = NULL;
44 static bool g_use_direct_gl = false; 42 static bool g_use_direct_gl = false;
45 43
46 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. 44 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface.
47 class WebGraphicsContextToOutputSurfaceAdapter : 45 class WebGraphicsContextToOutputSurfaceAdapter :
48 public WebKit::WebCompositorOutputSurface { 46 public WebKit::WebCompositorOutputSurface {
49 public: 47 public:
50 explicit WebGraphicsContextToOutputSurfaceAdapter( 48 explicit WebGraphicsContextToOutputSurfaceAdapter(
51 WebKit::WebGraphicsContext3D* context) 49 WebKit::WebGraphicsContext3D* context)
52 : m_context3D(context) 50 : m_context3D(context)
53 , m_client(0) 51 , m_client(0)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 namespace content { 88 namespace content {
91 89
92 // static 90 // static
93 Compositor* Compositor::Create(Client* client) { 91 Compositor* Compositor::Create(Client* client) {
94 return client ? new CompositorImpl(client) : NULL; 92 return client ? new CompositorImpl(client) : NULL;
95 } 93 }
96 94
97 // static 95 // static
98 void Compositor::Initialize() { 96 void Compositor::Initialize() {
99 DCHECK(!CompositorImpl::IsInitialized()); 97 DCHECK(!CompositorImpl::IsInitialized());
100 g_compositor_support.Get().initialize(g_impl_thread);
101 g_initialized = true; 98 g_initialized = true;
102 } 99 }
103 100
104 // static 101 // static
105 void Compositor::InitializeWithFlags(uint32 flags) { 102 void Compositor::InitializeWithFlags(uint32 flags) {
106 g_use_direct_gl = flags & DIRECT_CONTEXT_ON_DRAW_THREAD; 103 g_use_direct_gl = flags & DIRECT_CONTEXT_ON_DRAW_THREAD;
107 if (flags & ENABLE_COMPOSITOR_THREAD) 104 if (flags & ENABLE_COMPOSITOR_THREAD) {
105 TRACE_EVENT_INSTANT0("test_gpu", "ThreadedCompositingInitialization");
108 g_impl_thread = new webkit_glue::WebThreadImpl("Browser Compositor"); 106 g_impl_thread = new webkit_glue::WebThreadImpl("Browser Compositor");
107 }
109 Compositor::Initialize(); 108 Compositor::Initialize();
110 } 109 }
111 110
112 // static 111 // static
113 WebCompositorSupportImpl* CompositorImpl::CompositorSupport() {
114 DCHECK(g_initialized);
115 return g_compositor_support.Pointer();
116 }
117
118 // static
119 bool CompositorImpl::IsInitialized() { 112 bool CompositorImpl::IsInitialized() {
120 return g_initialized; 113 return g_initialized;
121 } 114 }
122 115
123 // static 116 // static
117 bool CompositorImpl::IsThreadingEnabled() {
118 return g_impl_thread;
119 }
120
121 // static
124 bool CompositorImpl::UsesDirectGL() { 122 bool CompositorImpl::UsesDirectGL() {
125 return g_use_direct_gl; 123 return g_use_direct_gl;
126 } 124 }
127 125
128 CompositorImpl::CompositorImpl(Compositor::Client* client) 126 CompositorImpl::CompositorImpl(Compositor::Client* client)
129 : window_(NULL), 127 : root_layer_(cc::Layer::create()),
128 window_(NULL),
130 surface_id_(0), 129 surface_id_(0),
131 client_(client), 130 client_(client),
132 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 131 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
133 DCHECK(client); 132 DCHECK(client);
134 root_layer_.reset(g_compositor_support.Get().createLayer());
135 } 133 }
136 134
137 CompositorImpl::~CompositorImpl() { 135 CompositorImpl::~CompositorImpl() {
138 } 136 }
139 137
140 void CompositorImpl::Composite() { 138 void CompositorImpl::Composite() {
141 if (host_.get()) 139 if (host_.get())
142 host_->composite(); 140 host_->composite();
143 } 141 }
144 142
145 void CompositorImpl::SetRootLayer(WebKit::WebLayer* root_layer) { 143 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) {
146 root_layer_->removeAllChildren(); 144 root_layer_->removeAllChildren();
147 root_layer_->addChild(root_layer); 145 root_layer_->addChild(root_layer);
148 } 146 }
149 147
150 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { 148 void CompositorImpl::SetWindowSurface(ANativeWindow* window) {
151 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); 149 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
152 150
153 if (window_) { 151 if (window_) {
154 tracker->RemoveSurface(surface_id_); 152 tracker->RemoveSurface(surface_id_);
155 ANativeWindow_release(window_); 153 ANativeWindow_release(window_);
(...skipping 10 matching lines...) Expand all
166 surface_id_, 164 surface_id_,
167 gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false)); 165 gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false));
168 SetVisible(true); 166 SetVisible(true);
169 } 167 }
170 } 168 }
171 169
172 void CompositorImpl::SetVisible(bool visible) { 170 void CompositorImpl::SetVisible(bool visible) {
173 if (!visible) { 171 if (!visible) {
174 host_.reset(); 172 host_.reset();
175 } else if (!host_.get()) { 173 } else if (!host_.get()) {
176 WebKit::WebLayerTreeView::Settings settings; 174 cc::LayerTreeSettings settings;
177 settings.refreshRate = 60.0; 175 settings.refreshRate = 60.0;
178 host_.reset(g_compositor_support.Get().createLayerTreeView( 176
179 this, *root_layer_, settings)); 177 scoped_ptr<cc::Thread> impl_thread;
178 if (g_impl_thread)
179 impl_thread = cc::ThreadImpl::createForDifferentThread(
180 g_impl_thread->message_loop()->message_loop_proxy());
181
182 host_ = cc::LayerTreeHost::create(this, settings, impl_thread.Pass());
183 host_->setRootLayer(root_layer_);
184
180 host_->setVisible(true); 185 host_->setVisible(true);
181 host_->setSurfaceReady(); 186 host_->setSurfaceReady();
182 host_->setViewportSize(size_); 187 host_->setViewportSize(size_, size_);
183 } 188 }
184 } 189 }
185 190
186 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { 191 void CompositorImpl::SetWindowBounds(const gfx::Size& size) {
187 if (size_ == size) 192 if (size_ == size)
188 return; 193 return;
189 194
190 size_ = size; 195 size_ = size;
191 if (host_) 196 if (host_)
192 host_->setViewportSize(size); 197 host_->setViewportSize(size, size);
193 root_layer_->setBounds(size); 198 root_layer_->setBounds(size);
194 } 199 }
195 200
196 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { 201 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) {
197 if (host_.get()) 202 if (host_.get())
198 return host_->compositeAndReadback(pixels, rect); 203 return host_->compositeAndReadback(pixels, rect);
199 else 204 else
200 return false; 205 return false;
201 } 206 }
202 207
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 260 }
256 261
257 void CompositorImpl::CopyTextureToBitmap(WebKit::WebGLId texture_id, 262 void CompositorImpl::CopyTextureToBitmap(WebKit::WebGLId texture_id,
258 gfx::JavaBitmap& bitmap) { 263 gfx::JavaBitmap& bitmap) {
259 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); 264 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
260 helper->ReadbackTextureSync(texture_id, 265 helper->ReadbackTextureSync(texture_id,
261 bitmap.size(), 266 bitmap.size(),
262 static_cast<unsigned char*> (bitmap.pixels())); 267 static_cast<unsigned char*> (bitmap.pixels()));
263 } 268 }
264 269
265 void CompositorImpl::updateAnimations(double frameBeginTime) { 270 void CompositorImpl::animate(double monotonicFrameBeginTime) {
266 } 271 }
267 272
268 void CompositorImpl::layout() { 273 void CompositorImpl::layout() {
269 } 274 }
270 275
271 void CompositorImpl::applyScrollAndScale(const WebKit::WebSize& scrollDelta, 276 void CompositorImpl::applyScrollAndScale(gfx::Vector2d scrollDelta,
272 float scaleFactor) { 277 float pageScale) {
273 } 278 }
274 279
275 WebKit::WebCompositorOutputSurface* CompositorImpl::createOutputSurface() { 280 scoped_ptr<WebKit::WebCompositorOutputSurface>
281 CompositorImpl::createOutputSurface() {
276 if (g_use_direct_gl) { 282 if (g_use_direct_gl) {
277 WebKit::WebGraphicsContext3D::Attributes attrs; 283 WebKit::WebGraphicsContext3D::Attributes attrs;
278 attrs.shareResources = false; 284 attrs.shareResources = false;
279 attrs.noAutomaticFlushes = true; 285 attrs.noAutomaticFlushes = true;
280 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context( 286 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context(
281 webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWindow( 287 webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWindow(
282 attrs, 288 attrs,
283 window_, 289 window_,
284 NULL)); 290 NULL));
285 return new WebGraphicsContextToOutputSurfaceAdapter(context.release()); 291 return scoped_ptr<WebKit::WebCompositorOutputSurface>(
292 new WebGraphicsContextToOutputSurfaceAdapter(context.release()));
286 } else { 293 } else {
287 DCHECK(window_ && surface_id_); 294 DCHECK(window_ && surface_id_);
288 WebKit::WebGraphicsContext3D::Attributes attrs; 295 WebKit::WebGraphicsContext3D::Attributes attrs;
289 attrs.shareResources = true; 296 attrs.shareResources = true;
290 attrs.noAutomaticFlushes = true; 297 attrs.noAutomaticFlushes = true;
291 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); 298 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance();
292 GURL url("chrome://gpu/Compositor::createContext3D"); 299 GURL url("chrome://gpu/Compositor::createContext3D");
293 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( 300 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
294 new WebGraphicsContext3DCommandBufferImpl(surface_id_, 301 new WebGraphicsContext3DCommandBufferImpl(surface_id_,
295 url, 302 url,
296 factory, 303 factory,
297 weak_factory_.GetWeakPtr())); 304 weak_factory_.GetWeakPtr()));
298 if (!context->Initialize( 305 if (!context->Initialize(
299 attrs, 306 attrs,
300 false, 307 false,
301 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) { 308 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) {
302 LOG(ERROR) << "Failed to create 3D context for compositor."; 309 LOG(ERROR) << "Failed to create 3D context for compositor.";
303 return NULL; 310 return scoped_ptr<WebKit::WebCompositorOutputSurface>();
304 } 311 }
305 return new WebGraphicsContextToOutputSurfaceAdapter(context.release()); 312 return scoped_ptr<WebKit::WebCompositorOutputSurface>(
313 new WebGraphicsContextToOutputSurfaceAdapter(context.release()));
306 } 314 }
307 } 315 }
308 316
317 scoped_ptr<cc::InputHandler> CompositorImpl::createInputHandler() {
318 scoped_ptr<cc::InputHandler> ret;
319 return ret.Pass();
joth 2012/11/29 21:19:38 wrong indent I think just "return scoped_ptr<cc::
Leandro GraciĆ” Gil 2012/11/30 12:11:11 Done.
320 }
321
309 void CompositorImpl::didRecreateOutputSurface(bool success) { 322 void CompositorImpl::didRecreateOutputSurface(bool success) {
310 } 323 }
311 324
312 void CompositorImpl::didCommit() { 325 void CompositorImpl::didCommit() {
313 } 326 }
314 327
315 void CompositorImpl::didCommitAndDrawFrame() { 328 void CompositorImpl::didCommitAndDrawFrame() {
316 } 329 }
317 330
318 void CompositorImpl::didCompleteSwapBuffers() { 331 void CompositorImpl::didCompleteSwapBuffers() {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 case ANDROID_BITMAP_FORMAT_RGBA_8888: 395 case ANDROID_BITMAP_FORMAT_RGBA_8888:
383 return GL_UNSIGNED_BYTE; 396 return GL_UNSIGNED_BYTE;
384 break; 397 break;
385 case ANDROID_BITMAP_FORMAT_RGB_565: 398 case ANDROID_BITMAP_FORMAT_RGB_565:
386 default: 399 default:
387 return GL_UNSIGNED_SHORT_5_6_5; 400 return GL_UNSIGNED_SHORT_5_6_5;
388 } 401 }
389 } 402 }
390 403
391 } // namespace content 404 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698