Commit 92fa4d29 authored by dtrainor@chromium.org's avatar dtrainor@chromium.org

Expose the WebGraphicsContext3D for Android

- Expose the WebGraphicsContext3D for Android's Compositor.

BUG=


Review URL: https://chromiumcodereview.appspot.com/11090075

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162231 0039d316-1c4b-4281-b951-d872f2087c98
parent 205f0789
......@@ -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
......@@ -13,6 +13,7 @@
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewClient.h"
struct ANativeWindow;
namespace content {
......@@ -36,6 +37,10 @@ class CompositorImpl : public Compositor,
virtual bool CompositeAndReadback(
void *pixels, const gfx::Rect& rect) OVERRIDE;
virtual void Composite() OVERRIDE;
virtual WebKit::WebGLId GenerateTexture(gfx::JavaBitmap& bitmap) OVERRIDE;
virtual WebKit::WebGLId GenerateCompressedTexture(
gfx::Size& size, int data_size, void* data) OVERRIDE;
virtual void DeleteTexture(WebKit::WebGLId texture_id) OVERRIDE;
// WebLayerTreeViewClient implementation.
virtual void updateAnimations(double frameBeginTime) OVERRIDE;
......@@ -50,6 +55,10 @@ class CompositorImpl : public Compositor,
virtual void scheduleComposite() OVERRIDE;
private:
WebKit::WebGLId BuildBasicTexture();
WebKit::WGC3Denum GetGLFormatForBitmap(gfx::JavaBitmap& bitmap);
WebKit::WGC3Denum GetGLTypeForBitmap(gfx::JavaBitmap& bitmap);
scoped_ptr<WebKit::WebLayer> root_layer_;
scoped_ptr<WebKit::WebLayerTreeView> host_;
......
......@@ -73,4 +73,9 @@ uint32_t ImageTransportFactoryAndroid::InsertSyncPoint() {
return context_->insertSyncPoint();
}
WebGraphicsContext3DCommandBufferImpl*
ImageTransportFactoryAndroid::GetContext3D() {
return context_.get();
}
} // namespace content
......@@ -24,6 +24,7 @@ class ImageTransportFactoryAndroid {
uint32_t InsertSyncPoint();
WebGraphicsContext3DCommandBufferImpl* GetContext3D();
private:
scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_;
};
......
......@@ -10,6 +10,12 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
namespace gfx {
class JavaBitmap;
}
namespace WebKit {
class WebLayer;
}
......@@ -51,6 +57,19 @@ class Compositor {
// Composite immediately. Used in single-threaded mode.
virtual void Composite() = 0;
// Generates an OpenGL texture and returns a texture handle. May return 0
// if the current context is lost.
virtual WebKit::WebGLId GenerateTexture(gfx::JavaBitmap& bitmap) = 0;
// Generates an OpenGL compressed texture and returns a texture handle. May
// return 0 if the current context is lost.
virtual WebKit::WebGLId GenerateCompressedTexture(gfx::Size& size,
int data_size,
void* data) = 0;
// Deletes an OpenGL texture.
virtual void DeleteTexture(WebKit::WebGLId texture_id) = 0;
protected:
Compositor() {}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment