diff options
author | Derek Sollenberger <djsollen@google.com> | 2011-06-29 05:33:11 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-29 05:33:11 -0700 |
commit | 2facab8e2bfadc4b9028b267b9596981bfb6cc8a (patch) | |
tree | 1040fe09b443ef0fc7e080ed8017377ae401d555 | |
parent | 4fe08aab7cb344ee175e2637d3c69e8d4b5dc80c (diff) | |
parent | 232d0b3572d13d9b4fb1211d9d56252a1ede3ed6 (diff) | |
download | external_webkit-2facab8e2bfadc4b9028b267b9596981bfb6cc8a.zip external_webkit-2facab8e2bfadc4b9028b267b9596981bfb6cc8a.tar.gz external_webkit-2facab8e2bfadc4b9028b267b9596981bfb6cc8a.tar.bz2 |
Merge "Add BaseRenderer to handle generic rendering tasks."
-rw-r--r-- | Source/WebCore/Android.mk | 1 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/BaseRenderer.cpp | 120 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/BaseRenderer.h | 103 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/BaseTile.cpp | 41 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/RasterRenderer.cpp | 132 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/RasterRenderer.h | 22 |
6 files changed, 295 insertions, 124 deletions
diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk index 4673b45..9ea7007 100644 --- a/Source/WebCore/Android.mk +++ b/Source/WebCore/Android.mk @@ -633,6 +633,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ \ platform/graphics/android/AndroidAnimation.cpp \ platform/graphics/android/BaseLayerAndroid.cpp \ + platform/graphics/android/BaseRenderer.cpp \ platform/graphics/android/BaseTile.cpp \ platform/graphics/android/BaseTileTexture.cpp \ platform/graphics/android/BitmapAllocatorAndroid.cpp \ diff --git a/Source/WebCore/platform/graphics/android/BaseRenderer.cpp b/Source/WebCore/platform/graphics/android/BaseRenderer.cpp new file mode 100644 index 0000000..13dfce6 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/BaseRenderer.cpp @@ -0,0 +1,120 @@ +/* + * Copyright 2011, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "config.h" +#include "BaseRenderer.h" + +#if USE(ACCELERATED_COMPOSITING) + +#include "GLUtils.h" +#include "SkBitmap.h" +#include "SkBitmapRef.h" +#include "SkCanvas.h" +#include "SkDevice.h" +#include "SkPicture.h" +#include "TilesManager.h" + +#include <wtf/text/CString.h> + +#ifdef DEBUG + +#include <cutils/log.h> +#include <wtf/CurrentTime.h> + +#undef XLOG +#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "BaseRenderer", __VA_ARGS__) + +#else + +#undef XLOG +#define XLOG(...) + +#endif // DEBUG + +namespace WebCore { + +void BaseRenderer::drawTileInfo(SkCanvas* canvas, + const TileRenderInfo& renderInfo, int pictureCount) +{ + SkPaint paint; + char str[256]; + snprintf(str, 256, "(%d,%d) %.2f, tl%x p%x c%d", renderInfo.x, renderInfo.y, + renderInfo.scale, this, renderInfo.tiledPage, pictureCount); + paint.setARGB(255, 0, 0, 0); + canvas->drawText(str, strlen(str), 0, 10, paint); + paint.setARGB(255, 255, 0, 0); + canvas->drawText(str, strlen(str), 0, 11, paint); + drawPerformanceInfo(canvas); +} + +int BaseRenderer::renderTiledContent(const TileRenderInfo& renderInfo) +{ + bool visualIndicator = TilesManager::instance()->getShowVisualIndicator(); + +#ifdef DEBUG + visualIndicator = true; + measurePerf = true; +#endif + + SkIRect* invalRect = renderInfo.invalRect; + + SkDevice* device = setupDevice(renderInfo); + SkCanvas canvas(device); + device->unref(); + + if (visualIndicator) + canvas.save(); + + canvas.scale(renderInfo.scale, renderInfo.scale); + canvas.translate(-renderInfo.invalX, -renderInfo.invalY); + int pictureCount = renderInfo.tiledPage->paintBaseLayerContent(&canvas); + + if (visualIndicator) { + canvas.restore(); + + int color = 20 + pictureCount % 100; + canvas.drawARGB(color, 0, 255, 0); + + SkPaint paint; + paint.setARGB(128, 255, 0, 0); + paint.setStrokeWidth(3); + canvas.drawLine(0, 0, invalRect->width(), invalRect->height(), paint); + paint.setARGB(128, 0, 255, 0); + canvas.drawLine(0, invalRect->height(), invalRect->width(), 0, paint); + paint.setARGB(128, 0, 0, 255); + canvas.drawLine(0, 0, invalRect->width(), 0, paint); + canvas.drawLine(invalRect->width(), 0, invalRect->width(), invalRect->height(), paint); + + drawTileInfo(&canvas, renderInfo, pictureCount); + } + + renderingComplete(renderInfo, &canvas); + return pictureCount; +} + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/BaseRenderer.h b/Source/WebCore/platform/graphics/android/BaseRenderer.h new file mode 100644 index 0000000..b48145f --- /dev/null +++ b/Source/WebCore/platform/graphics/android/BaseRenderer.h @@ -0,0 +1,103 @@ +/* + * Copyright 2011, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef BaseRenderer_h +#define BaseRenderer_h + +#if USE(ACCELERATED_COMPOSITING) + +#include "PerformanceMonitor.h" +#include "SkRect.h" + +class SkCanvas; +class SkDevice; + +namespace WebCore { + +class TextureInfo; +class TiledPage; + +struct TileRenderInfo { + // coordinates of the tile + int x; + int y; + + // current scale factor + float scale; + + // inval rectangle with coordinates in the tile's coordinate space + SkIRect* invalRect; + + // coordinates for the invalRect (upper-left) in the DOM's coordinate space + float invalX; + float invalY; + + // the expected size of the tile + SkSize tileSize; + + // the tiled page that contains the content to be drawn + TiledPage* tiledPage; + + // info about the texture that we are to render into + TextureInfo* textureInfo; + + // specifies whether or not to measure the rendering performance + bool measurePerf; +}; + +/** + * + */ +class BaseRenderer { +public: + enum RendererType { Raster, Ganesh }; + BaseRenderer(RendererType type) : m_type(type) {} + virtual ~BaseRenderer() {} + + int renderTiledContent(const TileRenderInfo& renderInfo); + + RendererType getType() { return m_type; } + +protected: + + virtual SkDevice* setupDevice(const TileRenderInfo& renderInfo) = 0; + virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) = 0; + + void drawTileInfo(SkCanvas* canvas, const TileRenderInfo& renderInfo, + int pictureCount); + + virtual void drawPerformanceInfo(SkCanvas* canvas) {} + + // Performance tracking + PerformanceMonitor m_perfMon; + +private: + RendererType m_type; +}; + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) +#endif // BaseRenderer_h diff --git a/Source/WebCore/platform/graphics/android/BaseTile.cpp b/Source/WebCore/platform/graphics/android/BaseTile.cpp index 7020208..87bdba4 100644 --- a/Source/WebCore/platform/graphics/android/BaseTile.cpp +++ b/Source/WebCore/platform/graphics/android/BaseTile.cpp @@ -28,6 +28,7 @@ #if USE(ACCELERATED_COMPOSITING) +#include "BaseRenderer.h" #include "GLUtils.h" #include "TextureInfo.h" #include "TilesManager.h" @@ -277,12 +278,20 @@ void BaseTile::paintBitmap() return; } - SkSize size = texture->getSize(); - const float tileWidth = size.width(); - const float tileHeight = size.height(); - unsigned int pictureCount = 0; + // setup the common renderInfo fields; + TileRenderInfo renderInfo; + renderInfo.x = x; + renderInfo.y = y; + renderInfo.scale = scale; + renderInfo.tileSize = texture->getSize(); + renderInfo.tiledPage = tiledPage; + renderInfo.textureInfo = textureInfo; + + const float tileWidth = renderInfo.tileSize.width(); + const float tileHeight = renderInfo.tileSize.height(); + SkRegion::Iterator cliperator(dirtyArea); bool fullRepaint = false; @@ -337,14 +346,12 @@ void BaseTile::paintBitmap() finalRealRect.fRight = finalRealRect.fLeft + iWidth; finalRealRect.fBottom = finalRealRect.fTop + iHeight; - // the canvas translate can be recomputed accounting for the scale - float tx = realTileRect.fLeft / scale; - float ty = realTileRect.fTop / scale; + renderInfo.invalRect = &finalRealRect; + renderInfo.invalX = realTileRect.fLeft / scale; + renderInfo.invalY = realTileRect.fTop / scale; + renderInfo.measurePerf = false; - pictureCount = m_renderer.renderContent(x, y, finalRealRect, - tx, ty, scale, texture, - textureInfo, tiledPage, - fullRepaint); + pictureCount = m_renderer.renderTiledContent(renderInfo); cliperator.next(); } @@ -353,13 +360,13 @@ void BaseTile::paintBitmap() if (fullRepaint) { SkIRect rect; rect.set(0, 0, tileWidth, tileHeight); - float tx = x * tileWidth / scale; - float ty = y * tileHeight / scale; - pictureCount = m_renderer.renderContent(x, y, rect, - tx, ty, scale, texture, - textureInfo, tiledPage, - fullRepaint); + renderInfo.invalRect = ▭ + renderInfo.invalX = x * tileWidth / scale; + renderInfo.invalY = y * tileHeight / scale; + renderInfo.measurePerf = TilesManager::instance()->getShowVisualIndicator(); + + pictureCount = m_renderer.renderTiledContent(renderInfo); } XLOG("%x update texture %x for tile %d, %d scale %.2f (m_scale: %.2f)", this, textureInfo, x, y, scale, m_scale); diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.cpp b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp index c1fcbcb..025dbae 100644 --- a/Source/WebCore/platform/graphics/android/RasterRenderer.cpp +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp @@ -33,14 +33,10 @@ #include "SkBitmap.h" #include "SkBitmapRef.h" #include "SkCanvas.h" +#include "SkDevice.h" #include "SkPicture.h" #include "TilesManager.h" -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> - #include <wtf/text/CString.h> #ifdef DEBUG @@ -63,16 +59,14 @@ namespace WebCore { static const String TAG_CREATE_BITMAP = "create_bitmap"; static const String TAG_DRAW_PICTURE = "draw_picture"; static const String TAG_UPDATE_TEXTURE = "update_texture"; -static const String TAG_RESET_BITMAP = "reset_bitmap"; #define TAG_COUNT 4 static const String TAGS[] = { TAG_CREATE_BITMAP, TAG_DRAW_PICTURE, TAG_UPDATE_TEXTURE, - TAG_RESET_BITMAP }; -RasterRenderer::RasterRenderer() +RasterRenderer::RasterRenderer() : BaseRenderer(BaseRenderer::Raster) { #ifdef DEBUG_COUNT ClassTracker::instance()->increment("RasterRenderer"); @@ -86,20 +80,47 @@ RasterRenderer::~RasterRenderer() #endif } -void RasterRenderer::drawTileInfo(SkCanvas* canvas, - BaseTileTexture* texture, - TiledPage* tiledPage, - int x, int y, float scale, - int pictureCount) +SkDevice* RasterRenderer::setupDevice(const TileRenderInfo& renderInfo) +{ + if (renderInfo.measurePerf) + m_perfMon.start(TAG_CREATE_BITMAP); + + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + renderInfo.invalRect->width(), renderInfo.invalRect->height()); + bitmap.allocPixels(); + + SkDevice* device = new SkDevice(NULL, bitmap, false); + + if (renderInfo.measurePerf) { + m_perfMon.stop(TAG_CREATE_BITMAP); + m_perfMon.start(TAG_DRAW_PICTURE); + } + + return device; +} + +void RasterRenderer::renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) +{ + if (renderInfo.measurePerf) { + m_perfMon.stop(TAG_DRAW_PICTURE); + m_perfMon.start(TAG_UPDATE_TEXTURE); + } + + const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false); + + GLUtils::paintTextureWithBitmap(renderInfo.textureInfo, renderInfo.tileSize, + bitmap, renderInfo.invalRect->fLeft, renderInfo.invalRect->fTop); + + if (renderInfo.measurePerf) + m_perfMon.stop(TAG_UPDATE_TEXTURE); +} + +void RasterRenderer::drawPerformanceInfo(SkCanvas* canvas) { SkPaint paint; char str[256]; - snprintf(str, 256, "(%d,%d) %.2f, tl%x tx%x p%x c%d", - x, y, scale, this, texture, tiledPage, pictureCount); - paint.setARGB(255, 0, 0, 0); - canvas->drawText(str, strlen(str), 0, 10, paint); - paint.setARGB(255, 255, 0, 0); - canvas->drawText(str, strlen(str), 0, 11, paint); float total = 0; for (int i = 0; i < TAG_COUNT; i++) { float tagDuration = m_perfMon.getAverageDuration(TAGS[i]); @@ -119,79 +140,6 @@ void RasterRenderer::drawTileInfo(SkCanvas* canvas, canvas->drawText(str, strlen(str), 0, textY + 1, paint); } -int RasterRenderer::renderContent(int x, int y, SkIRect rect, float tx, float ty, - float scale, BaseTileTexture* texture, - TextureInfo* textureInfo, - TiledPage* tiledPage, bool fullRepaint) -{ - bool visualIndicator = TilesManager::instance()->getShowVisualIndicator(); - bool measurePerf = fullRepaint && visualIndicator; - -#ifdef DEBUG - visualIndicator = true; - measurePerf = true; -#endif - - if (measurePerf) - m_perfMon.start(TAG_CREATE_BITMAP); - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); - bitmap.allocPixels(); - bitmap.eraseColor(0); - - SkCanvas canvas(bitmap); - canvas.drawARGB(255, 255, 255, 255); - - if (measurePerf) { - m_perfMon.stop(TAG_CREATE_BITMAP); - m_perfMon.start(TAG_DRAW_PICTURE); - } - if (visualIndicator) - canvas.save(); - - canvas.scale(scale, scale); - canvas.translate(-tx, -ty); - int pictureCount = tiledPage->paintBaseLayerContent(&canvas); - - if (measurePerf) { - m_perfMon.stop(TAG_DRAW_PICTURE); - } - if (visualIndicator) { - canvas.restore(); - - int color = 20 + pictureCount % 100; - canvas.drawARGB(color, 0, 255, 0); - - SkPaint paint; - paint.setARGB(128, 255, 0, 0); - paint.setStrokeWidth(3); - canvas.drawLine(0, 0, rect.width(), rect.height(), paint); - paint.setARGB(128, 0, 255, 0); - canvas.drawLine(0, rect.height(), rect.width(), 0, paint); - paint.setARGB(128, 0, 0, 255); - canvas.drawLine(0, 0, rect.width(), 0, paint); - canvas.drawLine(rect.width(), 0, rect.width(), rect.height(), paint); - - drawTileInfo(&canvas, texture, tiledPage, x, y, scale, pictureCount); - } - - if (measurePerf) - m_perfMon.start(TAG_UPDATE_TEXTURE); - GLUtils::paintTextureWithBitmap(textureInfo, texture->getSize(), bitmap, rect.fLeft, rect.fTop); - if (measurePerf) - m_perfMon.stop(TAG_UPDATE_TEXTURE); - - if (measurePerf) - m_perfMon.start(TAG_RESET_BITMAP); - - bitmap.reset(); - - if (measurePerf) - m_perfMon.stop(TAG_RESET_BITMAP); - - return pictureCount; -} - } // namespace WebCore #endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.h b/Source/WebCore/platform/graphics/android/RasterRenderer.h index efe1bd8..218d1b7 100644 --- a/Source/WebCore/platform/graphics/android/RasterRenderer.h +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.h @@ -28,10 +28,11 @@ #if USE(ACCELERATED_COMPOSITING) -#include "PerformanceMonitor.h" +#include "BaseRenderer.h" #include "SkRect.h" class SkCanvas; +class SkDevice; namespace WebCore { @@ -42,26 +43,17 @@ class TiledPage; /** * */ -class RasterRenderer { +class RasterRenderer : public BaseRenderer { public: RasterRenderer(); ~RasterRenderer(); - void drawTileInfo(SkCanvas* canvas, - BaseTileTexture* texture, - TiledPage* tiledPage, - int x, int y, float scale, int pictureCount); +protected: - int renderContent(int x, int y, SkIRect rect, float tx, float ty, - float scale, BaseTileTexture* texture, - TextureInfo* textureInfo, - TiledPage* tiledPage, - bool fullRepaint); + virtual SkDevice* setupDevice(const TileRenderInfo& renderInfo); + virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas); + virtual void drawPerformanceInfo(SkCanvas* canvas); -private: - - // Performance tracking - PerformanceMonitor m_perfMon; }; } // namespace WebCore |