diff options
author | Chris Craik <ccraik@google.com> | 2012-02-17 12:57:20 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-02-17 12:57:20 -0800 |
commit | 7eab0526008e6029e3f6e049ea4d7ceb8c424675 (patch) | |
tree | 6fcc1259b1cf4fe10da441e85749468fa76d5c21 /Source/WebCore/platform/graphics/android | |
parent | 08e661a90ab17e0e94c7566f8108cc93b1e503f3 (diff) | |
parent | 6ed5ffb1c54be9d646d4e4550a2e46b3f0a40305 (diff) | |
download | external_webkit-7eab0526008e6029e3f6e049ea4d7ceb8c424675.zip external_webkit-7eab0526008e6029e3f6e049ea4d7ceb8c424675.tar.gz external_webkit-7eab0526008e6029e3f6e049ea4d7ceb8c424675.tar.bz2 |
Merge "Fix rounding error in clip"
Diffstat (limited to 'Source/WebCore/platform/graphics/android')
4 files changed, 71 insertions, 64 deletions
diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp index 1c36564..e0d48ee 100644 --- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -243,7 +243,7 @@ int GLWebViewState::baseContentHeight() return m_treeManager.baseContentHeight(); } -void GLWebViewState::setViewport(SkRect& viewport, float scale) +void GLWebViewState::setViewport(const SkRect& viewport, float scale) { // allocate max possible number of tiles visible with this viewport / expandedTileBounds const float invTileContentWidth = scale / TilesManager::tileWidth(); @@ -343,9 +343,9 @@ void GLWebViewState::drawBackground(Color& backgroundColor) glClear(GL_COLOR_BUFFER_BIT); } -double GLWebViewState::setupDrawing(IntRect& viewRect, SkRect& visibleRect, - IntRect& webViewRect, int titleBarHeight, - IntRect& screenClip, float scale) +double GLWebViewState::setupDrawing(const IntRect& viewRect, const SkRect& visibleRect, + const IntRect& webViewRect, int titleBarHeight, + const IntRect& screenClip, float scale) { int left = viewRect.x(); int top = viewRect.y(); @@ -364,13 +364,8 @@ double GLWebViewState::setupDrawing(IntRect& viewRect, SkRect& visibleRect, TilesManager::tileHeight()); } - shader->setViewport(visibleRect, scale); - shader->setViewRect(viewRect); - shader->setWebViewRect(webViewRect); - shader->setTitleBarHeight(titleBarHeight); - shader->setScreenClip(screenClip); - shader->resetBlending(); - + shader->setupDrawing(viewRect, visibleRect, webViewRect, + titleBarHeight, screenClip, scale); shader->calculateAnimationDelta(); glViewport(left + shader->getAnimationDeltaX(), diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.h b/Source/WebCore/platform/graphics/android/GLWebViewState.h index cc0c56b..334cd8e 100644 --- a/Source/WebCore/platform/graphics/android/GLWebViewState.h +++ b/Source/WebCore/platform/graphics/android/GLWebViewState.h @@ -191,8 +191,6 @@ public: int baseContentWidth(); int baseContentHeight(); - void setViewport(SkRect& viewport, float scale); - // a rect containing the coordinates of all tiles in the current viewport const SkIRect& viewportTileBounds() const { return m_viewportTileBounds; } // a rect containing the viewportTileBounds before there was a scale change @@ -205,9 +203,6 @@ public: bool isScrolling() { return m_isScrolling || m_isViewportScrolling; } void drawBackground(Color& backgroundColor); - double setupDrawing(IntRect& viewRect, SkRect& visibleRect, - IntRect& webViewRect, int titleBarHeight, - IntRect& screenClip, float scale); bool setLayersRenderingMode(TexturesResult&); void fullInval(); @@ -253,6 +248,10 @@ public: private: void inval(const IntRect& rect); + void setViewport(const SkRect& viewport, float scale); + double setupDrawing(const IntRect& viewRect, const SkRect& visibleRect, + const IntRect& webViewRect, int titleBarHeight, + const IntRect& screenClip, float scale); void showFrameInfo(const IntRect& rect, bool treesSwapped); void clearRectWithColor(const IntRect& rect, float r, float g, float b, float a); diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp index a4af713..59c1271 100644 --- a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp +++ b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp @@ -38,9 +38,18 @@ #include <wtf/CurrentTime.h> #include <wtf/text/CString.h> +#ifdef DEBUG + #undef XLOG #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "ShaderProgram", __VA_ARGS__) +#else + +#undef XLOGC +#define XLOGC(...) android_printLog(ANDROID_LOG_DEBUG, "ShaderProgram", __VA_ARGS__) + +#endif + namespace WebCore { static const char gVertexShader[] = @@ -160,7 +169,7 @@ GLuint ShaderProgram::loadShader(GLenum shaderType, const char* pSource) char* buf = (char*) malloc(infoLen); if (buf) { glGetShaderInfoLog(shader, infoLen, 0, buf); - XLOG("could not compile shader %d:\n%s\n", shaderType, buf); + XLOGC("could not compile shader %d:\n%s\n", shaderType, buf); free(buf); } glDeleteShader(shader); @@ -175,13 +184,13 @@ GLint ShaderProgram::createProgram(const char* pVertexSource, const char* pFragm { GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource); if (!vertexShader) { - XLOG("couldn't load the vertex shader!"); + XLOGC("couldn't load the vertex shader!"); return -1; } GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource); if (!pixelShader) { - XLOG("couldn't load the pixel shader!"); + XLOGC("couldn't load the pixel shader!"); return -1; } @@ -201,7 +210,7 @@ GLint ShaderProgram::createProgram(const char* pVertexSource, const char* pFragm char* buf = (char*) malloc(bufLength); if (buf) { glGetProgramInfoLog(program, bufLength, 0, buf); - XLOG("could not link program:\n%s\n", buf); + XLOGC("could not link program:\n%s\n", buf); free(buf); } } @@ -345,14 +354,54 @@ void ShaderProgram::setBlendingState(bool enableBlending) // Drawing ///////////////////////////////////////////////////////////////////////////////////////// -void ShaderProgram::setViewport(SkRect& viewport, float scale) +void ShaderProgram::setupDrawing(const IntRect& viewRect, const SkRect& visibleRect, + const IntRect& webViewRect, int titleBarHeight, + const IntRect& screenClip, float scale) { + m_webViewRect = webViewRect; + m_titleBarHeight = titleBarHeight; + + //// viewport //// TransformationMatrix ortho; - GLUtils::setOrthographicMatrix(ortho, viewport.fLeft, viewport.fTop, - viewport.fRight, viewport.fBottom, -1000, 1000); + GLUtils::setOrthographicMatrix(ortho, visibleRect.fLeft, visibleRect.fTop, + visibleRect.fRight, visibleRect.fBottom, -1000, 1000); m_projectionMatrix = ortho; - m_viewport = viewport; + m_viewport = visibleRect; m_currentScale = scale; + + + //// viewRect //// + m_viewRect = viewRect; + + // We do clipping using glScissor, which needs to take + // coordinates in screen space. The following matrix transform + // content coordinates in screen coordinates. + TransformationMatrix viewTranslate; + viewTranslate.translate(1.0, 1.0); + + TransformationMatrix viewScale; + viewScale.scale3d(m_viewRect.width() * 0.5f, m_viewRect.height() * 0.5f, 1); + + m_documentToScreenMatrix = viewScale * viewTranslate * m_projectionMatrix; + + viewTranslate.scale3d(1, -1, 1); + m_documentToInvScreenMatrix = viewScale * viewTranslate * m_projectionMatrix; + + IntRect rect(0, 0, m_webViewRect.width(), m_webViewRect.height()); + m_documentViewport = m_documentToScreenMatrix.inverse().mapRect(rect); + + + //// clipping //// + IntRect mclip = screenClip; + + // the clip from frameworks is in full screen coordinates + mclip.setY(screenClip.y() - m_webViewRect.y() - m_titleBarHeight); + FloatRect tclip = convertInvScreenCoordToScreenCoord(mclip); + m_screenClip.setLocation(IntPoint(tclip.x(), tclip.y())); + // use ceilf to handle view -> doc -> view coord rounding errors + m_screenClip.setSize(IntSize(ceilf(tclip.width()), ceilf(tclip.height()))); + + resetBlending(); } // Calculate the matrix given the geometry. @@ -441,28 +490,6 @@ void ShaderProgram::drawQuad(SkRect& geometry, int textureId, float opacity, GLUtils::checkGlError("drawQuad"); } -void ShaderProgram::setViewRect(const IntRect& viewRect) -{ - m_viewRect = viewRect; - - // We do clipping using glScissor, which needs to take - // coordinates in screen space. The following matrix transform - // content coordinates in screen coordinates. - TransformationMatrix translate; - translate.translate(1.0, 1.0); - - TransformationMatrix scale; - scale.scale3d(m_viewRect.width() * 0.5f, m_viewRect.height() * 0.5f, 1); - - m_documentToScreenMatrix = scale * translate * m_projectionMatrix; - - translate.scale3d(1, -1, 1); - m_documentToInvScreenMatrix = scale * translate * m_projectionMatrix; - - IntRect rect(0, 0, m_webViewRect.width(), m_webViewRect.height()); - m_documentViewport = m_documentToScreenMatrix.inverse().mapRect(rect); -} - // This function transform a clip rect extracted from the current layer // into a clip rect in screen coordinates -- used by the clipping rects FloatRect ShaderProgram::rectInScreenCoord(const TransformationMatrix& drawMatrix, const IntSize& size) @@ -507,18 +534,6 @@ FloatRect ShaderProgram::convertScreenCoordToInvScreenCoord(const FloatRect& rec return rectInInvScreenCoord(documentRect); } -void ShaderProgram::setScreenClip(const IntRect& clip) -{ - m_screenClip = clip; - IntRect mclip = clip; - - // the clip from frameworks is in full screen coordinates - mclip.setY(clip.y() - m_webViewRect.y() - m_titleBarHeight); - FloatRect tclip = convertInvScreenCoordToScreenCoord(mclip); - IntRect screenClip(tclip.x(), tclip.y(), tclip.width(), tclip.height()); - m_screenClip = screenClip; -} - // clip is in screen coordinates void ShaderProgram::clip(const FloatRect& clip) { diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.h b/Source/WebCore/platform/graphics/android/ShaderProgram.h index 3d7aab5..e528e60 100644 --- a/Source/WebCore/platform/graphics/android/ShaderProgram.h +++ b/Source/WebCore/platform/graphics/android/ShaderProgram.h @@ -86,7 +86,9 @@ public: void init(); // Drawing - void setViewport(SkRect& viewport, float scale); + void setupDrawing(const IntRect& viewRect, const SkRect& visibleRect, + const IntRect& webViewRect, int titleBarHeight, + const IntRect& screenClip, float scale); float zValue(const TransformationMatrix& drawMatrix, float w, float h); // For drawQuad and drawLayerQuad, they can handle 3 cases for now: @@ -106,7 +108,6 @@ public: Color pureColor = Color()); void drawVideoLayerQuad(const TransformationMatrix& drawMatrix, float* textureMatrix, SkRect& geometry, int textureId); - void setViewRect(const IntRect& viewRect); FloatRect rectInScreenCoord(const TransformationMatrix& drawMatrix, const IntSize& size); FloatRect rectInInvScreenCoord(const TransformationMatrix& drawMatrix, @@ -118,14 +119,10 @@ public: FloatRect convertInvScreenCoordToScreenCoord(const FloatRect& rect); FloatRect convertScreenCoordToInvScreenCoord(const FloatRect& rect); - void setTitleBarHeight(int height) { m_titleBarHeight = height; } - void setWebViewRect(const IntRect& rect) { m_webViewRect = rect; } - void setScreenClip(const IntRect& clip); void clip(const FloatRect& rect); IntRect clippedRectWithViewport(const IntRect& rect, int margin = 0); FloatRect documentViewport() { return m_documentViewport; } - void resetBlending(); float contrast() { return m_contrast; } void setContrast(float c) { float contrast = c; @@ -159,6 +156,7 @@ private: const Color& pureColor); Color shaderColor(Color pureColor, float opacity); ShaderType getTextureShaderType(GLenum textureTarget); + void resetBlending(); bool m_blendingEnabled; |