diff options
author | Derek Sollenberger <djsollen@google.com> | 2011-06-30 12:54:21 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2011-06-30 14:17:33 -0400 |
commit | 8dfdf8aa25b250ed3b8c0a443cf1cbaf9bd12c5b (patch) | |
tree | e6289cb6f87508fb2be476e8a9541531ffb388b2 | |
parent | 2facab8e2bfadc4b9028b267b9596981bfb6cc8a (diff) | |
download | external_webkit-8dfdf8aa25b250ed3b8c0a443cf1cbaf9bd12c5b.zip external_webkit-8dfdf8aa25b250ed3b8c0a443cf1cbaf9bd12c5b.tar.gz external_webkit-8dfdf8aa25b250ed3b8c0a443cf1cbaf9bd12c5b.tar.bz2 |
Add initial support for Ganesh renderer.
The GaneshRenderer can now be swapped in for the RasterRenderer in
BaseTile. A following CL will enable this swap at runtime.
Change-Id: Id42040fce2895ab00cccb8f11dfd0489df861655
-rw-r--r-- | Android.mk | 4 | ||||
-rw-r--r-- | Source/WebCore/Android.mk | 2 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/BaseRenderer.cpp | 60 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/BaseRenderer.h | 9 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/BaseTile.cpp | 13 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/BaseTile.h | 4 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/GaneshContext.cpp | 128 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/GaneshContext.h | 60 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/GaneshRenderer.cpp | 164 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/GaneshRenderer.h | 59 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/RasterRenderer.cpp | 34 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/RasterRenderer.h | 8 |
12 files changed, 479 insertions, 66 deletions
@@ -151,8 +151,10 @@ LOCAL_C_INCLUDES := \ external/libxslt \ external/hyphenation \ external/skia/emoji \ + external/skia/gpu/include \ external/skia/include/core \ external/skia/include/effects \ + external/skia/include/gpu \ external/skia/include/images \ external/skia/include/ports \ external/skia/include/utils \ @@ -402,7 +404,7 @@ LOCAL_CFLAGS += -DSUPPORT_COMPLEX_SCRIPTS=1 endif # Build the list of static libraries -LOCAL_STATIC_LIBRARIES := libxml2 libxslt libhyphenation +LOCAL_STATIC_LIBRARIES := libxml2 libxslt libhyphenation libskiagpu ifeq ($(JAVASCRIPT_ENGINE),v8) LOCAL_STATIC_LIBRARIES += libv8 endif diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk index 9ea7007..65fdc7a 100644 --- a/Source/WebCore/Android.mk +++ b/Source/WebCore/Android.mk @@ -644,6 +644,8 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/graphics/android/FontCustomPlatformData.cpp \ platform/graphics/android/FontDataAndroid.cpp \ platform/graphics/android/FontPlatformDataAndroid.cpp \ + platform/graphics/android/GaneshContext.cpp \ + platform/graphics/android/GaneshRenderer.cpp \ platform/graphics/android/GLUtils.cpp \ platform/graphics/android/GLWebViewState.cpp \ platform/graphics/android/GlyphMapAndroid.cpp \ diff --git a/Source/WebCore/platform/graphics/android/BaseRenderer.cpp b/Source/WebCore/platform/graphics/android/BaseRenderer.cpp index 13dfce6..f9da6f5 100644 --- a/Source/WebCore/platform/graphics/android/BaseRenderer.cpp +++ b/Source/WebCore/platform/graphics/android/BaseRenderer.cpp @@ -67,48 +67,68 @@ void BaseRenderer::drawTileInfo(SkCanvas* canvas, 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 tagCount = 0; + const String* tags = getPerformanceTags(tagCount); + + float total = 0; + for (int i = 0; i < tagCount; 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 = (tagCount * 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); } int BaseRenderer::renderTiledContent(const TileRenderInfo& renderInfo) { - bool visualIndicator = TilesManager::instance()->getShowVisualIndicator(); + const bool visualIndicator = TilesManager::instance()->getShowVisualIndicator(); + const SkSize& tileSize = renderInfo.tileSize; -#ifdef DEBUG - visualIndicator = true; - measurePerf = true; -#endif - - SkIRect* invalRect = renderInfo.invalRect; - - SkDevice* device = setupDevice(renderInfo); - SkCanvas canvas(device); - device->unref(); + SkCanvas canvas; + setupCanvas(renderInfo, &canvas); if (visualIndicator) canvas.save(); + setupPartialInval(renderInfo, &canvas); + canvas.translate(-renderInfo.x * tileSize.width(), -renderInfo.y * tileSize.height()); 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); + const int color = 20 + (pictureCount % 100); + + // only color the invalidated area + SkPaint invalPaint; + invalPaint.setARGB(color, 0, 255, 0); + canvas.drawIRect(*renderInfo.invalRect, invalPaint); + // paint the tile boundaries SkPaint paint; paint.setARGB(128, 255, 0, 0); paint.setStrokeWidth(3); - canvas.drawLine(0, 0, invalRect->width(), invalRect->height(), paint); + canvas.drawLine(0, 0, tileSize.width(), tileSize.height(), paint); paint.setARGB(128, 0, 255, 0); - canvas.drawLine(0, invalRect->height(), invalRect->width(), 0, paint); + canvas.drawLine(0, tileSize.height(), tileSize.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); + canvas.drawLine(0, 0, tileSize.width(), 0, paint); + canvas.drawLine(tileSize.width(), 0, tileSize.width(), tileSize.height(), paint); - drawTileInfo(&canvas, renderInfo, pictureCount); + if (renderInfo.measurePerf) + drawTileInfo(&canvas, renderInfo, pictureCount); } renderingComplete(renderInfo, &canvas); diff --git a/Source/WebCore/platform/graphics/android/BaseRenderer.h b/Source/WebCore/platform/graphics/android/BaseRenderer.h index b48145f..046634a 100644 --- a/Source/WebCore/platform/graphics/android/BaseRenderer.h +++ b/Source/WebCore/platform/graphics/android/BaseRenderer.h @@ -50,10 +50,6 @@ struct TileRenderInfo { // 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; @@ -82,13 +78,14 @@ public: protected: - virtual SkDevice* setupDevice(const TileRenderInfo& renderInfo) = 0; + virtual void setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas) = 0; + virtual void setupPartialInval(const TileRenderInfo& renderInfo, SkCanvas* canvas) {} virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) = 0; void drawTileInfo(SkCanvas* canvas, const TileRenderInfo& renderInfo, int pictureCount); - virtual void drawPerformanceInfo(SkCanvas* canvas) {} + virtual const String* getPerformanceTags(int& tagCount) = 0; // Performance tracking PerformanceMonitor m_perfMon; diff --git a/Source/WebCore/platform/graphics/android/BaseTile.cpp b/Source/WebCore/platform/graphics/android/BaseTile.cpp index 87bdba4..2fa2427 100644 --- a/Source/WebCore/platform/graphics/android/BaseTile.cpp +++ b/Source/WebCore/platform/graphics/android/BaseTile.cpp @@ -28,7 +28,7 @@ #if USE(ACCELERATED_COMPOSITING) -#include "BaseRenderer.h" +#include "RasterRenderer.h" #include "GLUtils.h" #include "TextureInfo.h" #include "TilesManager.h" @@ -71,6 +71,7 @@ BaseTile::BaseTile() ClassTracker::instance()->increment("BaseTile"); #endif m_currentDirtyArea = &m_dirtyAreaA; + m_renderer = new RasterRenderer(); } BaseTile::~BaseTile() @@ -79,6 +80,8 @@ BaseTile::~BaseTile() if (m_texture) m_texture->release(this); + delete m_renderer; + #ifdef DEBUG_COUNT ClassTracker::instance()->decrement("BaseTile"); #endif @@ -347,11 +350,9 @@ void BaseTile::paintBitmap() finalRealRect.fBottom = finalRealRect.fTop + iHeight; renderInfo.invalRect = &finalRealRect; - renderInfo.invalX = realTileRect.fLeft / scale; - renderInfo.invalY = realTileRect.fTop / scale; renderInfo.measurePerf = false; - pictureCount = m_renderer.renderTiledContent(renderInfo); + pictureCount = m_renderer->renderTiledContent(renderInfo); cliperator.next(); } @@ -362,11 +363,9 @@ void BaseTile::paintBitmap() 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); + 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/BaseTile.h b/Source/WebCore/platform/graphics/android/BaseTile.h index cddaa60..d336ae2 100644 --- a/Source/WebCore/platform/graphics/android/BaseTile.h +++ b/Source/WebCore/platform/graphics/android/BaseTile.h @@ -28,7 +28,7 @@ #if USE(ACCELERATED_COMPOSITING) -#include "RasterRenderer.h" +#include "BaseRenderer.h" #include "SkRect.h" #include "SkRegion.h" #include "TextureOwner.h" @@ -135,7 +135,7 @@ private: // across all threads and cores. android::Mutex m_atomicSync; - RasterRenderer m_renderer; + BaseRenderer* m_renderer; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/GaneshContext.cpp b/Source/WebCore/platform/graphics/android/GaneshContext.cpp new file mode 100644 index 0000000..b316e5a --- /dev/null +++ b/Source/WebCore/platform/graphics/android/GaneshContext.cpp @@ -0,0 +1,128 @@ +/* + * 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 "GaneshContext.h" +#include "GLUtils.h" + +#if USE(ACCELERATED_COMPOSITING) + +#ifdef DEBUG + +#include <cutils/log.h> +#include <wtf/CurrentTime.h> + +#undef XLOG +#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GaneshContext", __VA_ARGS__) + +#else + +#undef XLOG +#define XLOG(...) + +#endif // DEBUG + +namespace WebCore { + +GaneshContext::GaneshContext() + : m_grContext(0) + , m_baseTileDevice(0) + , m_baseTileFbo(0) + , m_baseTileStencil(0) +{ +} + +GaneshContext* GaneshContext::gInstance = 0; + +GaneshContext* GaneshContext::instance() +{ + if (!gInstance) + gInstance = new GaneshContext(); + return gInstance; +} + +GrContext* GaneshContext::getGrContext() +{ + if (!m_grContext) { + m_grContext = GrContext::Create(kOpenGL_Shaders_GrEngine, NULL); + } + return m_grContext; +} + +SkDevice* GaneshContext::getDeviceForBaseTile(GLuint textureId) +{ + if (!m_baseTileFbo) { + glGenFramebuffers(1, &m_baseTileFbo); + XLOG("generated FBO"); + } + + if (!m_baseTileStencil) { + glGenRenderbuffers(1, &m_baseTileStencil); + glBindRenderbuffer(GL_RENDERBUFFER, m_baseTileStencil); + glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, + TilesManager::tileWidth(), + TilesManager::tileHeight()); + glClearStencil(0); + glClear(GL_STENCIL_BUFFER_BIT); + XLOG("generated stencil"); + } + + glBindFramebuffer(GL_FRAMEBUFFER, m_baseTileFbo); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_baseTileStencil); + + if (!m_baseTileDevice) { + + GrPlatformSurfaceDesc surfaceDesc; + surfaceDesc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType; + surfaceDesc.fRenderTargetFlags = kNone_GrPlatformRenderTargetFlagBit; + surfaceDesc.fWidth = TilesManager::tileWidth(); + surfaceDesc.fHeight = TilesManager::tileWidth(); + surfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; + surfaceDesc.fStencilBits = 8; + surfaceDesc.fPlatformRenderTarget = m_baseTileFbo; + + GrContext* grContext = getGrContext(); + GrRenderTarget* renderTarget = (GrRenderTarget*) grContext->createPlatformSurface(surfaceDesc); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + TilesManager::tileWidth(), TilesManager::tileWidth()); + + m_baseTileDevice = new SkGpuDevice(grContext, bitmap, renderTarget); + renderTarget->unref(); + XLOG("generated device %p", m_baseTileDevice); + } + + GLUtils::checkGlError("getDeviceForBaseTile"); + return m_baseTileDevice; +} + + + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/GaneshContext.h b/Source/WebCore/platform/graphics/android/GaneshContext.h new file mode 100644 index 0000000..9d90b96 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/GaneshContext.h @@ -0,0 +1,60 @@ +/* + * 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 GaneshContext_h +#define GaneshContext_h + +#if USE(ACCELERATED_COMPOSITING) + +#include "GrContext.h" +#include "SkGpuDevice.h" +#include "TilesManager.h" + +namespace WebCore { + +class GaneshContext { +public: + static GaneshContext* instance(); + + GrContext* getGrContext(); + + SkDevice* getDeviceForBaseTile(GLuint textureId); + +private: + + GaneshContext(); + + GrContext* m_grContext; + SkGpuDevice* m_baseTileDevice; + GLuint m_baseTileFbo; + GLuint m_baseTileStencil; + + static GaneshContext* gInstance; +}; + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) +#endif // GaneshContext_h diff --git a/Source/WebCore/platform/graphics/android/GaneshRenderer.cpp b/Source/WebCore/platform/graphics/android/GaneshRenderer.cpp new file mode 100644 index 0000000..fcb0675 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/GaneshRenderer.cpp @@ -0,0 +1,164 @@ +/* + * 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 "GaneshRenderer.h" + +#if USE(ACCELERATED_COMPOSITING) + +#include "GaneshContext.h" +#include "SkCanvas.h" +#include "SkGpuDevice.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, "GaneshRenderer", __VA_ARGS__) + +#else + +#undef XLOG +#define XLOG(...) + +#endif // DEBUG + +namespace WebCore { + +static const String TAG_CREATE_FBO = "create_fbo"; +static const String TAG_DRAW_PICTURE = "draw_picture"; +static const String TAG_UPDATE_TEXTURE = "update_texture"; +#define TAG_COUNT 3 +static const String TAGS[] = { + TAG_CREATE_FBO, + TAG_DRAW_PICTURE, + TAG_UPDATE_TEXTURE, +}; + +GaneshRenderer::GaneshRenderer() : BaseRenderer(BaseRenderer::Raster) +{ +#ifdef DEBUG_COUNT + ClassTracker::instance()->increment("GaneshRenderer"); +#endif +} + +GaneshRenderer::~GaneshRenderer() +{ +#ifdef DEBUG_COUNT + ClassTracker::instance()->decrement("GaneshRenderer"); +#endif +} + +void GaneshRenderer::setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas) +{ + if (renderInfo.measurePerf) + m_perfMon.start(TAG_CREATE_FBO); + + const float tileWidth = renderInfo.tileSize.width(); + const float tileHeight = renderInfo.tileSize.height(); + + glBindTexture(GL_TEXTURE_2D, renderInfo.textureInfo->m_textureId); + + // setup the texture if needed + if (renderInfo.textureInfo->m_width != tileWidth + || renderInfo.textureInfo->m_height != tileHeight) { + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tileWidth, tileHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + renderInfo.textureInfo->m_width = tileWidth; + renderInfo.textureInfo->m_height = tileHeight; + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + + GaneshContext* ganesh = GaneshContext::instance(); + + // TODO only need to reset if others are sharing our context + ganesh->getGrContext()->resetContext(); + + SkDevice* device = NULL; + if (tileWidth == TilesManager::tileWidth() && tileHeight == TilesManager::tileHeight()) { + device = ganesh->getDeviceForBaseTile(renderInfo.textureInfo->m_textureId); + } else { + // TODO support arbitrary sizes for layers + XLOG("ERROR: expected (%d,%d) actual (%d,%d)", + TilesManager::tileWidth(), TilesManager::tileHeight(), + tileWidth, tileHeight); + } + + if (renderInfo.measurePerf) { + m_perfMon.stop(TAG_CREATE_FBO); + m_perfMon.start(TAG_DRAW_PICTURE); + } + + // set the GPU device to the canvas + canvas->setDevice(device); + + // invert canvas contents + canvas->scale(SK_Scalar1, -SK_Scalar1); + canvas->translate(0, -SkIntToScalar(renderInfo.tileSize.height())); +} + +void GaneshRenderer::setupPartialInval(const TileRenderInfo& renderInfo, SkCanvas* canvas) +{ + // set the clip to our invalRect + SkRect clipRect = SkRect::MakeLTRB(renderInfo.invalRect->fLeft, + renderInfo.invalRect->fTop, + renderInfo.invalRect->fRight, + renderInfo.invalRect->fBottom); + canvas->clipRect(clipRect); +} + +void GaneshRenderer::renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) +{ + if (renderInfo.measurePerf) { + m_perfMon.stop(TAG_DRAW_PICTURE); + m_perfMon.start(TAG_UPDATE_TEXTURE); + } + + GaneshContext::instance()->getGrContext()->flush(); + + //TODO if texture is surfaceTexture then... + + if (renderInfo.measurePerf) + m_perfMon.stop(TAG_UPDATE_TEXTURE); +} + +const String* GaneshRenderer::getPerformanceTags(int& tagCount) +{ + tagCount = TAG_COUNT; + return TAGS; +} + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/GaneshRenderer.h b/Source/WebCore/platform/graphics/android/GaneshRenderer.h new file mode 100644 index 0000000..0e1d41e --- /dev/null +++ b/Source/WebCore/platform/graphics/android/GaneshRenderer.h @@ -0,0 +1,59 @@ +/* + * 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 GaneshRenderer_h +#define GaneshRenderer_h + +#if USE(ACCELERATED_COMPOSITING) + +#include "BaseRenderer.h" +#include "SkRect.h" + +class SkCanvas; +class SkDevice; + +namespace WebCore { + +/** + * + */ +class GaneshRenderer : public BaseRenderer { +public: + GaneshRenderer(); + ~GaneshRenderer(); + +protected: + + virtual void setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas); + virtual void setupPartialInval(const TileRenderInfo& renderInfo, SkCanvas* canvas); + virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas); + virtual const String* getPerformanceTags(int& tagCount); + +}; + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) +#endif // GaneshRenderer_h diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.cpp b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp index 025dbae..dc35cdd 100644 --- a/Source/WebCore/platform/graphics/android/RasterRenderer.cpp +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp @@ -34,7 +34,6 @@ #include "SkBitmapRef.h" #include "SkCanvas.h" #include "SkDevice.h" -#include "SkPicture.h" #include "TilesManager.h" #include <wtf/text/CString.h> @@ -59,7 +58,7 @@ 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 +#define TAG_COUNT 3 static const String TAGS[] = { TAG_CREATE_BITMAP, TAG_DRAW_PICTURE, @@ -80,7 +79,7 @@ RasterRenderer::~RasterRenderer() #endif } -SkDevice* RasterRenderer::setupDevice(const TileRenderInfo& renderInfo) +void RasterRenderer::setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas) { if (renderInfo.measurePerf) m_perfMon.start(TAG_CREATE_BITMAP); @@ -98,7 +97,11 @@ SkDevice* RasterRenderer::setupDevice(const TileRenderInfo& renderInfo) m_perfMon.start(TAG_DRAW_PICTURE); } - return device; + canvas->setDevice(device); + device->unref(); + + // ensure the canvas origin is translated to the coordinates of our inval rect + canvas->translate(-renderInfo.invalRect->fLeft, -renderInfo.invalRect->fTop); } void RasterRenderer::renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) @@ -117,27 +120,10 @@ void RasterRenderer::renderingComplete(const TileRenderInfo& renderInfo, SkCanva m_perfMon.stop(TAG_UPDATE_TEXTURE); } -void RasterRenderer::drawPerformanceInfo(SkCanvas* canvas) +const String* RasterRenderer::getPerformanceTags(int& tagCount) { - 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); + tagCount = TAG_COUNT; + return TAGS; } } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.h b/Source/WebCore/platform/graphics/android/RasterRenderer.h index 218d1b7..4308452 100644 --- a/Source/WebCore/platform/graphics/android/RasterRenderer.h +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.h @@ -36,10 +36,6 @@ class SkDevice; namespace WebCore { -class BaseTileTexture; -class TextureInfo; -class TiledPage; - /** * */ @@ -50,9 +46,9 @@ public: protected: - virtual SkDevice* setupDevice(const TileRenderInfo& renderInfo); + virtual void setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas); virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas); - virtual void drawPerformanceInfo(SkCanvas* canvas); + virtual const String* getPerformanceTags(int& tagCount); }; |