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

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

Issue 11090075: Expose the WebGraphicsContext3D for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 2 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/native_window_jni.h> 8 #include <android/native_window_jni.h>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 13 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
13 #include "content/browser/gpu/gpu_surface_tracker.h" 14 #include "content/browser/gpu/gpu_surface_tracker.h"
14 #include "content/browser/renderer_host/image_transport_factory_android.h" 15 #include "content/browser/renderer_host/image_transport_factory_android.h"
15 #include "content/common/gpu/client/gpu_channel_host.h" 16 #include "content/common/gpu/client/gpu_channel_host.h"
16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 17 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
17 #include "content/common/gpu/gpu_process_launch_causes.h" 18 #include "content/common/gpu/gpu_process_launch_causes.h"
18 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
20 #include "third_party/khronos/GLES2/gl2.h"
21 #include "third_party/khronos/GLES2/gl2ext.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" 22 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h" 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h"
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput Surface.h" 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput Surface.h"
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
26 #include "ui/gfx/android/java_bitmap.h"
27
28
29 namespace gfx {
30 class JavaBitmap;
31 }
22 32
23 namespace { 33 namespace {
24 34
25 static bool g_initialized = false; 35 static bool g_initialized = false;
26 36
27 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. 37 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface.
28 class WebGraphicsContextToOutputSurfaceAdapter : 38 class WebGraphicsContextToOutputSurfaceAdapter :
29 public WebKit::WebCompositorOutputSurface { 39 public WebKit::WebCompositorOutputSurface {
30 public: 40 public:
31 explicit WebGraphicsContextToOutputSurfaceAdapter( 41 explicit WebGraphicsContextToOutputSurfaceAdapter(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 root_layer_->setBounds(size); 175 root_layer_->setBounds(size);
166 } 176 }
167 177
168 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { 178 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) {
169 if (host_.get()) 179 if (host_.get())
170 return host_->compositeAndReadback(pixels, rect); 180 return host_->compositeAndReadback(pixels, rect);
171 else 181 else
172 return false; 182 return false;
173 } 183 }
174 184
185 WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) {
186 unsigned int texture_id = BuildBasicTexture();
187 WebKit::WebGraphicsContext3D* context =
188 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
189 if (texture_id == 0 || context->isContextLost())
190 return 0;
191 WebKit::WebGLId format = GetGLFormatForBitmap(bitmap);
192 WebKit::WebGLId type = GetGLTypeForBitmap(bitmap);
193
194 context->texImage2D(GL_TEXTURE_2D,
195 0,
196 format,
197 bitmap.size().width(),
198 bitmap.size().height(),
199 0,
200 format,
201 type,
202 bitmap.pixels());
203 DCHECK(context->getError() == GL_NO_ERROR);
204 return texture_id;
205 }
206
207 WebKit::WebGLId CompositorImpl::GenerateCompressedTexture(gfx::Size& size,
208 int data_size,
209 void* data) {
210 unsigned int texture_id = BuildBasicTexture();
211 WebKit::WebGraphicsContext3D* context =
212 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
213 if (texture_id == 0 || context->isContextLost())
214 return 0;
215 context->compressedTexImage2D(GL_TEXTURE_2D,
216 0,
217 GL_ETC1_RGB8_OES,
218 size.width(),
219 size.height(),
220 0,
221 data_size,
222 data);
223 DCHECK(context->getError() == GL_NO_ERROR);
224 return texture_id;
225 }
226
227 void CompositorImpl::DeleteTexture(WebKit::WebGLId texture_id) {
228 WebKit::WebGraphicsContext3D* context =
229 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
230 if (context->isContextLost())
231 return;
232 context->deleteTexture(texture_id);
233 DCHECK(context->getError() == GL_NO_ERROR);
234 }
235
175 void CompositorImpl::updateAnimations(double frameBeginTime) { 236 void CompositorImpl::updateAnimations(double frameBeginTime) {
176 } 237 }
177 238
178 void CompositorImpl::layout() { 239 void CompositorImpl::layout() {
179 } 240 }
180 241
181 void CompositorImpl::applyScrollAndScale(const WebKit::WebSize& scrollDelta, 242 void CompositorImpl::applyScrollAndScale(const WebKit::WebSize& scrollDelta,
182 float scaleFactor) { 243 float scaleFactor) {
183 } 244 }
184 245
(...skipping 29 matching lines...) Expand all
214 void CompositorImpl::didCommitAndDrawFrame() { 275 void CompositorImpl::didCommitAndDrawFrame() {
215 } 276 }
216 277
217 void CompositorImpl::didCompleteSwapBuffers() { 278 void CompositorImpl::didCompleteSwapBuffers() {
218 } 279 }
219 280
220 void CompositorImpl::scheduleComposite() { 281 void CompositorImpl::scheduleComposite() {
221 client_->ScheduleComposite(); 282 client_->ScheduleComposite();
222 } 283 }
223 284
285 WebKit::WebGLId CompositorImpl::BuildBasicTexture() {
286 WebKit::WebGraphicsContext3D* context =
287 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
288 if (context->isContextLost())
289 return 0;
290 WebKit::WebGLId texture_id = context->createTexture();
291 context->bindTexture(GL_TEXTURE_2D, texture_id);
292 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
293 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
294 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
295 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
296 DCHECK(context->getError() == GL_NO_ERROR);
297 return texture_id;
298 }
299
300 WebKit::WGC3Denum CompositorImpl::GetGLFormatForBitmap(
301 gfx::JavaBitmap& bitmap) {
302 switch (bitmap.format()) {
303 case ANDROID_BITMAP_FORMAT_A_8:
304 return GL_ALPHA;
305 break;
306 case ANDROID_BITMAP_FORMAT_RGBA_4444:
307 return GL_RGBA;
308 break;
309 case ANDROID_BITMAP_FORMAT_RGBA_8888:
310 return GL_RGBA;
311 break;
312 case ANDROID_BITMAP_FORMAT_RGB_565:
313 default:
314 return GL_RGB;
315 }
316 }
317
318 WebKit::WGC3Denum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) {
319 switch (bitmap.format()) {
320 case ANDROID_BITMAP_FORMAT_A_8:
321 return GL_UNSIGNED_BYTE;
322 break;
323 case ANDROID_BITMAP_FORMAT_RGBA_4444:
324 return GL_UNSIGNED_SHORT_4_4_4_4;
325 break;
326 case ANDROID_BITMAP_FORMAT_RGBA_8888:
327 return GL_UNSIGNED_BYTE;
328 break;
329 case ANDROID_BITMAP_FORMAT_RGB_565:
330 default:
331 return GL_UNSIGNED_SHORT_5_6_5;
332 }
333 }
334
224 } // namespace content 335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698