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

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: Expose destroy/create texture methods instead of the context 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 #ifndef ETC1_RGB8_OES
29 #define ETC1_RGB8_OES 0x8D64
no sievers 2012/10/12 22:45:56 you should not need this.
David Trainor- moved to gerrit 2012/10/15 19:01:56 Done.
30 #endif
31
32 namespace gfx {
33 class JavaBitmap;
34 }
22 35
23 namespace { 36 namespace {
24 37
25 static bool g_initialized = false; 38 static bool g_initialized = false;
26 39
27 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. 40 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface.
28 class WebGraphicsContextToOutputSurfaceAdapter : 41 class WebGraphicsContextToOutputSurfaceAdapter :
29 public WebKit::WebCompositorOutputSurface { 42 public WebKit::WebCompositorOutputSurface {
30 public: 43 public:
31 explicit WebGraphicsContextToOutputSurfaceAdapter( 44 explicit WebGraphicsContextToOutputSurfaceAdapter(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 root_layer_->setBounds(size); 181 root_layer_->setBounds(size);
169 } 182 }
170 183
171 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { 184 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) {
172 if (host_.get()) 185 if (host_.get())
173 return host_->compositeAndReadback(pixels, rect); 186 return host_->compositeAndReadback(pixels, rect);
174 else 187 else
175 return false; 188 return false;
176 } 189 }
177 190
191 WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) {
192 unsigned int texture_id = BuildBasicTexture();
193 WebKit::WebGraphicsContext3D* context =
194 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
195 if (texture_id == 0 || context->isContextLost())
196 return 0;
197 WebKit::WebGLId format = GetGLFormatForBitmap(bitmap);
198 WebKit::WebGLId type = GetGLTypeForBitmap(bitmap);
199
200 context->texImage2D(GL_TEXTURE_2D,
201 0,
202 format,
203 bitmap.size().width(),
204 bitmap.size().height(),
205 0,
206 format,
207 type,
208 bitmap.pixels());
209 DCHECK(context->getError() == GL_NO_ERROR);
210 return texture_id;
211 }
212
213 WebKit::WebGLId CompositorImpl::GenerateCompressedTexture(gfx::Size& size,
214 int data_size,
215 void* data) {
216 unsigned int texture_id = BuildBasicTexture();
217 WebKit::WebGraphicsContext3D* context =
218 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
219 if (texture_id == 0 || context->isContextLost())
220 return 0;
221 context->compressedTexImage2D(GL_TEXTURE_2D,
222 0,
223 ETC1_RGB8_OES,
224 size.width(),
225 size.height(),
226 0,
227 data_size,
228 data);
229 DCHECK(context->getError() == GL_NO_ERROR);
230 return texture_id;
231 }
232
233 bool CompositorImpl::DeleteTexture(WebKit::WebGLId texture_id) {
234 WebKit::WebGraphicsContext3D* context =
235 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
236 if (context->isContextLost())
237 return false;
238 context->deleteTexture(texture_id);
239 DCHECK(context->getError() == GL_NO_ERROR);
240 return true;
241 }
242
178 void CompositorImpl::updateAnimations(double frameBeginTime) { 243 void CompositorImpl::updateAnimations(double frameBeginTime) {
179 } 244 }
180 245
181 void CompositorImpl::layout() { 246 void CompositorImpl::layout() {
182 } 247 }
183 248
184 void CompositorImpl::applyScrollAndScale(const WebKit::WebSize& scrollDelta, 249 void CompositorImpl::applyScrollAndScale(const WebKit::WebSize& scrollDelta,
185 float scaleFactor) { 250 float scaleFactor) {
186 } 251 }
187 252
(...skipping 28 matching lines...) Expand all
216 281
217 void CompositorImpl::didCommitAndDrawFrame() { 282 void CompositorImpl::didCommitAndDrawFrame() {
218 } 283 }
219 284
220 void CompositorImpl::didCompleteSwapBuffers() { 285 void CompositorImpl::didCompleteSwapBuffers() {
221 } 286 }
222 287
223 void CompositorImpl::scheduleComposite() { 288 void CompositorImpl::scheduleComposite() {
224 } 289 }
225 290
291 WebKit::WebGLId CompositorImpl::BuildBasicTexture() {
292 WebKit::WebGraphicsContext3D* context =
293 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
294 if (context->isContextLost())
295 return 0;
296 WebKit::WebGLId texture_id = context->createTexture();
297 context->bindTexture(GL_TEXTURE_2D, texture_id);
298 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
299 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
300 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
301 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
302 DCHECK(context->getError() == GL_NO_ERROR);
303 return texture_id;
304 }
305
306 WebKit::WGC3Denum CompositorImpl::GetGLFormatForBitmap(
307 gfx::JavaBitmap& bitmap) {
308 switch (bitmap.format()) {
309 case ANDROID_BITMAP_FORMAT_A_8:
310 return GL_ALPHA;
311 break;
312 case ANDROID_BITMAP_FORMAT_RGBA_4444:
313 return GL_RGBA;
314 break;
315 case ANDROID_BITMAP_FORMAT_RGBA_8888:
316 return GL_RGBA;
317 break;
318 case ANDROID_BITMAP_FORMAT_RGB_565:
319 default:
320 return GL_RGB;
321 }
322 }
323
324 WebKit::WGC3Denum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) {
325 switch (bitmap.format()) {
326 case ANDROID_BITMAP_FORMAT_A_8:
327 return GL_UNSIGNED_BYTE;
328 break;
329 case ANDROID_BITMAP_FORMAT_RGBA_4444:
330 return GL_UNSIGNED_SHORT_4_4_4_4;
331 break;
332 case ANDROID_BITMAP_FORMAT_RGBA_8888:
333 return GL_UNSIGNED_BYTE;
334 break;
335 case ANDROID_BITMAP_FORMAT_RGB_565:
336 default:
337 return GL_UNSIGNED_SHORT_5_6_5;
338 }
339 }
340
226 } // namespace content 341 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698