summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp31
-rw-r--r--Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h1
-rw-r--r--Source/WebCore/platform/graphics/android/BaseTile.cpp20
-rw-r--r--Source/WebCore/platform/graphics/android/DoubleBufferedTexture.h3
-rw-r--r--Source/WebCore/platform/graphics/android/GLUtils.cpp127
-rw-r--r--Source/WebCore/platform/graphics/android/GLUtils.h10
-rw-r--r--Source/WebCore/platform/graphics/android/SharedTexture.cpp26
-rw-r--r--Source/WebCore/platform/graphics/android/TextureInfo.h3
8 files changed, 156 insertions, 65 deletions
diff --git a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp b/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp
index b24c806..0e22103 100644
--- a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp
+++ b/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp
@@ -41,7 +41,7 @@ namespace WebCore {
BackedDoubleBufferedTexture::BackedDoubleBufferedTexture(uint32_t w, uint32_t h,
SkBitmap* bitmap,
SkBitmap::Config config)
- : DoubleBufferedTexture(eglGetCurrentContext(), EglImageMode)
+ : DoubleBufferedTexture(eglGetCurrentContext(), SurfaceTextureMode)
, m_usedLevel(-1)
, m_config(config)
, m_owner(0)
@@ -82,8 +82,10 @@ BackedDoubleBufferedTexture::~BackedDoubleBufferedTexture()
if (!m_sharedBitmap)
delete m_bitmap;
delete m_canvas;
- SharedTexture* textures[3] = { m_textureA, m_textureB, 0 };
- destroyTextures(textures);
+ if (m_sharedTextureMode == EglImageMode) {
+ SharedTexture* textures[3] = { m_textureA, m_textureB, 0 };
+ destroyTextures(textures);
+ }
#ifdef DEBUG_COUNT
ClassTracker::instance()->decrement("BackedDoubleBufferedTexture");
#endif
@@ -146,21 +148,6 @@ bool BackedDoubleBufferedTexture::busy()
return m_busy;
}
-bool BackedDoubleBufferedTexture::textureExist(TextureInfo* textureInfo)
-{
- if (!m_bitmap)
- return false;
-
- if (!m_bitmap->width() || !m_bitmap->height())
- return false;
-
- if (textureInfo->m_width == m_bitmap->width() &&
- textureInfo->m_height == m_bitmap->height())
- return true;
-
- return false;
-}
-
void BackedDoubleBufferedTexture::producerUpdate(TextureInfo* textureInfo)
{
if (!m_bitmap)
@@ -172,13 +159,7 @@ void BackedDoubleBufferedTexture::producerUpdate(TextureInfo* textureInfo)
return;
}
- if (textureExist(textureInfo))
- GLUtils::updateTextureWithBitmap(textureInfo->m_textureId, *m_bitmap);
- else {
- GLUtils::createTextureWithBitmap(textureInfo->m_textureId, *m_bitmap);
- textureInfo->m_width = m_bitmap->width();
- textureInfo->m_height = m_bitmap->height();
- }
+ GLUtils::paintTextureWithBitmap(textureInfo, m_bitmap, 0, 0, this);
if (!m_sharedBitmap) {
delete m_bitmap;
diff --git a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h b/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h
index 7c2ea90..89ea771 100644
--- a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h
+++ b/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h
@@ -75,7 +75,6 @@ public:
// swaps) the texture.
virtual void producerUpdate(TextureInfo* textureInfo);
void producerUpdate(TextureInfo* textureInfo, SkBitmap* bitmap, SkIRect& rect);
- bool textureExist(TextureInfo* textureInfo);
// The level can be one of the following values:
// * -1 for an unused texture.
diff --git a/Source/WebCore/platform/graphics/android/BaseTile.cpp b/Source/WebCore/platform/graphics/android/BaseTile.cpp
index 03f180e..35ebf13 100644
--- a/Source/WebCore/platform/graphics/android/BaseTile.cpp
+++ b/Source/WebCore/platform/graphics/android/BaseTile.cpp
@@ -449,7 +449,9 @@ int BaseTile::paintPartialBitmap(SkIRect r, float ptx, float pty,
SkIRect rect = r;
float tx = ptx;
float ty = pty;
- if (!texture->textureExist(textureInfo)) {
+ // TODO: Implement the partial invalidate in Surface Texture Mode
+ if (!GLUtils::textureExist(textureInfo, texture->bitmap())
+ || textureInfo->getSharedTextureMode() == SurfaceTextureMode) {
fullRepaint = true;
}
@@ -517,17 +519,11 @@ int BaseTile::paintPartialBitmap(SkIRect r, float ptx, float pty,
drawTileInfo(&canvas, texture, x(), y(), scale, pictureCount);
}
- if (!texture->textureExist(textureInfo)) {
- GLUtils::createTextureWithBitmap(textureInfo->m_textureId, bitmap);
- textureInfo->m_width = rect.width();
- textureInfo->m_height = rect.height();
- } else {
- if (measurePerf)
- m_perfMon.start(TAG_UPDATE_TEXTURE);
- GLUtils::updateTextureWithBitmap(textureInfo->m_textureId, rect.fLeft, rect.fTop, bitmap);
- if (measurePerf)
- m_perfMon.stop(TAG_UPDATE_TEXTURE);
- }
+ if (measurePerf)
+ m_perfMon.start(TAG_UPDATE_TEXTURE);
+ GLUtils::paintTextureWithBitmap(textureInfo, &bitmap, rect.fLeft, rect.fTop, texture);
+ if (measurePerf)
+ m_perfMon.stop(TAG_UPDATE_TEXTURE);
if (measurePerf)
m_perfMon.start(TAG_RESET_BITMAP);
diff --git a/Source/WebCore/platform/graphics/android/DoubleBufferedTexture.h b/Source/WebCore/platform/graphics/android/DoubleBufferedTexture.h
index 57935d3..821b79b 100644
--- a/Source/WebCore/platform/graphics/android/DoubleBufferedTexture.h
+++ b/Source/WebCore/platform/graphics/android/DoubleBufferedTexture.h
@@ -56,6 +56,7 @@ protected:
SharedTexture* m_textureA;
SharedTexture* m_textureB;
+ SharedTextureMode m_sharedTextureMode;
private:
SharedTexture* m_writeableTexture;
@@ -66,8 +67,6 @@ private:
EGLContext m_cContext;
bool m_supportsEGLImage;
-
- SharedTextureMode m_sharedTextureMode;
};
} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/android/GLUtils.cpp b/Source/WebCore/platform/graphics/android/GLUtils.cpp
index 5eabb85..a7ddbbd 100644
--- a/Source/WebCore/platform/graphics/android/GLUtils.cpp
+++ b/Source/WebCore/platform/graphics/android/GLUtils.cpp
@@ -31,12 +31,15 @@
#include "ShaderProgram.h"
#include <cutils/log.h>
+#include <gui/SurfaceTexture.h>
#include <wtf/CurrentTime.h>
#include <wtf/text/CString.h>
#undef XLOG
#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GLUtils", __VA_ARGS__)
+struct ANativeWindowBuffer;
+
namespace WebCore {
using namespace android;
@@ -140,6 +143,11 @@ bool GLUtils::checkGlErrorOn(void* p, const char* op)
return ret;
}
+void GLUtils::checkSurfaceTextureError(const char* functionName, int status)
+{
+ if (status != NO_ERROR)
+ XLOG("ERROR at calling %s status is (%d)", functionName, status);
+}
/////////////////////////////////////////////////////////////////////////////////////////
// GL & EGL extension checks
/////////////////////////////////////////////////////////////////////////////////////////
@@ -328,6 +336,104 @@ GLuint GLUtils::createSampleTexture()
return texture;
}
+bool GLUtils::textureExist(TextureInfo* textureInfo, const SkBitmap* bitmap)
+{
+ if (!bitmap)
+ return false;
+
+ if (!bitmap->width() || !bitmap->height())
+ return false;
+
+ if (textureInfo->m_width == bitmap->width()
+ && textureInfo->m_height == bitmap->height())
+ return true;
+
+ return false;
+}
+
+void GLUtils::paintTextureWithBitmap(TextureInfo* textureInfo,
+ SkBitmap* bitmap,
+ int x,
+ int y,
+ BackedDoubleBufferedTexture* texture)
+{
+ SharedTextureMode mode = textureInfo->getSharedTextureMode();
+ if (textureExist(textureInfo, texture->bitmap())) {
+ if (mode == EglImageMode)
+ GLUtils::updateTextureWithBitmap(textureInfo->m_textureId, x, y, *bitmap);
+ else if (mode == SurfaceTextureMode)
+ GLUtils::updateSurfaceTextureWithBitmap(textureInfo, x, y, *bitmap);
+ } else {
+ if (mode == EglImageMode)
+ GLUtils::createTextureWithBitmap(textureInfo->m_textureId, *bitmap);
+ else if (mode == SurfaceTextureMode)
+ GLUtils::createSurfaceTextureWithBitmap(textureInfo, *bitmap);
+
+ textureInfo->m_width = bitmap->width();
+ textureInfo->m_height = bitmap->height();
+ }
+}
+
+void GLUtils::createSurfaceTextureWithBitmap(TextureInfo* texture, SkBitmap& bitmap, GLint filter)
+{
+ sp<android::SurfaceTexture> surfaceTexture = texture->m_surfaceTexture;
+ sp<ANativeWindow> ANW = texture->m_ANW;
+
+ texture->m_width = bitmap.width();
+ texture->m_height = bitmap.height();
+ texture->m_internalFormat = GL_RGBA;
+
+ int result;
+ result = native_window_set_buffers_geometry(ANW.get(),
+ texture->m_width, texture->m_height, HAL_PIXEL_FORMAT_RGBA_8888);
+ checkSurfaceTextureError("native_window_set_buffers_geometry", result);
+ result = native_window_set_usage(ANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
+ checkSurfaceTextureError("native_window_set_usage", result);
+
+ updateSurfaceTextureWithBitmap(texture, 0, 0, bitmap, filter);
+}
+
+void GLUtils::updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, SkBitmap& bitmap, GLint filter)
+{
+ sp<android::SurfaceTexture> surfaceTexture = texture->m_surfaceTexture;
+ sp<ANativeWindow> ANW = texture->m_ANW;
+
+ ANativeWindowBuffer* anb;
+ int status = ANW->dequeueBuffer(ANW.get(), &anb);
+ checkSurfaceTextureError("dequeueBuffer", status);
+
+ sp<android::GraphicBuffer> buf(new android::GraphicBuffer(anb, false));
+ status |= ANW->lockBuffer(ANW.get(), buf->getNativeBuffer());
+ checkSurfaceTextureError("lockBuffer", status);
+
+ // Fill the buffer with the content of the bitmap
+ uint8_t* img = 0;
+ status |= buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+ checkSurfaceTextureError("lock", status);
+
+ if (status == NO_ERROR) {
+ int row, col;
+ int bpp = 4; // Now only deal with RGBA8888 format.
+
+ bitmap.lockPixels();
+ uint8_t* bitmapOrigin = static_cast<uint8_t*>(bitmap.getPixels());
+
+ // Copied pixel by pixel since we need to handle the offsets and stride.
+ for (row = 0 ; row < bitmap.height(); row ++) {
+ for (col = 0 ; col < bitmap.width(); col ++) {
+ uint8_t* dst = &(img[(buf->getStride() * (row + x) + (col + y)) * bpp]);
+ uint8_t* src = &(bitmapOrigin[(bitmap.width() * row + col) * bpp]);
+ memcpy(dst, src, bpp);
+ }
+ }
+ bitmap.unlockPixels();
+ }
+ buf->unlock();
+ status = ANW->queueBuffer(ANW.get(), buf->getNativeBuffer());
+ checkSurfaceTextureError("queueBuffer", status);
+}
+
void GLUtils::createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint filter)
{
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -359,27 +465,6 @@ void GLUtils::createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint fi
glDeleteFramebuffers(1, &fboID);
}
-void GLUtils::updateTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint filter)
-{
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glBindTexture(GL_TEXTURE_2D, texture);
- GLUtils::checkGlError("glBindTexture");
- SkBitmap::Config config = bitmap.getConfig();
- int internalformat = getInternalFormat(config);
- int type = getType(config);
- bitmap.lockPixels();
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap.width(), bitmap.height(),
- internalformat, type, bitmap.getPixels());
- bitmap.unlockPixels();
- if (GLUtils::checkGlError("glTexSubImage2D")) {
- XLOG("GL ERROR: glTexSubImage2D parameters are : bitmap.width() %d, bitmap.height() %d,"
- " internalformat 0x%x, type 0x%x, bitmap.getPixels() %p",
- bitmap.width(), bitmap.height(), internalformat, type, bitmap.getPixels());
- }
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
-}
-
void GLUtils::updateTextureWithBitmap(GLuint texture, int x, int y, SkBitmap& bitmap, GLint filter)
{
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
diff --git a/Source/WebCore/platform/graphics/android/GLUtils.h b/Source/WebCore/platform/graphics/android/GLUtils.h
index 1e8df39..85656f1 100644
--- a/Source/WebCore/platform/graphics/android/GLUtils.h
+++ b/Source/WebCore/platform/graphics/android/GLUtils.h
@@ -28,8 +28,10 @@
#if USE(ACCELERATED_COMPOSITING)
+#include "BackedDoubleBufferedTexture.h"
#include "SkBitmap.h"
#include "SkMatrix.h"
+#include "TextureInfo.h"
#include "TransformationMatrix.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
@@ -51,6 +53,7 @@ public:
static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE);
static bool checkGlErrorOn(void* p, const char* op);
static bool checkGlError(const char* op);
+ static void checkSurfaceTextureError(const char* functionName, int status);
// GL & EGL extension checks
static bool isEGLImageSupported();
@@ -62,10 +65,15 @@ public:
static GLuint createSampleColorTexture(int r, int g, int b);
static GLuint createSampleTexture();
static void createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint filter = GL_LINEAR);
- static void updateTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint filter = GL_LINEAR);
static void updateTextureWithBitmap(GLuint texture, int x, int y, SkBitmap& bitmap, GLint filter = GL_LINEAR);
static void createEGLImageFromTexture(GLuint texture, EGLImageKHR* image);
static void createTextureFromEGLImage(GLuint texture, EGLImageKHR image, GLint filter = GL_LINEAR);
+
+ static bool textureExist(TextureInfo* textureInfo, const SkBitmap* bitmap);
+ static void paintTextureWithBitmap(TextureInfo* textureInfo, SkBitmap* bitmap, int x, int y, BackedDoubleBufferedTexture* texture);
+
+ static void createSurfaceTextureWithBitmap(TextureInfo* texture, SkBitmap& bitmap, GLint filter = GL_LINEAR);
+ static void updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, SkBitmap& bitmap, GLint filter = GL_LINEAR);
};
} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/android/SharedTexture.cpp b/Source/WebCore/platform/graphics/android/SharedTexture.cpp
index 6df37a0..5f1cd77 100644
--- a/Source/WebCore/platform/graphics/android/SharedTexture.cpp
+++ b/Source/WebCore/platform/graphics/android/SharedTexture.cpp
@@ -27,7 +27,9 @@
#include "SharedTexture.h"
#include "GLUtils.h"
+#include <android/native_window.h>
#include <gui/SurfaceTexture.h>
+#include <gui/SurfaceTextureClient.h>
#define LOG_NDEBUG 1
#define LOG_TAG "SharedTexture.cpp"
@@ -54,6 +56,15 @@ SharedTexture::SharedTexture(SharedTextureMode mode)
m_display = 0;
m_supportsEGLImage = false;
m_supportsEGLFenceSyncKHR = false;
+ } else if (m_sharedTextureMode == SurfaceTextureMode) {
+ glGenTextures(1, &m_sourceTexture->m_textureId);
+
+ m_sourceTexture->m_surfaceTexture =
+ new android::SurfaceTexture(m_sourceTexture->m_textureId);
+ m_sourceTexture->m_ANW =
+ new android::SurfaceTextureClient(m_sourceTexture->m_surfaceTexture);
+
+ m_sourceTexture->m_surfaceTexture->setSynchronousMode(false);
}
}
@@ -64,7 +75,10 @@ SharedTexture::~SharedTexture()
{
if (m_sharedTextureMode == EglImageMode)
deleteTargetTexture();
-
+ else if (m_sharedTextureMode == SurfaceTextureMode) {
+ m_sourceTexture->m_surfaceTexture.clear();
+ m_sourceTexture->m_ANW.clear();
+ }
delete m_sourceTexture;
delete m_targetTexture;
}
@@ -182,8 +196,16 @@ void SharedTexture::releaseSource()
TextureInfo* SharedTexture::lockTarget()
{
// Note that the source and targe are the same when using Surface Texture.
- if (m_sharedTextureMode == SurfaceTextureMode)
+ if (m_sharedTextureMode == SurfaceTextureMode) {
+ m_sourceTexture->m_surfaceTexture->updateTexImage();
+
+ // Surface Texture requires the filter to be non mipmap
+ glBindTexture(GL_TEXTURE_2D, m_sourceTexture->m_textureId);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
return m_sourceTexture;
+ }
m_lock.lock();
diff --git a/Source/WebCore/platform/graphics/android/TextureInfo.h b/Source/WebCore/platform/graphics/android/TextureInfo.h
index 4a9ce30..dfc3092 100644
--- a/Source/WebCore/platform/graphics/android/TextureInfo.h
+++ b/Source/WebCore/platform/graphics/android/TextureInfo.h
@@ -34,7 +34,7 @@
using android::sp;
namespace android {
- class SurfaceTexture;
+class SurfaceTexture;
}
namespace WebCore {
@@ -57,6 +57,7 @@ public:
bool equalsAttributes(const TextureInfo* otherTexture);
void copyAttributes(const TextureInfo* sourceTexture);
+ SharedTextureMode getSharedTextureMode() { return m_sharedTextureMode; }
bool operator==(const TextureInfo& otherTexture);
GLuint m_textureId;