| 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/public/browser/android/graphics_context.h" | 5 #include "content/browser/android/graphics_context.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "content/browser/android/draw_delegate_impl.h" | 7 #include "content/browser/android/draw_delegate_impl.h" |
| 9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 8 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 10 #include "content/browser/gpu/gpu_surface_tracker.h" | 9 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 11 #include "content/common/gpu/client/gpu_channel_host.h" | 10 #include "content/common/gpu/client/gpu_channel_host.h" |
| 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 11 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 13 #include "content/common/gpu/gpu_process_launch_causes.h" | 12 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 14 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC
ontext3D.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC
ontext3D.h" |
| 16 | 15 |
| 17 #include <android/native_window_jni.h> | 16 #include <android/native_window_jni.h> |
| 18 | 17 |
| 19 using content::BrowserGpuChannelHostFactory; | 18 using content::BrowserGpuChannelHostFactory; |
| 20 | 19 |
| 21 namespace { | 20 namespace content { |
| 22 | 21 |
| 23 // GraphicsContext implementation using a gpu command buffer. | 22 GraphicsContext::GraphicsContext(WebGraphicsContext3DCommandBufferImpl* context, |
| 24 class CmdBufferGraphicsContext : public content::GraphicsContext { | 23 int surface_id, |
| 25 public: | 24 ANativeWindow* window, |
| 26 CmdBufferGraphicsContext(WebGraphicsContext3DCommandBufferImpl* context, | 25 int texture_id1, |
| 27 int surface_id, | 26 int texture_id2) |
| 28 ANativeWindow* window, | 27 : context_(context), |
| 29 int texture_id1, | 28 surface_id_(surface_id), |
| 30 int texture_id2) | 29 window_(window) { |
| 31 : context_(context), | 30 texture_id_[0] = texture_id1; |
| 32 surface_id_(surface_id), | 31 texture_id_[1] = texture_id2; |
| 33 window_(window) { | 32 } |
| 34 texture_id_[0] = texture_id1; | |
| 35 texture_id_[1] = texture_id2; | |
| 36 } | |
| 37 | 33 |
| 38 virtual ~CmdBufferGraphicsContext() { | 34 GraphicsContext::~GraphicsContext() { |
| 39 context_->makeContextCurrent(); | 35 context_->makeContextCurrent(); |
| 40 context_->deleteTexture(texture_id_[0]); | 36 context_->deleteTexture(texture_id_[0]); |
| 41 context_->deleteTexture(texture_id_[1]); | 37 context_->deleteTexture(texture_id_[1]); |
| 42 context_->finish(); | 38 context_->finish(); |
| 43 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 39 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 44 tracker->RemoveSurface(surface_id_); | 40 tracker->RemoveSurface(surface_id_); |
| 45 ANativeWindow_release(window_); | 41 ANativeWindow_release(window_); |
| 46 } | 42 } |
| 47 | 43 |
| 48 virtual WebKit::WebGraphicsContext3D* GetContext3D() { | 44 uint32 GraphicsContext::InsertSyncPoint() { |
| 49 return context_.get(); | 45 return context_->insertSyncPoint(); |
| 50 } | 46 } |
| 51 virtual uint32 InsertSyncPoint() { | |
| 52 return context_->insertSyncPoint(); | |
| 53 } | |
| 54 | 47 |
| 55 private: | 48 int GraphicsContext::GetSurfaceID() { |
| 56 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_; | 49 return surface_id_; |
| 57 int surface_id_; | 50 } |
| 58 ANativeWindow* window_; | |
| 59 int texture_id_[2]; | |
| 60 }; | |
| 61 | |
| 62 } // anonymous namespace | |
| 63 | |
| 64 namespace content { | |
| 65 | 51 |
| 66 // static | 52 // static |
| 67 GraphicsContext* GraphicsContext::CreateForUI( | 53 GraphicsContext* GraphicsContext::CreateForUI( |
| 68 ANativeWindow* window) { | 54 ANativeWindow* window) { |
| 69 DCHECK(window); | 55 DCHECK(window); |
| 70 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 56 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 71 | 57 |
| 72 ANativeWindow_acquire(window); | 58 ANativeWindow_acquire(window); |
| 73 int surface_id = tracker->AddSurfaceForNativeWidget(window); | 59 int surface_id = tracker->AddSurfaceForNativeWidget(window); |
| 74 | 60 |
| 75 tracker->SetSurfaceHandle( | 61 tracker->SetSurfaceHandle( |
| 76 surface_id, | 62 surface_id, |
| 77 gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false)); | 63 gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false)); |
| 78 | 64 |
| 79 WebKit::WebGraphicsContext3D::Attributes attrs; | 65 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 80 attrs.shareResources = true; | 66 attrs.shareResources = true; |
| 81 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); | 67 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); |
| 82 GURL url("chrome://gpu/GpuProcessTransportHelper::CreateContext"); | 68 GURL url("chrome://gpu/GpuProcessTransportHelper::CreateContext"); |
| 83 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; | 69 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; |
| 84 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 70 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 85 new WebGraphicsContext3DCommandBufferImpl( | 71 new WebGraphicsContext3DCommandBufferImpl( |
| 86 surface_id, | 72 0, |
| 87 url, | 73 url, |
| 88 factory, | 74 factory, |
| 89 swap_client)); | 75 swap_client)); |
| 90 if (!context->Initialize( | 76 if (!context->Initialize( |
| 91 attrs, | 77 attrs, |
| 92 false, | 78 false, |
| 93 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) { | 79 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) { |
| 94 return NULL; | 80 return NULL; |
| 95 } | 81 } |
| 96 | 82 |
| 97 context->makeContextCurrent(); | 83 context->makeContextCurrent(); |
| 98 | 84 |
| 99 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 85 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
| 100 gfx::kNullPluginWindow, true); | 86 gfx::kNullPluginWindow, true); |
| 101 handle.parent_gpu_process_id = context->GetGPUProcessID(); | 87 handle.parent_gpu_process_id = context->GetGPUProcessID(); |
| 102 handle.parent_client_id = context->GetChannelID(); | 88 handle.parent_client_id = context->GetChannelID(); |
| 103 handle.parent_context_id = context->GetContextID(); | 89 handle.parent_context_id = context->GetContextID(); |
| 104 handle.parent_texture_id[0] = context->createTexture(); | 90 handle.parent_texture_id[0] = context->createTexture(); |
| 105 handle.parent_texture_id[1] = context->createTexture(); | 91 handle.parent_texture_id[1] = context->createTexture(); |
| 106 handle.sync_point = context->insertSyncPoint(); | 92 handle.sync_point = context->insertSyncPoint(); |
| 107 | 93 |
| 108 DrawDelegateImpl::GetInstance()->SetDrawSurface(handle); | 94 DrawDelegateImpl::GetInstance()->SetDrawSurface(handle); |
| 109 | 95 |
| 110 return new CmdBufferGraphicsContext( | 96 return new GraphicsContext( |
| 111 context.release(), surface_id, window, | 97 context.release(), surface_id, window, |
| 112 handle.parent_texture_id[0], | 98 handle.parent_texture_id[0], |
| 113 handle.parent_texture_id[1]); | 99 handle.parent_texture_id[1]); |
| 114 } | 100 } |
| 115 | 101 |
| 116 } // namespace content | 102 } // namespace content |
| OLD | NEW |