diff options
Diffstat (limited to 'Source')
22 files changed, 611 insertions, 360 deletions
diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk index 638bcb9..9ea7007 100644 --- a/Source/WebCore/Android.mk +++ b/Source/WebCore/Android.mk @@ -632,9 +632,10 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/graphics/WidthIterator.cpp \ \ platform/graphics/android/AndroidAnimation.cpp \ - platform/graphics/android/BackedDoubleBufferedTexture.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 \ platform/graphics/android/ClassTracker.cpp \ platform/graphics/android/DoubleBufferedTexture.cpp \ @@ -662,6 +663,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/graphics/android/PatternAndroid.cpp \ platform/graphics/android/PlatformGraphicsContext.cpp \ platform/graphics/android/PerformanceMonitor.cpp \ + platform/graphics/android/RasterRenderer.cpp \ platform/graphics/android/ScrollableLayerAndroid.cpp \ platform/graphics/android/SharedBufferStream.cpp \ platform/graphics/android/ShaderProgram.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 8a1b587..87bdba4 100644 --- a/Source/WebCore/platform/graphics/android/BaseTile.cpp +++ b/Source/WebCore/platform/graphics/android/BaseTile.cpp @@ -28,24 +28,18 @@ #if USE(ACCELERATED_COMPOSITING) +#include "BaseRenderer.h" #include "GLUtils.h" -#include "SkBitmap.h" -#include "SkBitmapRef.h" -#include "SkCanvas.h" -#include "SkPicture.h" +#include "TextureInfo.h" #include "TilesManager.h" -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> #include <cutils/atomic.h> -#include <wtf/text/CString.h> #ifdef DEBUG #include <cutils/log.h> #include <wtf/CurrentTime.h> +#include <wtf/text/CString.h> #undef XLOG #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "BaseTile", __VA_ARGS__) @@ -59,20 +53,6 @@ namespace WebCore { -static const String TAG_CREATE_BITMAP = "create_bitmap"; -static const String TAG_RECORD_PICTURE = "record_picture"; -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 5 -static const String TAGS[] = { - TAG_CREATE_BITMAP, - TAG_RECORD_PICTURE, - TAG_DRAW_PICTURE, - TAG_UPDATE_TEXTURE, - TAG_RESET_BITMAP -}; - BaseTile::BaseTile() : m_page(0) , m_x(-1) @@ -116,7 +96,7 @@ void BaseTile::setContents(TiledPage* page, int x, int y) void BaseTile::reserveTexture() { - BackedDoubleBufferedTexture* texture = TilesManager::instance()->getAvailableTexture(this); + BaseTileTexture* texture = TilesManager::instance()->getAvailableTexture(this); android::AutoMutex lock(m_atomicSync); if (texture && m_texture != texture) { @@ -126,7 +106,7 @@ void BaseTile::reserveTexture() } } -bool BaseTile::removeTexture(BackedDoubleBufferedTexture* texture) +bool BaseTile::removeTexture(BaseTileTexture* texture) { XLOG("%x removeTexture res: %x... page %x", this, m_texture, m_page); // We update atomically, so paintBitmap() can see the correct value @@ -266,38 +246,6 @@ bool BaseTile::isTileReady() return false; } -void BaseTile::drawTileInfo(SkCanvas* canvas, - BackedDoubleBufferedTexture* texture, - int x, int y, float scale, - int pictureCount) -{ - SkPaint paint; - char str[256]; - snprintf(str, 256, "(%d,%d) %.2f, tl%x tx%x p%x c%x", - x, y, scale, this, texture, m_page, 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]); - total += tagDuration; - snprintf(str, 256, "%s: %.2f", TAGS[i].utf8().data(), tagDuration); - paint.setARGB(255, 0, 0, 0); - int textY = (i * 12) + 25; - canvas->drawText(str, strlen(str), 0, textY, paint); - paint.setARGB(255, 255, 0, 0); - canvas->drawText(str, strlen(str), 0, textY + 1, paint); - } - snprintf(str, 256, "total: %.2f", total); - paint.setARGB(255, 0, 0, 0); - int textY = (TAG_COUNT * 12) + 30; - canvas->drawText(str, strlen(str), 0, textY, paint); - paint.setARGB(255, 255, 0, 0); - canvas->drawText(str, strlen(str), 0, textY + 1, paint); -} - // This is called from the texture generation thread void BaseTile::paintBitmap() { @@ -307,7 +255,7 @@ void BaseTile::paintBitmap() // can be updated by other threads without consequence. m_atomicSync.lock(); bool dirty = m_dirty; - BackedDoubleBufferedTexture* texture = m_texture; + BaseTileTexture* texture = m_texture; SkRegion dirtyArea = *m_currentDirtyArea; float scale = m_scale; const int x = m_x; @@ -330,74 +278,97 @@ void BaseTile::paintBitmap() return; } - SkSize size = texture->getSize(); - float tileWidth = size.width(); - float tileHeight = size.height(); + unsigned int pictureCount = 0; - const float invScale = 1 / scale; - float w = tileWidth * invScale; - float h = tileHeight * invScale; + // 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; - SkCanvas* canvas; - unsigned int pictureCount = 0; + const float tileWidth = renderInfo.tileSize.width(); + const float tileHeight = renderInfo.tileSize.height(); SkRegion::Iterator cliperator(dirtyArea); bool fullRepaint = false; - if (((m_currentDirtyArea == &m_dirtyAreaA) && m_fullRepaintA) || - ((m_currentDirtyArea == &m_dirtyAreaB) && m_fullRepaintB)) + // TODO: Implement the partial invalidate in Surface Texture Mode + if (((m_currentDirtyArea == &m_dirtyAreaA) && m_fullRepaintA) + || ((m_currentDirtyArea == &m_dirtyAreaB) && m_fullRepaintB) + || textureInfo->m_width != tileWidth + || textureInfo->m_height != tileHeight + || textureInfo->getSharedTextureMode() == SurfaceTextureMode) { fullRepaint = true; + } - if (fullRepaint) { - SkIRect rect; - pictureCount = paintPartialBitmap(rect, 0, 0, scale, texture, - textureInfo, tiledPage, true); - } else { + if (!fullRepaint) { while (!cliperator.done()) { SkRect dirtyRect; dirtyRect.set(cliperator.rect()); - float left = x * tileWidth; - float top = y * tileHeight; - // compute the rect to corresponds to pixels SkRect realTileRect; - realTileRect.fLeft = left; - realTileRect.fTop = top; - realTileRect.fRight = left + tileWidth; - realTileRect.fBottom = top + tileHeight; + realTileRect.fLeft = x * tileWidth; + realTileRect.fTop = y * tileHeight; + realTileRect.fRight = realTileRect.fLeft + tileWidth; + realTileRect.fBottom = realTileRect.fTop + tileHeight; // scale the dirtyRect for intersect computation. SkRect realDirtyRect = SkRect::MakeWH(dirtyRect.width() * scale, dirtyRect.height() * scale); realDirtyRect.offset(dirtyRect.fLeft * scale, dirtyRect.fTop * scale); + // set realTileRect to the intersection of itself and the dirty rect if (!realTileRect.intersect(realDirtyRect)) { cliperator.next(); continue; } - realTileRect.fLeft = floorf(realTileRect.fLeft); - realTileRect.fTop = floorf(realTileRect.fTop); - realTileRect.fRight = ceilf(realTileRect.fRight); - realTileRect.fBottom = ceilf(realTileRect.fBottom); - + // initialize finalRealRect to the rounded values of realTileRect SkIRect finalRealRect; - finalRealRect.fLeft = static_cast<int>(realTileRect.fLeft) % static_cast<int>(tileWidth); - finalRealRect.fTop = static_cast<int>(realTileRect.fTop) % static_cast<int>(tileHeight); - finalRealRect.fRight = finalRealRect.fLeft + realTileRect.width(); - finalRealRect.fBottom = finalRealRect.fTop + realTileRect.height(); + realTileRect.roundOut(&finalRealRect); + + // stash the int values of the current width and height + const int iWidth = finalRealRect.width(); + const int iHeight = finalRealRect.height(); + + if (iWidth == tileWidth || iHeight == tileHeight) { + fullRepaint = true; + break; + } - // the canvas translate can be recomputed accounting for the scale - float tx = - realTileRect.fLeft / scale; - float ty = - realTileRect.fTop / scale; + // translate the rect into tile space coordinates + finalRealRect.fLeft = finalRealRect.fLeft % static_cast<int>(tileWidth); + finalRealRect.fTop = finalRealRect.fTop % static_cast<int>(tileHeight); + finalRealRect.fRight = finalRealRect.fLeft + iWidth; + finalRealRect.fBottom = finalRealRect.fTop + iHeight; - pictureCount = paintPartialBitmap(finalRealRect, tx, ty, scale, texture, - textureInfo, tiledPage); + renderInfo.invalRect = &finalRealRect; + renderInfo.invalX = realTileRect.fLeft / scale; + renderInfo.invalY = realTileRect.fTop / scale; + renderInfo.measurePerf = false; + + pictureCount = m_renderer.renderTiledContent(renderInfo); cliperator.next(); } } + + if (fullRepaint) { + SkIRect rect; + rect.set(0, 0, tileWidth, tileHeight); + + 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); m_atomicSync.lock(); @@ -422,7 +393,9 @@ void BaseTile::paintBitmap() if (m_scale != scale) m_dirty = true; - if (!fullRepaint) + if (fullRepaint) + m_currentDirtyArea->setEmpty(); + else m_currentDirtyArea->op(dirtyArea, SkRegion::kDifference_Op); if (!m_currentDirtyArea->isEmpty()) @@ -442,101 +415,6 @@ void BaseTile::paintBitmap() m_atomicSync.unlock(); } -int BaseTile::paintPartialBitmap(SkIRect r, float ptx, float pty, - float scale, BackedDoubleBufferedTexture* texture, - TextureInfo* textureInfo, - TiledPage* tiledPage, bool fullRepaint) -{ - SkIRect rect = r; - float tx = ptx; - float ty = pty; - // TODO: Implement the partial invalidate in Surface Texture Mode - if (!GLUtils::textureExist(textureInfo, texture->bitmap()) - || textureInfo->getSharedTextureMode() == SurfaceTextureMode) { - fullRepaint = true; - } - - if ((rect.width() > TilesManager::instance()->tileWidth()) || - (rect.height() > TilesManager::instance()->tileHeight())) - fullRepaint = true; - - if (fullRepaint) { - rect.set(0, 0, TilesManager::instance()->tileWidth(), - TilesManager::instance()->tileHeight()); - tx = - x() * TilesManager::instance()->tileWidth() / scale; - ty = - y() * TilesManager::instance()->tileHeight() / scale; - } - bool visualIndicator = TilesManager::instance()->getShowVisualIndicator(); - bool measurePerf = fullRepaint && visualIndicator; - - 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_RECORD_PICTURE); - } - SkPicture picture; - SkCanvas* nCanvas = picture.beginRecording(rect.width(), rect.height()); - nCanvas->scale(scale, scale); - nCanvas->translate(tx, ty); - int pictureCount = tiledPage->paintBaseLayerContent(nCanvas); - picture.endRecording(); - - if (measurePerf) { - m_perfMon.stop(TAG_RECORD_PICTURE); - m_perfMon.start(TAG_DRAW_PICTURE); - } - if (visualIndicator) - canvas.save(); - picture.draw(&canvas); - if (visualIndicator) - canvas.restore(); - if (measurePerf) { - m_perfMon.stop(TAG_DRAW_PICTURE); - } - - if (visualIndicator) { - 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, x(), y(), scale, pictureCount); - } - - 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); - - 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/BaseTile.h b/Source/WebCore/platform/graphics/android/BaseTile.h index a48378b..cddaa60 100644 --- a/Source/WebCore/platform/graphics/android/BaseTile.h +++ b/Source/WebCore/platform/graphics/android/BaseTile.h @@ -28,24 +28,18 @@ #if USE(ACCELERATED_COMPOSITING) -#include "HashMap.h" -#include "PerformanceMonitor.h" -#include "TextureInfo.h" -#include "SkBitmap.h" -#include "SkCanvas.h" +#include "RasterRenderer.h" #include "SkRect.h" #include "SkRegion.h" #include "TextureOwner.h" -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <GLES2/gl2.h> #include <utils/threads.h> namespace WebCore { +class TextureInfo; class TiledPage; -class BackedDoubleBufferedTexture; +class BaseTileTexture; /** * An individual tile that is used to construct part of a webpage's BaseLayer of @@ -80,13 +74,10 @@ public: // the only thread-safe function called by the background thread void paintBitmap(); int paintPartialBitmap(SkIRect rect, float tx, float ty, - float scale, BackedDoubleBufferedTexture* texture, + float scale, BaseTileTexture* texture, TextureInfo* textureInfo, TiledPage* tiledPage, bool fullRepaint = false); - void drawTileInfo(SkCanvas* canvas, - BackedDoubleBufferedTexture* texture, - int x, int y, float scale, int pictureCount); void markAsDirty(const unsigned int pictureCount, const SkRegion& dirtyArea); @@ -101,10 +92,10 @@ public: int x() const { return m_x; } int y() const { return m_y; } unsigned int lastPaintedPicture() const { return m_lastPaintedPicture; } - BackedDoubleBufferedTexture* texture() { return m_texture; } + BaseTileTexture* texture() { return m_texture; } // TextureOwner implementation - virtual bool removeTexture(BackedDoubleBufferedTexture* texture); + virtual bool removeTexture(BaseTileTexture* texture); virtual TiledPage* page() { return m_page; } private: @@ -114,7 +105,7 @@ private: int m_y; // The remaining variables can be updated throughout the lifetime of the object - BackedDoubleBufferedTexture* m_texture; + BaseTileTexture* m_texture; float m_scale; // used to signal that the that the tile is out-of-date and needs to be redrawn bool m_dirty; @@ -144,8 +135,7 @@ private: // across all threads and cores. android::Mutex m_atomicSync; - // Performance tracking - PerformanceMonitor m_perfMon; + RasterRenderer m_renderer; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp b/Source/WebCore/platform/graphics/android/BaseTileTexture.cpp index 0e22103..ee8cebf 100644 --- a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp +++ b/Source/WebCore/platform/graphics/android/BaseTileTexture.cpp @@ -24,7 +24,7 @@ */ #include "config.h" -#include "BackedDoubleBufferedTexture.h" +#include "BaseTileTexture.h" #include "BaseTile.h" #include "ClassTracker.h" @@ -33,65 +33,38 @@ #include "TilesManager.h" #define LOG_NDEBUG 1 -#define LOG_TAG "BackedDoubleBufferedTexture.cpp" +#define LOG_TAG "BaseTileTexture.cpp" #include <utils/Log.h> namespace WebCore { -BackedDoubleBufferedTexture::BackedDoubleBufferedTexture(uint32_t w, uint32_t h, - SkBitmap* bitmap, - SkBitmap::Config config) +BaseTileTexture::BaseTileTexture(uint32_t w, uint32_t h) : DoubleBufferedTexture(eglGetCurrentContext(), SurfaceTextureMode) , m_usedLevel(-1) - , m_config(config) , m_owner(0) , m_delayedReleaseOwner(0) , m_delayedRelease(false) , m_busy(false) { m_size.set(w, h); - if (bitmap) { - m_bitmap = bitmap; - m_sharedBitmap = true; - m_canvas = new SkCanvas(*m_bitmap); - } else { - m_bitmap = 0; - m_sharedBitmap = false; - m_canvas = 0; - } #ifdef DEBUG_COUNT - ClassTracker::instance()->increment("BackedDoubleBufferedTexture"); + ClassTracker::instance()->increment("BaseTileTexture"); #endif } -SkCanvas* BackedDoubleBufferedTexture::canvas() -{ - if (!m_bitmap && !m_sharedBitmap) { - m_bitmap = new SkBitmap(); - m_bitmap->setConfig(m_config, m_size.width(), m_size.height()); - m_bitmap->allocPixels(); - m_bitmap->eraseColor(0); - m_canvas = new SkCanvas(*m_bitmap); - } - return m_canvas; -} - -BackedDoubleBufferedTexture::~BackedDoubleBufferedTexture() +BaseTileTexture::~BaseTileTexture() { - if (!m_sharedBitmap) - delete m_bitmap; - delete m_canvas; if (m_sharedTextureMode == EglImageMode) { SharedTexture* textures[3] = { m_textureA, m_textureB, 0 }; destroyTextures(textures); } #ifdef DEBUG_COUNT - ClassTracker::instance()->decrement("BackedDoubleBufferedTexture"); + ClassTracker::instance()->decrement("BaseTileTexture"); #endif } -void BackedDoubleBufferedTexture::destroyTextures(SharedTexture** textures) +void BaseTileTexture::destroyTextures(SharedTexture** textures) { int x = 0; while (textures[x]) { @@ -108,7 +81,7 @@ void BackedDoubleBufferedTexture::destroyTextures(SharedTexture** textures) } } -TextureInfo* BackedDoubleBufferedTexture::producerLock() +TextureInfo* BaseTileTexture::producerLock() { m_busyLock.lock(); m_busy = true; @@ -116,19 +89,19 @@ TextureInfo* BackedDoubleBufferedTexture::producerLock() return DoubleBufferedTexture::producerLock(); } -void BackedDoubleBufferedTexture::producerRelease() +void BaseTileTexture::producerRelease() { DoubleBufferedTexture::producerRelease(); setNotBusy(); } -void BackedDoubleBufferedTexture::producerReleaseAndSwap() +void BaseTileTexture::producerReleaseAndSwap() { DoubleBufferedTexture::producerReleaseAndSwap(); setNotBusy(); } -void BackedDoubleBufferedTexture::setNotBusy() +void BaseTileTexture::setNotBusy() { android::Mutex::Autolock lock(m_busyLock); m_busy = false; @@ -142,36 +115,26 @@ void BackedDoubleBufferedTexture::setNotBusy() m_busyCond.signal(); } -bool BackedDoubleBufferedTexture::busy() +bool BaseTileTexture::busy() { android::Mutex::Autolock lock(m_busyLock); return m_busy; } -void BackedDoubleBufferedTexture::producerUpdate(TextureInfo* textureInfo) +void BaseTileTexture::producerUpdate(TextureInfo* textureInfo, const SkBitmap& bitmap) { - if (!m_bitmap) - return; - // no need to upload a texture since the bitmap is empty - if (!m_bitmap->width() && !m_bitmap->height()) { + if (!bitmap.width() && !bitmap.height()) { producerRelease(); return; } - GLUtils::paintTextureWithBitmap(textureInfo, m_bitmap, 0, 0, this); - - if (!m_sharedBitmap) { - delete m_bitmap; - delete m_canvas; - m_bitmap = 0; - m_canvas = 0; - } + GLUtils::paintTextureWithBitmap(textureInfo, m_size, bitmap, 0, 0); producerReleaseAndSwap(); } -bool BackedDoubleBufferedTexture::acquire(TextureOwner* owner, bool force) +bool BaseTileTexture::acquire(TextureOwner* owner, bool force) { if (m_owner == owner) { if (m_delayedRelease) { @@ -184,7 +147,7 @@ bool BackedDoubleBufferedTexture::acquire(TextureOwner* owner, bool force) return setOwner(owner, force); } -bool BackedDoubleBufferedTexture::tryAcquire(TextureOwner* owner, TiledPage* currentPage, TiledPage* nextPage) +bool BaseTileTexture::tryAcquire(TextureOwner* owner, TiledPage* currentPage, TiledPage* nextPage) { m_busyLock.lock(); if (!m_busy @@ -198,7 +161,7 @@ bool BackedDoubleBufferedTexture::tryAcquire(TextureOwner* owner, TiledPage* cur return false; } -bool BackedDoubleBufferedTexture::setOwner(TextureOwner* owner, bool force) +bool BaseTileTexture::setOwner(TextureOwner* owner, bool force) { // if the writable texture is busy (i.e. currently being written to) then we // can't change the owner out from underneath that texture @@ -215,7 +178,7 @@ bool BackedDoubleBufferedTexture::setOwner(TextureOwner* owner, bool force) // first and paintBitmapGL() will bail out, or we execute it after, // and paintBitmapGL() will mark the texture as busy before // relinquishing the lock. LayerAndroid::removeTexture() will call - // BackedDoubleBufferedTexture::release(), which will then do nothing + // BaseTileTexture::release(), which will then do nothing // if the texture is busy and we then don't return true. bool proceed = true; if (m_owner && m_owner != owner) @@ -229,7 +192,7 @@ bool BackedDoubleBufferedTexture::setOwner(TextureOwner* owner, bool force) return false; } -bool BackedDoubleBufferedTexture::release(TextureOwner* owner) +bool BaseTileTexture::release(TextureOwner* owner) { android::Mutex::Autolock lock(m_busyLock); if (m_owner != owner) @@ -244,7 +207,7 @@ bool BackedDoubleBufferedTexture::release(TextureOwner* owner) return true; } -void BackedDoubleBufferedTexture::setTile(TextureInfo* info, int x, int y, +void BaseTileTexture::setTile(TextureInfo* info, int x, int y, float scale, unsigned int pictureCount) { TextureTileInfo* textureInfo = m_texturesInfo.get(getWriteableTexture()); @@ -258,7 +221,7 @@ void BackedDoubleBufferedTexture::setTile(TextureInfo* info, int x, int y, m_texturesInfo.set(getWriteableTexture(), textureInfo); } -bool BackedDoubleBufferedTexture::readyFor(BaseTile* baseTile) +bool BaseTileTexture::readyFor(BaseTile* baseTile) { TextureTileInfo* info = m_texturesInfo.get(getReadableTexture()); if (info && diff --git a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h b/Source/WebCore/platform/graphics/android/BaseTileTexture.h index 89ea771..0a7534a 100644 --- a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h +++ b/Source/WebCore/platform/graphics/android/BaseTileTexture.h @@ -23,8 +23,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef BackedDoubleBufferedTexture_h -#define BackedDoubleBufferedTexture_h +#ifndef BaseTileTexture_h +#define BaseTileTexture_h #include "DoubleBufferedTexture.h" #include "GLWebViewState.h" @@ -57,14 +57,12 @@ class TextureTileInfo { }; // DoubleBufferedTexture using a SkBitmap as backing mechanism -class BackedDoubleBufferedTexture : public DoubleBufferedTexture { +class BaseTileTexture : public DoubleBufferedTexture { public: // This object is to be constructed on the consumer's thread and must have // a width and height greater than 0. - BackedDoubleBufferedTexture(uint32_t w, uint32_t h, - SkBitmap* bitmap = 0, - SkBitmap::Config config = SkBitmap::kARGB_8888_Config); - virtual ~BackedDoubleBufferedTexture(); + BaseTileTexture(uint32_t w, uint32_t h); + virtual ~BaseTileTexture(); // these functions override their parent virtual TextureInfo* producerLock(); @@ -73,8 +71,7 @@ public: // updates the texture with current bitmap and releases (and if needed also // swaps) the texture. - virtual void producerUpdate(TextureInfo* textureInfo); - void producerUpdate(TextureInfo* textureInfo, SkBitmap* bitmap, SkIRect& rect); + virtual void producerUpdate(TextureInfo* textureInfo, const SkBitmap& bitmap); // The level can be one of the following values: // * -1 for an unused texture. @@ -97,8 +94,6 @@ public: // private member accessor functions TextureOwner* owner() { return m_owner; } // only used by the consumer thread TextureOwner* delayedReleaseOwner() { return m_delayedReleaseOwner; } - SkCanvas* canvas(); // only used by the producer thread - SkBitmap* bitmap() { return m_bitmap; } bool busy(); void setNotBusy(); @@ -114,10 +109,7 @@ protected: private: void destroyTextures(SharedTexture** textures); - SkBitmap* m_bitmap; - bool m_sharedBitmap; SkSize m_size; - SkCanvas* m_canvas; int m_usedLevel; SkBitmap::Config m_config; TextureOwner* m_owner; @@ -142,4 +134,4 @@ private: } // namespace WebCore -#endif // BackedDoubleBufferedTexture_h +#endif // BaseTileTexture_h diff --git a/Source/WebCore/platform/graphics/android/GLUtils.cpp b/Source/WebCore/platform/graphics/android/GLUtils.cpp index 29608cf..e32f1e9 100644 --- a/Source/WebCore/platform/graphics/android/GLUtils.cpp +++ b/Source/WebCore/platform/graphics/android/GLUtils.cpp @@ -336,45 +336,36 @@ 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) + const SkSize& requiredSize, + const SkBitmap& bitmap, + int x, int y) { SharedTextureMode mode = textureInfo->getSharedTextureMode(); - if (textureExist(textureInfo, texture->bitmap())) { + if (requiredSize.equals(textureInfo->m_width, textureInfo->m_height)) { if (mode == EglImageMode) - GLUtils::updateTextureWithBitmap(textureInfo->m_textureId, x, y, *bitmap); + GLUtils::updateTextureWithBitmap(textureInfo->m_textureId, x, y, bitmap); else if (mode == SurfaceTextureMode) - GLUtils::updateSurfaceTextureWithBitmap(textureInfo, x, y, *bitmap); + GLUtils::updateSurfaceTextureWithBitmap(textureInfo, x, y, bitmap); } else { + + if (!requiredSize.equals(bitmap.width(), bitmap.height())) { + XLOG("The bitmap size (%d,%d) does not equal the texture size (%d,%d)", + bitmap.width(), bitmap.height(), + requiredSize.width(), requiredSize.height()); + } + if (mode == EglImageMode) - GLUtils::createTextureWithBitmap(textureInfo->m_textureId, *bitmap); + GLUtils::createTextureWithBitmap(textureInfo->m_textureId, bitmap); else if (mode == SurfaceTextureMode) - GLUtils::createSurfaceTextureWithBitmap(textureInfo, *bitmap); + GLUtils::createSurfaceTextureWithBitmap(textureInfo, bitmap); - textureInfo->m_width = bitmap->width(); - textureInfo->m_height = bitmap->height(); + textureInfo->m_width = bitmap.width(); + textureInfo->m_height = bitmap.height(); } } -void GLUtils::createSurfaceTextureWithBitmap(TextureInfo* texture, SkBitmap& bitmap, GLint filter) +void GLUtils::createSurfaceTextureWithBitmap(TextureInfo* texture, const SkBitmap& bitmap, GLint filter) { sp<android::SurfaceTexture> surfaceTexture = texture->m_surfaceTexture; sp<ANativeWindow> ANW = texture->m_ANW; @@ -394,7 +385,7 @@ void GLUtils::createSurfaceTextureWithBitmap(TextureInfo* texture, SkBitmap& bit updateSurfaceTextureWithBitmap(texture, 0, 0, bitmap, filter); } -void GLUtils::updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, SkBitmap& bitmap, GLint filter) +void GLUtils::updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, const SkBitmap& bitmap, GLint filter) { sp<android::SurfaceTexture> surfaceTexture = texture->m_surfaceTexture; sp<ANativeWindow> ANW = texture->m_ANW; @@ -431,7 +422,7 @@ void GLUtils::updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, checkSurfaceTextureError("queueBuffer", status); } -void GLUtils::createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint filter) +void GLUtils::createTextureWithBitmap(GLuint texture, const SkBitmap& bitmap, GLint filter) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, texture); @@ -462,7 +453,7 @@ void GLUtils::createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint fi glDeleteFramebuffers(1, &fboID); } -void GLUtils::updateTextureWithBitmap(GLuint texture, int x, int y, SkBitmap& bitmap, GLint filter) +void GLUtils::updateTextureWithBitmap(GLuint texture, int x, int y, const SkBitmap& bitmap, GLint filter) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, texture); diff --git a/Source/WebCore/platform/graphics/android/GLUtils.h b/Source/WebCore/platform/graphics/android/GLUtils.h index 85656f1..a015136 100644 --- a/Source/WebCore/platform/graphics/android/GLUtils.h +++ b/Source/WebCore/platform/graphics/android/GLUtils.h @@ -28,9 +28,9 @@ #if USE(ACCELERATED_COMPOSITING) -#include "BackedDoubleBufferedTexture.h" #include "SkBitmap.h" #include "SkMatrix.h" +#include "SkSize.h" #include "TextureInfo.h" #include "TransformationMatrix.h" #include <EGL/egl.h> @@ -64,16 +64,15 @@ public: static void deleteTexture(GLuint* texture); 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, int x, int y, SkBitmap& bitmap, GLint filter = GL_LINEAR); + static void createTextureWithBitmap(GLuint texture, const SkBitmap& bitmap, GLint filter = GL_LINEAR); + static void updateTextureWithBitmap(GLuint texture, int x, int y, const 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 paintTextureWithBitmap(TextureInfo* textureInfo, const SkSize& requiredSize, const SkBitmap& bitmap, int x, int y); - 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); + static void createSurfaceTextureWithBitmap(TextureInfo* texture, const SkBitmap& bitmap, GLint filter = GL_LINEAR); + static void updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, const SkBitmap& bitmap, GLint filter = GL_LINEAR); }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp index 74b246f..e90829a 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -163,7 +163,7 @@ LayerAndroid::LayerAndroid(SkPicture* picture) : SkLayer(), #endif } -bool LayerAndroid::removeTexture(BackedDoubleBufferedTexture* aTexture) +bool LayerAndroid::removeTexture(BaseTileTexture* aTexture) { LayerTexture* texture = static_cast<LayerTexture*>(aTexture); android::AutoMutex lock(m_atomicSync); @@ -1051,14 +1051,21 @@ void LayerAndroid::paintBitmapGL() } XLOG("LayerAndroid %d %x (%.2f, %.2f) paintBitmapGL WE ARE PAINTING", uniqueId(), this, getWidth(), getHeight()); - SkCanvas* canvas = texture->canvas(); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, texture->getSize().width(), texture->getSize().height()); + bitmap.allocPixels(); + + SkCanvas canvas(bitmap); + canvas.drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); + float scale = texture->scale(); IntRect textureRect = texture->rect(); - canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); + if (m_contentsImage) { - contentDraw(canvas); + contentDraw(&canvas); } else { SkPicture picture; SkCanvas* nCanvas = picture.beginRecording(textureRect.width(), @@ -1067,9 +1074,9 @@ void LayerAndroid::paintBitmapGL() nCanvas->translate(-textureRect.x(), -textureRect.y()); contentDraw(nCanvas); picture.endRecording(); - picture.draw(canvas); + picture.draw(&canvas); } - extraDraw(canvas); + extraDraw(&canvas); m_atomicSync.lock(); texture->setTextureInfoFor(this); @@ -1078,7 +1085,7 @@ void LayerAndroid::paintBitmapGL() m_requestSent = false; XLOG("LayerAndroid %d paintBitmapGL PAINTING DONE, updating the texture", uniqueId()); - texture->producerUpdate(textureInfo); + texture->producerUpdate(textureInfo, bitmap); m_atomicSync.unlock(); diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.h b/Source/WebCore/platform/graphics/android/LayerAndroid.h index fe41e35..551e020 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.h @@ -84,7 +84,7 @@ struct SkLength { namespace WebCore { class AndroidAnimation; -class BackedDoubleBufferedTexture; +class BaseTileTexture; class LayerAndroidFindState; class RenderLayer; class TiledPage; @@ -98,7 +98,7 @@ public: virtual ~LayerAndroid(); // TextureOwner methods - virtual bool removeTexture(BackedDoubleBufferedTexture* texture); + virtual bool removeTexture(BaseTileTexture* texture); LayerTexture* texture() { return m_reservedTexture; } virtual TiledPage* page() { return 0; } diff --git a/Source/WebCore/platform/graphics/android/LayerTexture.h b/Source/WebCore/platform/graphics/android/LayerTexture.h index be3594f..7a6c369 100644 --- a/Source/WebCore/platform/graphics/android/LayerTexture.h +++ b/Source/WebCore/platform/graphics/android/LayerTexture.h @@ -26,17 +26,16 @@ #ifndef LayerTexture_h #define LayerTexture_h -#include "BackedDoubleBufferedTexture.h" +#include "BaseTileTexture.h" #include "ClassTracker.h" #include "IntRect.h" namespace WebCore { -class LayerTexture : public BackedDoubleBufferedTexture { +class LayerTexture : public BaseTileTexture { public: - LayerTexture(uint32_t w, uint32_t h, - SkBitmap::Config config = SkBitmap::kARGB_8888_Config) - : BackedDoubleBufferedTexture(w, h, 0, config) + LayerTexture(uint32_t w, uint32_t h) + : BaseTileTexture(w, h) , m_layerId(0) , m_scale(1) , m_ready(false) diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.cpp b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp new file mode 100644 index 0000000..025dbae --- /dev/null +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp @@ -0,0 +1,145 @@ +/* + * 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 "RasterRenderer.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, "RasterRenderer", __VA_ARGS__) + +#else + +#undef XLOG +#define XLOG(...) + +#endif // DEBUG + +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"; +#define TAG_COUNT 4 +static const String TAGS[] = { + TAG_CREATE_BITMAP, + TAG_DRAW_PICTURE, + TAG_UPDATE_TEXTURE, +}; + +RasterRenderer::RasterRenderer() : BaseRenderer(BaseRenderer::Raster) +{ +#ifdef DEBUG_COUNT + ClassTracker::instance()->increment("RasterRenderer"); +#endif +} + +RasterRenderer::~RasterRenderer() +{ +#ifdef DEBUG_COUNT + ClassTracker::instance()->decrement("RasterRenderer"); +#endif +} + +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]; + float total = 0; + for (int i = 0; i < TAG_COUNT; i++) { + float tagDuration = m_perfMon.getAverageDuration(TAGS[i]); + total += tagDuration; + snprintf(str, 256, "%s: %.2f", TAGS[i].utf8().data(), tagDuration); + paint.setARGB(255, 0, 0, 0); + int textY = (i * 12) + 25; + canvas->drawText(str, strlen(str), 0, textY, paint); + paint.setARGB(255, 255, 0, 0); + canvas->drawText(str, strlen(str), 0, textY + 1, paint); + } + snprintf(str, 256, "total: %.2f", total); + paint.setARGB(255, 0, 0, 0); + int textY = (TAG_COUNT * 12) + 30; + canvas->drawText(str, strlen(str), 0, textY, paint); + paint.setARGB(255, 255, 0, 0); + canvas->drawText(str, strlen(str), 0, textY + 1, paint); +} + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.h b/Source/WebCore/platform/graphics/android/RasterRenderer.h new file mode 100644 index 0000000..218d1b7 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.h @@ -0,0 +1,62 @@ +/* + * 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 RasterRenderer_h +#define RasterRenderer_h + +#if USE(ACCELERATED_COMPOSITING) + +#include "BaseRenderer.h" +#include "SkRect.h" + +class SkCanvas; +class SkDevice; + +namespace WebCore { + +class BaseTileTexture; +class TextureInfo; +class TiledPage; + +/** + * + */ +class RasterRenderer : public BaseRenderer { +public: + RasterRenderer(); + ~RasterRenderer(); + +protected: + + virtual SkDevice* setupDevice(const TileRenderInfo& renderInfo); + virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas); + virtual void drawPerformanceInfo(SkCanvas* canvas); + +}; + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) +#endif // RasterRenderer_h diff --git a/Source/WebCore/platform/graphics/android/SharedTexture.cpp b/Source/WebCore/platform/graphics/android/SharedTexture.cpp index cbe44da..4f52107 100644 --- a/Source/WebCore/platform/graphics/android/SharedTexture.cpp +++ b/Source/WebCore/platform/graphics/android/SharedTexture.cpp @@ -78,6 +78,7 @@ SharedTexture::~SharedTexture() else if (m_sharedTextureMode == SurfaceTextureMode) { m_sourceTexture->m_surfaceTexture.clear(); m_sourceTexture->m_ANW.clear(); + GLUtils::deleteTexture(&m_sourceTexture->m_textureId); } delete m_sourceTexture; delete m_targetTexture; diff --git a/Source/WebCore/platform/graphics/android/TextureOwner.h b/Source/WebCore/platform/graphics/android/TextureOwner.h index aebbf90..bd3a291 100644 --- a/Source/WebCore/platform/graphics/android/TextureOwner.h +++ b/Source/WebCore/platform/graphics/android/TextureOwner.h @@ -29,12 +29,12 @@ namespace WebCore { class TiledPage; -class BackedDoubleBufferedTexture; +class BaseTileTexture; class TextureOwner { public: virtual ~TextureOwner() { } - virtual bool removeTexture(BackedDoubleBufferedTexture* texture) = 0; + virtual bool removeTexture(BaseTileTexture* texture) = 0; virtual TiledPage* page() = 0; }; diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp index 0e91dc7..b4df0a1 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp @@ -96,10 +96,6 @@ TilesManager::TilesManager() { XLOG("TilesManager ctor"); m_textures.reserveCapacity(MAX_TEXTURE_ALLOCATION); - m_tilesBitmap = new SkBitmap(); - m_tilesBitmap->setConfig(SkBitmap::kARGB_8888_Config, tileWidth(), tileHeight()); - m_tilesBitmap->allocPixels(); - m_tilesBitmap->eraseColor(0); m_pixmapsGenerationThread = new TexturesGenerator(); m_pixmapsGenerationThread->run("TexturesGenerator"); } @@ -110,12 +106,12 @@ void TilesManager::allocateTiles() XLOG("%d tiles to allocate (%d textures planned)", nbTexturesToAllocate, m_maxTextureCount); int nbTexturesAllocated = 0; for (int i = 0; i < nbTexturesToAllocate; i++) { - BackedDoubleBufferedTexture* texture = new BackedDoubleBufferedTexture( - tileWidth(), tileHeight(), m_tilesBitmap); + BaseTileTexture* texture = new BaseTileTexture( + tileWidth(), tileHeight()); // the atomic load ensures that the texture has been fully initialized // before we pass a pointer for other threads to operate on - BackedDoubleBufferedTexture* loadedTexture = - reinterpret_cast<BackedDoubleBufferedTexture*>( + BaseTileTexture* loadedTexture = + reinterpret_cast<BaseTileTexture*>( android_atomic_acquire_load(reinterpret_cast<int32_t*>(&texture))); m_textures.append(loadedTexture); nbTexturesAllocated++; @@ -128,7 +124,7 @@ void TilesManager::printTextures() #ifdef DEBUG XLOG("++++++"); for (unsigned int i = 0; i < m_textures.size(); i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; BaseTile* o = 0; if (texture->owner()) o = (BaseTile*) texture->owner(); @@ -150,7 +146,7 @@ void TilesManager::resetTextureUsage(TiledPage* page) { android::Mutex::Autolock lock(m_texturesLock); for (unsigned int i = 0; i < m_textures.size(); i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; TextureOwner* owner = texture->owner(); if (owner) { if (owner->page() == page) @@ -159,7 +155,7 @@ void TilesManager::resetTextureUsage(TiledPage* page) } } -BackedDoubleBufferedTexture* TilesManager::getAvailableTexture(BaseTile* owner) +BaseTileTexture* TilesManager::getAvailableTexture(BaseTile* owner) { android::Mutex::Autolock lock(m_texturesLock); @@ -177,11 +173,11 @@ BackedDoubleBufferedTexture* TilesManager::getAvailableTexture(BaseTile* owner) // 3. return any texture not used by the tile's page or the page's sibiling // // The texture level indicates a tiles closeness to the current viewport - BackedDoubleBufferedTexture* farthestTexture = 0; + BaseTileTexture* farthestTexture = 0; int farthestTextureLevel = 0; const unsigned int max = m_textures.size(); for (unsigned int i = 0; i < max; i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; if (texture->usedLevel() == -1) { // found an unused texture, grab it farthestTexture = texture; break; @@ -204,7 +200,7 @@ BackedDoubleBufferedTexture* TilesManager::getAvailableTexture(BaseTile* owner) TiledPage* currentPage = owner->page(); TiledPage* nextPage = currentPage->sibling(); for (unsigned int i = 0; i < max; i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; if (texture->tryAcquire(owner, currentPage, nextPage)) { XLOG("grab a texture that wasn't ours, (%x != %x) at %d => texture %x", owner->page(), texture->owner()->page(), i, texture); diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h index e43afed..5237c14 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.h +++ b/Source/WebCore/platform/graphics/android/TilesManager.h @@ -28,8 +28,8 @@ #if USE(ACCELERATED_COMPOSITING) -#include "BackedDoubleBufferedTexture.h" #include "BaseTile.h" +#include "BaseTileTexture.h" #include "LayerAndroid.h" #include "LayerTexture.h" #include "ShaderProgram.h" @@ -79,7 +79,7 @@ public: ShaderProgram* shader() { return &m_shader; } VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; } - BackedDoubleBufferedTexture* getAvailableTexture(BaseTile* owner); + BaseTileTexture* getAvailableTexture(BaseTile* owner); void printLayersTextures(const char* s); void cleanupLayersTextures(LayerAndroid* layer, bool forceCleanup = false); @@ -134,7 +134,7 @@ private: m_generatorReadyCond.wait(m_generatorLock); } - Vector<BackedDoubleBufferedTexture*> m_textures; + Vector<BaseTileTexture*> m_textures; Vector<LayerTexture*> m_layersTextures; unsigned int m_layersMemoryUsage; @@ -156,7 +156,6 @@ private: ShaderProgram m_shader; VideoLayerManager m_videoLayerManager; - SkBitmap* m_tilesBitmap; }; } // namespace WebCore diff --git a/Source/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/Source/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index e293e97..9ee0de2 100644 --- a/Source/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/Source/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -488,7 +488,7 @@ void WebUrlLoaderClient::reportSslCertError(int cert_error, net::X509Certificate std::vector<std::string> chain_bytes; cert->GetChainDEREncodedBytes(&chain_bytes); this->AddRef(); - m_webFrame->reportSslCertError(this, cert_error, chain_bytes[0]); + m_webFrame->reportSslCertError(this, cert_error, chain_bytes[0], m_request->getUrl()); } void WebUrlLoaderClient::requestClientCert(net::SSLCertRequestInfo* cert_request_info) diff --git a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp index cd9cdba..fb558c6 100644 --- a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -288,7 +288,7 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* mJavaFrame->mGetFile = env->GetMethodID(clazz, "getFile", "(Ljava/lang/String;[BII)I"); mJavaFrame->mDidReceiveAuthenticationChallenge = env->GetMethodID(clazz, "didReceiveAuthenticationChallenge", "(ILjava/lang/String;Ljava/lang/String;Z)V"); - mJavaFrame->mReportSslCertError = env->GetMethodID(clazz, "reportSslCertError", "(II[B)V"); + mJavaFrame->mReportSslCertError = env->GetMethodID(clazz, "reportSslCertError", "(II[BLjava/lang/String;)V"); mJavaFrame->mRequestClientCert = env->GetMethodID(clazz, "requestClientCert", "(I[B)V"); mJavaFrame->mDownloadStart = env->GetMethodID(clazz, "downloadStart", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V"); @@ -966,7 +966,7 @@ WebFrame::didReceiveAuthenticationChallenge(WebUrlLoaderClient* client, const st #endif void -WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert) +WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert, const std::string& url) { #ifdef ANDROID_INSTRUMENT TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter); @@ -982,8 +982,11 @@ WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const s jbyte* bytes = env->GetByteArrayElements(jCert, NULL); cert.copy(reinterpret_cast<char*>(bytes), len); - env->CallVoidMethod(javaFrame.get(), mJavaFrame->mReportSslCertError, jHandle, cert_error, jCert); + jstring jUrl = env->NewStringUTF(url.c_str()); + + env->CallVoidMethod(javaFrame.get(), mJavaFrame->mReportSslCertError, jHandle, cert_error, jCert, jUrl); env->DeleteLocalRef(jCert); + env->DeleteLocalRef(jUrl); checkException(env); } diff --git a/Source/WebKit/android/jni/WebCoreFrameBridge.h b/Source/WebKit/android/jni/WebCoreFrameBridge.h index d74948f..acf4eb4 100644 --- a/Source/WebKit/android/jni/WebCoreFrameBridge.h +++ b/Source/WebKit/android/jni/WebCoreFrameBridge.h @@ -117,7 +117,7 @@ class WebFrame : public WebCoreRefObject { void didReceiveAuthenticationChallenge(WebUrlLoaderClient*, const std::string& host, const std::string& realm, bool useCachedCredentials); - void reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert); + void reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert, const std::string& url); void requestClientCert(WebUrlLoaderClient* client, const std::string& host_and_port); diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp index 236c07b..e0bb6b4 100644 --- a/Source/WebKit/android/nav/WebView.cpp +++ b/Source/WebKit/android/nav/WebView.cpp @@ -482,7 +482,8 @@ bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, WebCore::In m_glWebViewState->resetRings(); if (extra) { if (extra == &m_ring) { - m_glWebViewState->setRings(m_ring.rings(), m_ring.m_isPressed); + if (root == m_ring.m_frame) + m_glWebViewState->setRings(m_ring.rings(), m_ring.m_isPressed); } else { LayerAndroid mainPicture(m_navPictureUI); PictureSet* content = m_baseLayer->content(); |