From 485445e9a624fe92ca04a1d0e92c1f71aaf8cd8f Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Wed, 25 Apr 2012 15:30:11 -0700 Subject: Support partial draw in terms of a rect. In this way, we can cover any internal rect area of the tiles. bug:6338952 Change-Id: If236a7f6ad82a3f9126a692ca5b08240a3631f88 --- .../graphics/android/rendering/DrawQuadData.h | 14 ++++++++------ .../graphics/android/rendering/ShaderProgram.cpp | 20 ++++++++++++-------- .../graphics/android/rendering/ShaderProgram.h | 2 +- .../platform/graphics/android/rendering/Tile.cpp | 10 ++++++---- .../platform/graphics/android/rendering/Tile.h | 2 +- .../graphics/android/rendering/TileGrid.cpp | 22 ++++++++++++++++++---- .../graphics/android/rendering/TileTexture.cpp | 2 +- .../graphics/android/rendering/TileTexture.h | 4 ++-- 8 files changed, 49 insertions(+), 27 deletions(-) diff --git a/Source/WebCore/platform/graphics/android/rendering/DrawQuadData.h b/Source/WebCore/platform/graphics/android/rendering/DrawQuadData.h index bce82f2..719df14 100644 --- a/Source/WebCore/platform/graphics/android/rendering/DrawQuadData.h +++ b/Source/WebCore/platform/graphics/android/rendering/DrawQuadData.h @@ -29,7 +29,7 @@ #if USE(ACCELERATED_COMPOSITING) #include "Color.h" -#include "FloatPoint.h" +#include "FloatRect.h" #include "SkRect.h" #include @@ -51,13 +51,14 @@ public: const SkRect* geometry = 0, float opacity = 1.0f, bool forceBlending = true, - FloatPoint fillPortion = FloatPoint(1.0f, 1.0f)) + FloatRect fillPortion = FloatRect(0.0f, 0.0f, 1.0f, 1.0f)) : m_type(type) , m_drawMatrix(drawMatrix) , m_geometry(geometry) , m_opacity(opacity) , m_forceBlending(forceBlending) - , m_fillPortion(fillPortion.x(), fillPortion.y()) + , m_fillPortion(fillPortion.x(), fillPortion.y(), + fillPortion.width(), fillPortion.height()) { } @@ -67,7 +68,8 @@ public: , m_geometry(data.m_geometry) , m_opacity(data.m_opacity) , m_forceBlending(data.m_forceBlending) - , m_fillPortion(data.m_fillPortion.x(), data.m_fillPortion.y()) + , m_fillPortion(data.m_fillPortion.x(), data.m_fillPortion.y(), + data.m_fillPortion.width(), data.m_fillPortion.height()) { } @@ -90,7 +92,7 @@ public: virtual int textureId() const { return 0; } virtual GLint textureFilter() const { return 0; } virtual GLenum textureTarget() const { return 0; } - virtual FloatPoint fillPortion() const { return m_fillPortion; } + virtual FloatRect fillPortion() const { return m_fillPortion; } private: DrawQuadType m_type; @@ -98,7 +100,7 @@ private: const SkRect* m_geometry; float m_opacity; bool m_forceBlending; - FloatPoint m_fillPortion; + FloatRect m_fillPortion; }; class PureColorQuadData : public DrawQuadData { diff --git a/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.cpp b/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.cpp index 817efb8..ced6e62 100644 --- a/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.cpp @@ -44,14 +44,16 @@ namespace WebCore { +// fillPortion.xy = starting UV coordinate. +// fillPortion.zw = UV coordinate width and height. static const char gVertexShader[] = "attribute vec4 vPosition;\n" "uniform mat4 projectionMatrix;\n" - "uniform vec2 fillPortion;\n" + "uniform vec4 fillPortion;\n" "varying vec2 v_texCoord;\n" "void main() {\n" " gl_Position = projectionMatrix * vPosition;\n" - " v_texCoord = vPosition.xy * fillPortion;\n" + " v_texCoord = vPosition.xy * fillPortion.zw + fillPortion.xy;\n" "}\n"; static const char gFragmentShader[] = @@ -594,7 +596,7 @@ float ShaderProgram::zValue(const TransformationMatrix& drawMatrix, float w, flo void ShaderProgram::drawQuadInternal(ShaderType type, const GLfloat* matrix, int textureId, float opacity, GLenum textureTarget, GLenum filter, - const Color& pureColor, const FloatPoint& fillPortion) + const Color& pureColor, const FloatRect& fillPortion) { glUseProgram(m_handleArray[type].programHandle); glUniformMatrix4fv(m_handleArray[type].projMtxHandle, 1, GL_FALSE, matrix); @@ -611,7 +613,8 @@ void ShaderProgram::drawQuadInternal(ShaderType type, const GLfloat* matrix, if (contrastHandle != -1) glUniform1f(contrastHandle, m_contrast); - glUniform2f(m_handleArray[type].fillPortionHandle, fillPortion.x(), fillPortion.y()); + glUniform4f(m_handleArray[type].fillPortionHandle, fillPortion.x(), fillPortion.y(), + fillPortion.width(), fillPortion.height()); } else { glUniform4f(m_handleArray[type].pureColorHandle, pureColor.red() / 255.0, pureColor.green() / 255.0, @@ -643,7 +646,7 @@ GLfloat* ShaderProgram::getTileProjectionMatrix(const DrawQuadData* data) const TransformationMatrix* matrix = data->drawMatrix(); const SkRect* geometry = data->geometry(); - FloatPoint fillPortion = data->fillPortion(); + FloatRect fillPortion = data->fillPortion(); // This modifiedDrawMatrix tranform (0,0)(1x1) to the final rect in screen // coordinate, before applying the m_webViewMatrix. // It first scale and translate the vertex array from (0,0)(1x1) to real @@ -654,9 +657,10 @@ GLfloat* ShaderProgram::getTileProjectionMatrix(const DrawQuadData* data) TransformationMatrix modifiedDrawMatrix; if (type == LayerQuad) modifiedDrawMatrix = *matrix; - modifiedDrawMatrix.translate(geometry->fLeft, geometry->fTop); - modifiedDrawMatrix.scale3d(geometry->width() * fillPortion.x(), - geometry->height() * fillPortion.y(), 1); + modifiedDrawMatrix.translate(geometry->fLeft + geometry->width() * fillPortion.x(), + geometry->fTop + geometry->height() * fillPortion.y()); + modifiedDrawMatrix.scale3d(geometry->width() * fillPortion.width(), + geometry->height() * fillPortion.height(), 1); // Even when we are on a alpha layer or not, we need to respect the // m_webViewMatrix, it may contain the layout offset. Normally it is diff --git a/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.h b/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.h index e290242..8c9e301 100644 --- a/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.h +++ b/Source/WebCore/platform/graphics/android/rendering/ShaderProgram.h @@ -167,7 +167,7 @@ private: void setBlendingState(bool enableBlending); void drawQuadInternal(ShaderType type, const GLfloat* matrix, int textureId, float opacity, GLenum textureTarget, GLenum filter, - const Color& pureColor, const FloatPoint& fillPortion); + const Color& pureColor, const FloatRect& fillPortion); Color shaderColor(Color pureColor, float opacity); ShaderType getTextureShaderType(GLenum textureTarget); void resetBlending(); diff --git a/Source/WebCore/platform/graphics/android/rendering/Tile.cpp b/Source/WebCore/platform/graphics/android/rendering/Tile.cpp index 0501777..2ee45b0 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Tile.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/Tile.cpp @@ -210,7 +210,7 @@ void Tile::setRepaintPending(bool pending) bool Tile::drawGL(float opacity, const SkRect& rect, float scale, const TransformationMatrix* transform, bool forceBlending, bool usePointSampling, - const FloatPoint& fillPortion) + const FloatRect& fillPortion) { if (m_x < 0 || m_y < 0 || m_scale != scale) return false; @@ -220,9 +220,11 @@ bool Tile::drawGL(float opacity, const SkRect& rect, float scale, if (!m_frontTexture) return false; - if (fillPortion.x() < 1.0f || fillPortion.y() < 1.0f) - ALOGV("drawing tile %p (%d, %d with fill portions %f %f", - this, m_x, m_y, fillPortion.x(), fillPortion.y()); + if (fillPortion.maxX() < 1.0f || fillPortion.maxY() < 1.0f + || fillPortion.x() > 0.0f || fillPortion.y() > 0.0f) + ALOGV("drawing tile %p (%d, %d with fill portions %f %f->%f, %f", + this, m_x, m_y, fillPortion.x(), fillPortion.y(), + fillPortion.maxX(), fillPortion.maxY()); m_frontTexture->drawGL(isLayerTile(), rect, opacity, transform, forceBlending, usePointSampling, fillPortion); diff --git a/Source/WebCore/platform/graphics/android/rendering/Tile.h b/Source/WebCore/platform/graphics/android/rendering/Tile.h index 58ba15b..c115f1c 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Tile.h +++ b/Source/WebCore/platform/graphics/android/rendering/Tile.h @@ -104,7 +104,7 @@ public: bool drawGL(float opacity, const SkRect& rect, float scale, const TransformationMatrix* transform, bool forceBlending, bool usePointSampling, - const FloatPoint& fillPortion); + const FloatRect& fillPortion); // the only thread-safe function called by the background thread void paintBitmap(TilePainter* painter); diff --git a/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp b/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp index 7c6175f..8bf033e 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp @@ -296,10 +296,12 @@ void TileGrid::drawGL(const IntRect& visibleArea, float opacity, bool usePointSampling = TilesManager::instance()->shader()->usePointSampling(m_scale, transform); - + float minTileX = visibleArea.x() / tileWidth; + float minTileY = visibleArea.y() / tileWidth; float maxTileWidth = visibleArea.maxX() / tileWidth; float maxTileHeight = visibleArea.maxY() / tileWidth; - + ALOGV("minTileX, minTileY, maxTileWidth, maxTileHeight %f, %f, %f %f", + minTileX, minTileY, maxTileWidth, maxTileHeight); for (unsigned int i = 0; i < m_tiles.size(); i++) { Tile* tile = m_tiles[i]; @@ -316,8 +318,20 @@ void TileGrid::drawGL(const IntRect& visibleArea, float opacity, bool forceBaseBlending = background ? background->hasAlpha() : false; - FloatPoint fillPortion(std::min(maxTileWidth - tile->x(), 1.0f), - std::min(maxTileHeight - tile->y(), 1.0f)); + float left = std::max(minTileX - tile->x(), 0.0f); + float top = std::max(minTileY - tile->y(), 0.0f); + float right = std::min(maxTileWidth - tile->x(), 1.0f); + float bottom = std::min(maxTileHeight - tile->y(), 1.0f); + if (left > 1.0f || top > 1.0f || right < 0.0f || bottom < 0.0f) { + ALOGE("Unexpected portion:left, top, right, bottom %f %f %f %f", + left, top, right, bottom); + left = 0.0f; + top = 0.0f; + right = 1.0f; + bottom = 1.0f; + } + FloatRect fillPortion(left, top, right - left, bottom - top); + bool success = tile->drawGL(opacity, rect, m_scale, transform, forceBaseBlending, usePointSampling, fillPortion); if (semiOpaqueBaseSurface && success) { diff --git a/Source/WebCore/platform/graphics/android/rendering/TileTexture.cpp b/Source/WebCore/platform/graphics/android/rendering/TileTexture.cpp index 54c67cc..be4b4db 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TileTexture.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TileTexture.cpp @@ -121,7 +121,7 @@ void TileTexture::transferComplete() void TileTexture::drawGL(bool isLayer, const SkRect& rect, float opacity, const TransformationMatrix* transform, bool forceBlending, bool usePointSampling, - const FloatPoint& fillPortion) + const FloatRect& fillPortion) { ShaderProgram* shader = TilesManager::instance()->shader(); diff --git a/Source/WebCore/platform/graphics/android/rendering/TileTexture.h b/Source/WebCore/platform/graphics/android/rendering/TileTexture.h index b694241..e31da5b 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TileTexture.h +++ b/Source/WebCore/platform/graphics/android/rendering/TileTexture.h @@ -27,7 +27,7 @@ #define TileTexture_h #include "Color.h" -#include "FloatPoint.h" +#include "FloatRect.h" #include "SkBitmap.h" #include "SkRect.h" #include "SkSize.h" @@ -82,7 +82,7 @@ public: void drawGL(bool isLayer, const SkRect& rect, float opacity, const TransformationMatrix* transform, bool forceBlending, bool usePointSampling, - const FloatPoint& fillPortion); + const FloatRect& fillPortion); private: TextureInfo m_ownTextureInfo; SkSize m_size; -- cgit v1.1