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/image_transport_factory_android.h" | 5 #include "content/browser/renderer_host/image_transport_factory_android.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 8 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
9 #include "content/browser/renderer_host/compositor_impl_android.h" | 9 #include "content/browser/renderer_host/compositor_impl_android.h" |
10 #include "content/common/gpu/gpu_process_launch_causes.h" | 10 #include "content/common/gpu/gpu_process_launch_causes.h" |
11 #include "content/common/gpu/client/gl_helper.h" | 11 #include "content/common/gpu/client/gl_helper.h" |
12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
14 #include "third_party/khronos/GLES2/gl2.h" | |
15 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" | 14 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
16 | 15 |
17 namespace content { | 16 namespace content { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 static ImageTransportFactoryAndroid* g_factory = NULL; | 20 static ImageTransportFactoryAndroid* g_factory = NULL; |
22 | 21 |
23 class DirectGLImageTransportFactory : public ImageTransportFactoryAndroid { | 22 class DirectGLImageTransportFactory : public ImageTransportFactoryAndroid { |
24 public: | 23 public: |
25 DirectGLImageTransportFactory(); | 24 DirectGLImageTransportFactory(); |
26 virtual ~DirectGLImageTransportFactory(); | 25 virtual ~DirectGLImageTransportFactory(); |
27 | 26 |
28 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { | 27 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { |
29 return gfx::GLSurfaceHandle(); | 28 return gfx::GLSurfaceHandle(); |
30 } | 29 } |
31 virtual void DestroySharedSurfaceHandle( | 30 virtual void DestroySharedSurfaceHandle( |
32 const gfx::GLSurfaceHandle& handle) OVERRIDE {} | 31 const gfx::GLSurfaceHandle& handle) OVERRIDE {} |
33 virtual uint32_t InsertSyncPoint() OVERRIDE { return 0; } | 32 virtual uint32_t InsertSyncPoint() OVERRIDE { return 0; } |
34 virtual uint32_t CreateTexture() OVERRIDE { | |
35 return context_->createTexture(); | |
36 } | |
37 virtual void DeleteTexture(uint32_t id) OVERRIDE { | |
38 context_->deleteTexture(id); | |
39 } | |
40 virtual void AcquireTexture( | |
41 uint32 texture_id, const signed char* mailbox_name) OVERRIDE {} | |
42 virtual void ReleaseTexture( | |
43 uint32 texture_id, const signed char* mailbox_name) OVERRIDE {} | |
44 virtual WebKit::WebGraphicsContext3D* GetContext3D() OVERRIDE { | 33 virtual WebKit::WebGraphicsContext3D* GetContext3D() OVERRIDE { |
45 return context_.get(); | 34 return context_.get(); |
46 } | 35 } |
47 virtual GLHelper* GetGLHelper() OVERRIDE { return NULL; } | 36 virtual GLHelper* GetGLHelper() OVERRIDE { return NULL; } |
48 | 37 |
49 private: | 38 private: |
50 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context_; | 39 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessImpl> context_; |
51 | 40 |
52 DISALLOW_COPY_AND_ASSIGN(DirectGLImageTransportFactory); | 41 DISALLOW_COPY_AND_ASSIGN(DirectGLImageTransportFactory); |
53 }; | 42 }; |
(...skipping 14 matching lines...) Expand all Loading... |
68 | 57 |
69 class CmdBufferImageTransportFactory : public ImageTransportFactoryAndroid { | 58 class CmdBufferImageTransportFactory : public ImageTransportFactoryAndroid { |
70 public: | 59 public: |
71 CmdBufferImageTransportFactory(); | 60 CmdBufferImageTransportFactory(); |
72 virtual ~CmdBufferImageTransportFactory(); | 61 virtual ~CmdBufferImageTransportFactory(); |
73 | 62 |
74 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE; | 63 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE; |
75 virtual void DestroySharedSurfaceHandle( | 64 virtual void DestroySharedSurfaceHandle( |
76 const gfx::GLSurfaceHandle& handle) OVERRIDE; | 65 const gfx::GLSurfaceHandle& handle) OVERRIDE; |
77 virtual uint32_t InsertSyncPoint() OVERRIDE; | 66 virtual uint32_t InsertSyncPoint() OVERRIDE; |
78 virtual uint32_t CreateTexture() OVERRIDE; | |
79 virtual void DeleteTexture(uint32_t id) OVERRIDE; | |
80 virtual void AcquireTexture( | |
81 uint32 texture_id, const signed char* mailbox_name) OVERRIDE; | |
82 virtual void ReleaseTexture( | |
83 uint32 texture_id, const signed char* mailbox_name) OVERRIDE; | |
84 virtual WebKit::WebGraphicsContext3D* GetContext3D() OVERRIDE { | 67 virtual WebKit::WebGraphicsContext3D* GetContext3D() OVERRIDE { |
85 return context_.get(); | 68 return context_.get(); |
86 } | 69 } |
87 virtual GLHelper* GetGLHelper() OVERRIDE; | 70 virtual GLHelper* GetGLHelper() OVERRIDE; |
88 | 71 |
89 private: | 72 private: |
90 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_; | 73 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_; |
91 scoped_ptr<GLHelper> gl_helper_; | 74 scoped_ptr<GLHelper> gl_helper_; |
92 | 75 |
93 DISALLOW_COPY_AND_ASSIGN(CmdBufferImageTransportFactory); | 76 DISALLOW_COPY_AND_ASSIGN(CmdBufferImageTransportFactory); |
(...skipping 21 matching lines...) Expand all Loading... |
115 gfx::GLSurfaceHandle | 98 gfx::GLSurfaceHandle |
116 CmdBufferImageTransportFactory::CreateSharedSurfaceHandle() { | 99 CmdBufferImageTransportFactory::CreateSharedSurfaceHandle() { |
117 if (!context_->makeContextCurrent()) { | 100 if (!context_->makeContextCurrent()) { |
118 NOTREACHED() << "Failed to make shared graphics context current"; | 101 NOTREACHED() << "Failed to make shared graphics context current"; |
119 return gfx::GLSurfaceHandle(); | 102 return gfx::GLSurfaceHandle(); |
120 } | 103 } |
121 | 104 |
122 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 105 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
123 gfx::kNullPluginWindow, true); | 106 gfx::kNullPluginWindow, true); |
124 handle.parent_gpu_process_id = context_->GetGPUProcessID(); | 107 handle.parent_gpu_process_id = context_->GetGPUProcessID(); |
| 108 handle.parent_client_id = context_->GetChannelID(); |
| 109 handle.parent_context_id = context_->GetContextID(); |
| 110 handle.parent_texture_id[0] = context_->createTexture(); |
| 111 handle.parent_texture_id[1] = context_->createTexture(); |
| 112 handle.sync_point = context_->insertSyncPoint(); |
125 context_->flush(); | 113 context_->flush(); |
126 return handle; | 114 return handle; |
127 } | 115 } |
128 | 116 |
129 void CmdBufferImageTransportFactory::DestroySharedSurfaceHandle( | 117 void CmdBufferImageTransportFactory::DestroySharedSurfaceHandle( |
130 const gfx::GLSurfaceHandle& handle) { | 118 const gfx::GLSurfaceHandle& handle) { |
131 if (!context_->makeContextCurrent()) { | 119 if (!context_->makeContextCurrent()) { |
132 NOTREACHED() << "Failed to make shared graphics context current"; | 120 NOTREACHED() << "Failed to make shared graphics context current"; |
133 return; | 121 return; |
134 } | 122 } |
| 123 |
| 124 context_->deleteTexture(handle.parent_texture_id[0]); |
| 125 context_->deleteTexture(handle.parent_texture_id[1]); |
| 126 context_->finish(); |
135 } | 127 } |
136 | 128 |
137 uint32_t CmdBufferImageTransportFactory::InsertSyncPoint() { | 129 uint32_t CmdBufferImageTransportFactory::InsertSyncPoint() { |
138 return context_->insertSyncPoint(); | 130 return context_->insertSyncPoint(); |
139 } | 131 } |
140 | 132 |
141 uint32_t CmdBufferImageTransportFactory::CreateTexture() { | |
142 return context_->createTexture(); | |
143 } | |
144 | |
145 void CmdBufferImageTransportFactory::DeleteTexture(uint32_t id) { | |
146 context_->deleteTexture(id); | |
147 } | |
148 | |
149 void CmdBufferImageTransportFactory::AcquireTexture( | |
150 uint32 texture_id, const signed char* mailbox_name) { | |
151 context_->bindTexture(GL_TEXTURE_2D, texture_id); | |
152 context_->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_name); | |
153 context_->flush(); | |
154 } | |
155 | |
156 void CmdBufferImageTransportFactory::ReleaseTexture( | |
157 uint32 texture_id, const signed char* mailbox_name) { | |
158 context_->bindTexture(GL_TEXTURE_2D, texture_id); | |
159 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox_name); | |
160 } | |
161 | |
162 GLHelper* CmdBufferImageTransportFactory::GetGLHelper() { | 133 GLHelper* CmdBufferImageTransportFactory::GetGLHelper() { |
163 if (!gl_helper_.get()) | 134 if (!gl_helper_.get()) |
164 gl_helper_.reset(new GLHelper(GetContext3D(), NULL)); | 135 gl_helper_.reset(new GLHelper(GetContext3D(), NULL)); |
165 | 136 |
166 return gl_helper_.get(); | 137 return gl_helper_.get(); |
167 } | 138 } |
168 | 139 |
169 } // anonymous namespace | 140 } // anonymous namespace |
170 | 141 |
171 // static | 142 // static |
172 ImageTransportFactoryAndroid* ImageTransportFactoryAndroid::GetInstance() { | 143 ImageTransportFactoryAndroid* ImageTransportFactoryAndroid::GetInstance() { |
173 if (!g_factory) { | 144 if (!g_factory) { |
174 if (CompositorImpl::UsesDirectGL()) | 145 if (CompositorImpl::UsesDirectGL()) |
175 g_factory = new DirectGLImageTransportFactory(); | 146 g_factory = new DirectGLImageTransportFactory(); |
176 else | 147 else |
177 g_factory = new CmdBufferImageTransportFactory(); | 148 g_factory = new CmdBufferImageTransportFactory(); |
178 } | 149 } |
179 | 150 |
180 return g_factory; | 151 return g_factory; |
181 } | 152 } |
182 | 153 |
183 ImageTransportFactoryAndroid::ImageTransportFactoryAndroid() { | 154 ImageTransportFactoryAndroid::ImageTransportFactoryAndroid() { |
184 } | 155 } |
185 | 156 |
186 ImageTransportFactoryAndroid::~ImageTransportFactoryAndroid() { | 157 ImageTransportFactoryAndroid::~ImageTransportFactoryAndroid() { |
187 } | 158 } |
188 | 159 |
189 } // namespace content | 160 } // namespace content |
OLD | NEW |