| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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 webkit_glue::WebThreadImpl* g_impl_thread = NULL; | 41 static webkit_glue::WebThreadImpl* g_impl_thread = NULL; |
| 42 static bool g_use_direct_gl = false; | 42 static bool g_use_direct_gl = false; |
| 43 | 43 |
| 44 // Adapts a pure WebGraphicsContext3D into a cc::OutputSurface. | |
| 45 class WebGraphicsContextToOutputSurfaceAdapter : public cc::OutputSurface { | |
| 46 public: | |
| 47 explicit WebGraphicsContextToOutputSurfaceAdapter( | |
| 48 WebKit::WebGraphicsContext3D* context) | |
| 49 : context3d_(context), | |
| 50 client_(0) { | |
| 51 } | |
| 52 | |
| 53 virtual bool BindToClient(cc::OutputSurfaceClient* client) OVERRIDE { | |
| 54 DCHECK(client); | |
| 55 if (!context3d_->makeContextCurrent()) | |
| 56 return false; | |
| 57 client_ = client; | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 virtual const struct Capabilities& Capabilities() const OVERRIDE { | |
| 62 return capabilities_; | |
| 63 } | |
| 64 | |
| 65 virtual WebKit::WebGraphicsContext3D* Context3D() const OVERRIDE { | |
| 66 return context3d_.get(); | |
| 67 } | |
| 68 | |
| 69 virtual cc::SoftwareOutputDevice* SoftwareDevice() const OVERRIDE { | |
| 70 return NULL; | |
| 71 } | |
| 72 | |
| 73 virtual void SendFrameToParentCompositor( | |
| 74 cc::CompositorFrame*) OVERRIDE { | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; | |
| 79 struct Capabilities capabilities_; | |
| 80 cc::OutputSurfaceClient* client_; | |
| 81 }; | |
| 82 | |
| 83 } // anonymous namespace | 44 } // anonymous namespace |
| 84 | 45 |
| 85 namespace content { | 46 namespace content { |
| 86 | 47 |
| 87 // static | 48 // static |
| 88 Compositor* Compositor::Create(Client* client) { | 49 Compositor* Compositor::Create(Client* client) { |
| 89 return client ? new CompositorImpl(client) : NULL; | 50 return client ? new CompositorImpl(client) : NULL; |
| 90 } | 51 } |
| 91 | 52 |
| 92 // static | 53 // static |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 scoped_ptr<cc::OutputSurface> CompositorImpl::createOutputSurface() { | 272 scoped_ptr<cc::OutputSurface> CompositorImpl::createOutputSurface() { |
| 312 if (g_use_direct_gl) { | 273 if (g_use_direct_gl) { |
| 313 WebKit::WebGraphicsContext3D::Attributes attrs; | 274 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 314 attrs.shareResources = false; | 275 attrs.shareResources = false; |
| 315 attrs.noAutomaticFlushes = true; | 276 attrs.noAutomaticFlushes = true; |
| 316 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context( | 277 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context( |
| 317 webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWindow( | 278 webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWindow( |
| 318 attrs, | 279 attrs, |
| 319 window_, | 280 window_, |
| 320 NULL)); | 281 NULL)); |
| 321 return scoped_ptr<cc::OutputSurface>( | 282 return make_scoped_ptr(new cc::OutputSurface( |
| 322 new WebGraphicsContextToOutputSurfaceAdapter(context.release())); | 283 context.PassAs<WebKit::WebGraphicsContext3D>())); |
| 323 } else { | 284 } else { |
| 324 DCHECK(window_ && surface_id_); | 285 DCHECK(window_ && surface_id_); |
| 325 WebKit::WebGraphicsContext3D::Attributes attrs; | 286 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 326 attrs.shareResources = true; | 287 attrs.shareResources = true; |
| 327 attrs.noAutomaticFlushes = true; | 288 attrs.noAutomaticFlushes = true; |
| 328 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); | 289 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); |
| 329 GURL url("chrome://gpu/Compositor::createContext3D"); | 290 GURL url("chrome://gpu/Compositor::createContext3D"); |
| 330 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 291 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 331 new WebGraphicsContext3DCommandBufferImpl(surface_id_, | 292 new WebGraphicsContext3DCommandBufferImpl(surface_id_, |
| 332 url, | 293 url, |
| 333 factory, | 294 factory, |
| 334 weak_factory_.GetWeakPtr())); | 295 weak_factory_.GetWeakPtr())); |
| 335 if (!context->Initialize( | 296 if (!context->Initialize( |
| 336 attrs, | 297 attrs, |
| 337 false, | 298 false, |
| 338 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
{ | 299 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
{ |
| 339 LOG(ERROR) << "Failed to create 3D context for compositor."; | 300 LOG(ERROR) << "Failed to create 3D context for compositor."; |
| 340 return scoped_ptr<cc::OutputSurface>(); | 301 return scoped_ptr<cc::OutputSurface>(); |
| 341 } | 302 } |
| 342 return scoped_ptr<cc::OutputSurface>( | 303 return make_scoped_ptr(new cc::OutputSurface( |
| 343 new WebGraphicsContextToOutputSurfaceAdapter(context.release())); | 304 context.PassAs<WebKit::WebGraphicsContext3D>())); |
| 344 } | 305 } |
| 345 } | 306 } |
| 346 | 307 |
| 347 scoped_ptr<cc::InputHandler> CompositorImpl::createInputHandler() { | 308 scoped_ptr<cc::InputHandler> CompositorImpl::createInputHandler() { |
| 348 return scoped_ptr<cc::InputHandler>(); | 309 return scoped_ptr<cc::InputHandler>(); |
| 349 } | 310 } |
| 350 | 311 |
| 351 void CompositorImpl::didRecreateOutputSurface(bool success) { | 312 void CompositorImpl::didRecreateOutputSurface(bool success) { |
| 352 } | 313 } |
| 353 | 314 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 385 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 425 return GL_UNSIGNED_BYTE; | 386 return GL_UNSIGNED_BYTE; |
| 426 break; | 387 break; |
| 427 case ANDROID_BITMAP_FORMAT_RGB_565: | 388 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 428 default: | 389 default: |
| 429 return GL_UNSIGNED_SHORT_5_6_5; | 390 return GL_UNSIGNED_SHORT_5_6_5; |
| 430 } | 391 } |
| 431 } | 392 } |
| 432 | 393 |
| 433 } // namespace content | 394 } // namespace content |
| OLD | NEW |