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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/compositor_impl_android.cc
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc
index 5da1a65de7722ce93ecccc37caf2842bc74b0706..b38a7bc6c6e851378e5db1d6c9d9fa766722a8bb 100644
--- a/content/browser/renderer_host/compositor_impl_android.cc
+++ b/content/browser/renderer_host/compositor_impl_android.cc
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/compositor_impl_android.h"
+#include <android/bitmap.h>
#include <android/native_window_jni.h>
#include "base/bind.h"
@@ -16,9 +17,21 @@
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
#include "content/common/gpu/gpu_process_launch_causes.h"
#include "content/public/common/content_switches.h"
+#include "third_party/khronos/GLES2/gl2.h"
+#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSupport.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
+#include "ui/gfx/android/java_bitmap.h"
+
+#ifndef ETC1_RGB8_OES
+#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.
+#endif
+
+namespace gfx {
+class JavaBitmap;
+}
namespace {
@@ -175,6 +188,58 @@ bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) {
return false;
}
+WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) {
+ unsigned int texture_id = BuildBasicTexture();
+ WebKit::WebGraphicsContext3D* context =
+ ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
+ if (texture_id == 0 || context->isContextLost())
+ return 0;
+ WebKit::WebGLId format = GetGLFormatForBitmap(bitmap);
+ WebKit::WebGLId type = GetGLTypeForBitmap(bitmap);
+
+ context->texImage2D(GL_TEXTURE_2D,
+ 0,
+ format,
+ bitmap.size().width(),
+ bitmap.size().height(),
+ 0,
+ format,
+ type,
+ bitmap.pixels());
+ DCHECK(context->getError() == GL_NO_ERROR);
+ return texture_id;
+}
+
+WebKit::WebGLId CompositorImpl::GenerateCompressedTexture(gfx::Size& size,
+ int data_size,
+ void* data) {
+ unsigned int texture_id = BuildBasicTexture();
+ WebKit::WebGraphicsContext3D* context =
+ ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
+ if (texture_id == 0 || context->isContextLost())
+ return 0;
+ context->compressedTexImage2D(GL_TEXTURE_2D,
+ 0,
+ ETC1_RGB8_OES,
+ size.width(),
+ size.height(),
+ 0,
+ data_size,
+ data);
+ DCHECK(context->getError() == GL_NO_ERROR);
+ return texture_id;
+}
+
+bool CompositorImpl::DeleteTexture(WebKit::WebGLId texture_id) {
+ WebKit::WebGraphicsContext3D* context =
+ ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
+ if (context->isContextLost())
+ return false;
+ context->deleteTexture(texture_id);
+ DCHECK(context->getError() == GL_NO_ERROR);
+ return true;
+}
+
void CompositorImpl::updateAnimations(double frameBeginTime) {
}
@@ -223,4 +288,54 @@ void CompositorImpl::didCompleteSwapBuffers() {
void CompositorImpl::scheduleComposite() {
}
+WebKit::WebGLId CompositorImpl::BuildBasicTexture() {
+ WebKit::WebGraphicsContext3D* context =
+ ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
+ if (context->isContextLost())
+ return 0;
+ WebKit::WebGLId texture_id = context->createTexture();
+ context->bindTexture(GL_TEXTURE_2D, texture_id);
+ context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ DCHECK(context->getError() == GL_NO_ERROR);
+ return texture_id;
+}
+
+WebKit::WGC3Denum CompositorImpl::GetGLFormatForBitmap(
+ gfx::JavaBitmap& bitmap) {
+ switch (bitmap.format()) {
+ case ANDROID_BITMAP_FORMAT_A_8:
+ return GL_ALPHA;
+ break;
+ case ANDROID_BITMAP_FORMAT_RGBA_4444:
+ return GL_RGBA;
+ break;
+ case ANDROID_BITMAP_FORMAT_RGBA_8888:
+ return GL_RGBA;
+ break;
+ case ANDROID_BITMAP_FORMAT_RGB_565:
+ default:
+ return GL_RGB;
+ }
+}
+
+WebKit::WGC3Denum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) {
+ switch (bitmap.format()) {
+ case ANDROID_BITMAP_FORMAT_A_8:
+ return GL_UNSIGNED_BYTE;
+ break;
+ case ANDROID_BITMAP_FORMAT_RGBA_4444:
+ return GL_UNSIGNED_SHORT_4_4_4_4;
+ break;
+ case ANDROID_BITMAP_FORMAT_RGBA_8888:
+ return GL_UNSIGNED_BYTE;
+ break;
+ case ANDROID_BITMAP_FORMAT_RGB_565:
+ default:
+ return GL_UNSIGNED_SHORT_5_6_5;
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698