diff options
author | Chris Craik <ccraik@google.com> | 2012-07-19 13:14:30 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2012-07-19 14:27:01 -0700 |
commit | 73502db10afa184358f2880c9e52906e5abc89c1 (patch) | |
tree | 25c29367e8b509b366841630a329990ac80b96b5 /Source/WebCore | |
parent | 6fda3e621352a695b3b6a02c6008d372b7c6febc (diff) | |
download | external_webkit-73502db10afa184358f2880c9e52906e5abc89c1.zip external_webkit-73502db10afa184358f2880c9e52906e5abc89c1.tar.gz external_webkit-73502db10afa184358f2880c9e52906e5abc89c1.tar.bz2 |
Use canvas-based pure color check
Fall back to standard brute-force method.
InstrumentedPlatformCanvas from upstream webkit trunk/Source/WebCore/platform/graphics/blackberry/InstrumentedPlatformCanvas.h as of changeset 113390 ( http://trac.webkit.org/changeset/113390 )
Change-Id: I7b3884b8284d896c0948d23b6ec9fe0d2d98a6d5
Diffstat (limited to 'Source/WebCore')
6 files changed, 333 insertions, 14 deletions
diff --git a/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.cpp b/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.cpp index 6f679da..37f9013 100644 --- a/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.cpp @@ -34,6 +34,7 @@ #include "AndroidLog.h" #include "GaneshRenderer.h" #include "GLUtils.h" +#include "InstrumentedPlatformCanvas.h" #include "RasterRenderer.h" #include "SkBitmap.h" #include "SkBitmapRef.h" @@ -94,7 +95,8 @@ void BaseRenderer::renderTiledContent(TileRenderInfo& renderInfo) const bool visualIndicator = TilesManager::instance()->getShowVisualIndicator(); const SkSize& tileSize = renderInfo.tileSize; - SkCanvas canvas; + InstrumentedPlatformCanvas canvas(TilesManager::instance()->tileWidth(), + TilesManager::instance()->tileHeight()); setupCanvas(renderInfo, &canvas); if (!canvas.getDevice()) { @@ -112,10 +114,8 @@ void BaseRenderer::renderTiledContent(TileRenderInfo& renderInfo) canvas.translate(-renderInfo.x * tileSize.width(), -renderInfo.y * tileSize.height()); canvas.scale(renderInfo.scale, renderInfo.scale); renderInfo.tilePainter->paint(&canvas); - if (renderInfo.baseTile && renderInfo.baseTile->backTexture()) - checkForPureColor(renderInfo, &canvas); - else - renderInfo.isPureColor = false; + + checkForPureColor(renderInfo, canvas); if (visualIndicator) { double after = currentTimeMS(); @@ -144,6 +144,14 @@ void BaseRenderer::renderTiledContent(TileRenderInfo& renderInfo) renderingComplete(renderInfo, &canvas); } +void BaseRenderer::checkForPureColor(TileRenderInfo& renderInfo, InstrumentedPlatformCanvas& canvas) +{ + renderInfo.isPureColor = canvas.isSolidColor(); + renderInfo.pureColor = canvas.solidColor(); + ALOGD("isPureColor = %d, pureColor = %d", renderInfo.isPureColor, renderInfo.pureColor); + deviceCheckForPureColor(renderInfo, &canvas); +} + } // namespace WebCore #endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.h b/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.h index b25a50e..dc8831a 100644 --- a/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.h +++ b/Source/WebCore/platform/graphics/android/rendering/BaseRenderer.h @@ -37,6 +37,7 @@ class SkDevice; namespace WebCore { +class InstrumentedPlatformCanvas; class TextureInfo; class TilePainter; class Tile; @@ -87,7 +88,10 @@ protected: virtual void setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas) = 0; virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) = 0; - virtual void checkForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas) = 0; + void checkForPureColor(TileRenderInfo& renderInfo, InstrumentedPlatformCanvas& canvas); + + // performs additional pure color check, renderInfo.isPureColor may already be set to true + virtual void deviceCheckForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas) = 0; void drawTileInfo(SkCanvas* canvas, const TileRenderInfo& renderInfo, int updateCount, double renderDuration); diff --git a/Source/WebCore/platform/graphics/android/rendering/GaneshRenderer.h b/Source/WebCore/platform/graphics/android/rendering/GaneshRenderer.h index cdd9f3e..77982e8 100644 --- a/Source/WebCore/platform/graphics/android/rendering/GaneshRenderer.h +++ b/Source/WebCore/platform/graphics/android/rendering/GaneshRenderer.h @@ -48,9 +48,7 @@ protected: virtual void setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas); virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas); - virtual void checkForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas) { - renderInfo.isPureColor = false; - } + virtual void deviceCheckForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas) {} }; diff --git a/Source/WebCore/platform/graphics/android/rendering/InstrumentedPlatformCanvas.h b/Source/WebCore/platform/graphics/android/rendering/InstrumentedPlatformCanvas.h new file mode 100644 index 0000000..faa5bcd --- /dev/null +++ b/Source/WebCore/platform/graphics/android/rendering/InstrumentedPlatformCanvas.h @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2011 Research In Motion Limited. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef InstrumentedPlatformCanvas_h +#define InstrumentedPlatformCanvas_h + +#include "SkCanvas.h" + +#define DEBUG_SKIA_DRAWING 0 +#if DEBUG_SKIA_DRAWING +#define WRAPCANVAS_LOG_ENTRY(...) do { \ + fprintf(stderr, "%s ", __FUNCTION__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ +} while (0) +#else +#define WRAPCANVAS_LOG_ENTRY(...) ((void)0) +#endif + +namespace WebCore { + +class InstrumentedPlatformCanvas : public SkCanvas { +public: + InstrumentedPlatformCanvas(int width, int height) + : m_size(width, height) + , m_isSolidColor(true) + , m_solidColor(0, 0, 0, 0) + { + } + + virtual ~InstrumentedPlatformCanvas() { } + + bool isSolidColor() const { return m_isSolidColor; } + Color solidColor() const { return m_solidColor; } + + // overrides from SkCanvas + virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) + { + WRAPCANVAS_LOG_ENTRY(""); + return SkCanvas::save(flags); + } + + virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + return SkCanvas::saveLayer(bounds, paint, flags); + } + + virtual void restore() + { + WRAPCANVAS_LOG_ENTRY(""); + SkCanvas::restore(); + } + + virtual bool translate(SkScalar dx, SkScalar dy) + { + WRAPCANVAS_LOG_ENTRY(""); + return SkCanvas::translate(dx, dy); + } + + virtual bool scale(SkScalar sx, SkScalar sy) + { + WRAPCANVAS_LOG_ENTRY(""); + return SkCanvas::scale(sx, sy); + } + + virtual bool rotate(SkScalar degrees) + { + WRAPCANVAS_LOG_ENTRY(""); + return SkCanvas::rotate(degrees); + } + + virtual bool skew(SkScalar sx, SkScalar sy) + { + WRAPCANVAS_LOG_ENTRY(""); + return SkCanvas::skew(sx, sy); + } + + virtual bool concat(const SkMatrix& matrix) + { + WRAPCANVAS_LOG_ENTRY(""); + return SkCanvas::concat(matrix); + } + + virtual void setMatrix(const SkMatrix& matrix) + { + WRAPCANVAS_LOG_ENTRY(""); + SkCanvas::setMatrix(matrix); + } + + virtual bool clipRect(const SkRect& rect, SkRegion::Op op) + { + WRAPCANVAS_LOG_ENTRY(""); + return SkCanvas::clipRect(rect, op); + } + + virtual bool clipPath(const SkPath& path, SkRegion::Op op) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + return SkCanvas::clipPath(path, op); + } + + virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + return SkCanvas::clipRegion(region, op); + } + + virtual void clear(SkColor color) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = true; + m_solidColor = Color(color); + SkCanvas::clear(color); + } + + virtual void drawPaint(const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawPaint(paint); + } + + virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], + const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawPoints(mode, count, pts, paint); + } + + virtual void drawRect(const SkRect& rect, const SkPaint& paint) + { +#if DEBUG_SKIA_DRAWING + IntRect rectToDraw(rect); + WRAPCANVAS_LOG_ENTRY("rect = (x=%d,y=%d,width=%d,height=%d)", INT_RECT_ARGS(rectToDraw); +#endif + IntRect canvasRect(IntPoint(), m_size); + if (m_isSolidColor + && getTotalMatrix().rectStaysRect() + && getTotalClip().contains(canvasRect)) { + const SkMatrix& matrix = getTotalMatrix(); + SkRect mapped; + matrix.mapRect(&mapped, rect); + if (mapped.contains(canvasRect)) { + Color color = solidColor(paint); + m_isSolidColor = color.isValid(); + m_solidColor = color; + } else + m_isSolidColor = false; + } else + m_isSolidColor = false; + SkCanvas::drawRect(rect, paint); + } + + virtual void drawPath(const SkPath& path, const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawPath(path, paint); + } + + virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, + SkScalar top, const SkPaint* paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawBitmap(bitmap, left, top, paint); + } + + virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, + const SkRect& dst, const SkPaint* paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawBitmapRect(bitmap, src, dst, paint); + } + + virtual void drawBitmapMatrix(const SkBitmap& bitmap, + const SkMatrix& matrix, const SkPaint* paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawBitmapMatrix(bitmap, matrix, paint); + } + + virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, + const SkRect& dst, const SkPaint* paint = 0) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawBitmapNine(bitmap, center, dst, paint); + } + + virtual void drawSprite(const SkBitmap& bitmap, int left, int top, + const SkPaint* paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawSprite(bitmap, left, top, paint); + } + + virtual void drawText(const void* text, size_t byteLength, SkScalar x, + SkScalar y, const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawText(text, byteLength, x, y, paint); + } + + virtual void drawPosText(const void* text, size_t byteLength, + const SkPoint pos[], const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawPosText(text, byteLength, pos, paint); + } + + virtual void drawPosTextH(const void* text, size_t byteLength, + const SkScalar xpos[], SkScalar constY, const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawPosTextH(text, byteLength, xpos, constY, paint); + } + + virtual void drawTextOnPath(const void* text, size_t byteLength, + const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawTextOnPath(text, byteLength, path, matrix, paint); + } + + virtual void drawPicture(SkPicture& picture) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawPicture(picture); + } + + virtual void drawVertices(VertexMode mode, int vertexCount, + const SkPoint vertices[], const SkPoint texs[], + const SkColor colors[], SkXfermode* xfermode, + const uint16_t indices[], int indexCount, const SkPaint& paint) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawVertices(mode, vertexCount, vertices, texs, + colors, xfermode, indices, indexCount, paint); + } + + virtual void drawData(const void* data, size_t size) + { + WRAPCANVAS_LOG_ENTRY(""); + m_isSolidColor = false; + SkCanvas::drawData(data, size); + } + +private: + Color solidColor(const SkPaint& paint) + { + if (paint.getStyle() != SkPaint::kFill_Style) + return Color(); + if (paint.getLooper() || paint.getShader()) + return Color(); + + SkXfermode::Mode mode; + SkXfermode::AsMode(paint.getXfermode(), &mode); + if (mode == SkXfermode::kClear_Mode) + return Color(0, 0, 0, 0); + + if ((mode == SkXfermode::kSrcOver_Mode && paint.getAlpha() == 255) + || mode == SkXfermode::kSrc_Mode) + return Color(paint.getColor()); + return Color(); + } + + IntSize m_size; + bool m_isSolidColor; + Color m_solidColor; + SkPaint m_solidPaint; +}; + +} // namespace WebCore + +#endif // InstrumentedPlatformCanvas_h diff --git a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp index 5c78ad9..fd26380 100644 --- a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp @@ -101,12 +101,16 @@ void RasterRenderer::renderingComplete(const TileRenderInfo& renderInfo, SkCanva GLUtils::paintTextureWithBitmap(&renderInfo, m_bitmap); } -void RasterRenderer::checkForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas) +void RasterRenderer::deviceCheckForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas) { - m_bitmapIsPureColor = GLUtils::isPureColorBitmap(m_bitmap, m_bitmapPureColor); + if (!renderInfo.isPureColor) { + // base renderer may have already determined isPureColor, so only do the + // brute force check if needed + renderInfo.isPureColor = GLUtils::isPureColorBitmap(m_bitmap, renderInfo.pureColor); + } - renderInfo.isPureColor = m_bitmapIsPureColor; - renderInfo.pureColor = m_bitmapPureColor; + m_bitmapIsPureColor = renderInfo.isPureColor; + m_bitmapPureColor = renderInfo.pureColor; } } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h index 34b57ca..791c6b6 100644 --- a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h +++ b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h @@ -48,7 +48,7 @@ public: protected: virtual void setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas); virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas); - virtual void checkForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas); + virtual void deviceCheckForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas); private: SkBitmap m_bitmap; |