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 dc21f2d5fcc6597bc3be170339273dfce4dd7607..3c476baed9a2f3ce70d1d162c7e82910a4f08c68 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,18 @@ |
#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" |
+ |
+ |
+namespace gfx { |
+class JavaBitmap; |
+} |
namespace { |
@@ -172,6 +182,57 @@ 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, |
+ GL_ETC1_RGB8_OES, |
+ size.width(), |
+ size.height(), |
+ 0, |
+ data_size, |
+ data); |
+ DCHECK(context->getError() == GL_NO_ERROR); |
+ return texture_id; |
+} |
+ |
+void CompositorImpl::DeleteTexture(WebKit::WebGLId texture_id) { |
+ WebKit::WebGraphicsContext3D* context = |
+ ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
+ if (context->isContextLost()) |
+ return; |
+ context->deleteTexture(texture_id); |
+ DCHECK(context->getError() == GL_NO_ERROR); |
+} |
+ |
void CompositorImpl::updateAnimations(double frameBeginTime) { |
} |
@@ -221,4 +282,54 @@ void CompositorImpl::scheduleComposite() { |
client_->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 |