Changeset 142037 in webkit
- Timestamp:
- Feb 6, 2013 2:46:42 PM (11 years ago)
- Location:
- trunk/Source/WebKit/blackberry
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/blackberry/Api/BackingStore.cpp
r141903 r142037 1 1 /* 2 * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.2 * Copyright (C) 2009, 2010, 2011, 2012, 2013 Research In Motion Limited. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 991 991 return Platform::IntRect(); 992 992 993 Platform::IntRect screenRect = m_client->mapFromTransformedContentsToTransformedViewport(dirtyRect); 993 Platform::ViewportAccessor* viewportAccessor = m_webPage->webkitThreadViewportAccessor(); 994 Platform::IntRect screenRect = viewportAccessor->pixelViewportFromContents(dirtyRect); 994 995 windowFrontBufferState()->clearBlittedRegion(screenRect); 995 996 996 paintDefaultBackground(dirtyRect, m_webPage->webkitThreadViewportAccessor(), true /*flush*/);997 998 const Platform::IntPoint origin = unclippedVisibleContentsRect().location();999 // We don't need a buffer since we're direct rendering to window.1000 renderContents(0, origin, dirtyRect); 997 paintDefaultBackground(dirtyRect, viewportAccessor, true /*flush*/); 998 999 if (!renderContents(buffer(), screenRect, viewportAccessor->scale(), viewportAccessor->documentFromPixelContents(dirtyRect.location()))) 1000 return Platform::IntRect(); 1001 1001 1002 windowBackBufferState()->addBlittedRegion(screenRect); 1002 1003 … … 1047 1048 if (tileIndexList.isEmpty()) 1048 1049 return tileIndexList; 1050 1051 Platform::ViewportAccessor* viewportAccessor = m_webPage->webkitThreadViewportAccessor(); 1049 1052 1050 1053 BackingStoreGeometry* geometry = frontState(); … … 1061 1064 1062 1065 for (size_t i = 0; i < tileIndexList.size(); ++i) { 1063 TileIndex index = tileIndexList[i];1064 Platform::IntRect dirtyRect(newGeometry->originOfTile(index), tileSize());1065 1066 1066 if (!SurfacePool::globalSurfacePool()->numberOfAvailableBackBuffers()) { 1067 1067 newGeometry->setTileMap(newTileMap); … … 1079 1079 } 1080 1080 1081 TileIndex index = tileIndexList[i]; 1082 Platform::IntPoint tileOrigin = newGeometry->originOfTile(index); 1083 Platform::IntRect dirtyRect(tileOrigin, tileSize()); 1084 1081 1085 // Paint default background if contents rect is empty. 1082 1086 if (!expandedContentsRect().isEmpty()) { … … 1106 1110 backBuffer->paintBackground(); 1107 1111 1108 Platform::IntPoint tileOrigin = geometry->originOfTile(index);1109 1112 backBuffer->setLastRenderScale(currentScale); 1110 1113 backBuffer->setLastRenderOrigin(tileOrigin); … … 1120 1123 SurfacePool::globalSurfacePool()->waitForBuffer(backBuffer); 1121 1124 1122 // FIXME: modify render to take a Vector<IntRect> parameter so we're not recreating 1123 // GraphicsContext on the stack each time. 1124 renderContents(nativeBuffer, tileOrigin, dirtyRect); 1125 const Platform::FloatPoint documentDirtyRectOrigin = viewportAccessor->toDocumentContents(dirtyRect.location(), currentScale); 1126 const Platform::IntRect dstRect(dirtyRect.location() - tileOrigin, dirtyRect.size()); 1127 1128 if (!renderContents(nativeBuffer, dstRect, currentScale, documentDirtyRectOrigin)) 1129 continue; 1125 1130 1126 1131 // Add the newly rendered region to the tile so it can keep track for blits. … … 1894 1899 } 1895 1900 1896 void BackingStorePrivate::renderContents(Platform::Graphics::Drawable* drawable, 1897 const Platform::IntRect& contentsRect, 1898 const Platform::IntSize& destinationSize) const 1899 { 1900 if (!drawable || contentsRect.isEmpty()) 1901 return; 1902 1903 requestLayoutIfNeeded(); 1904 1905 PlatformGraphicsContext* platformGraphicsContext = SurfacePool::globalSurfacePool()->createPlatformGraphicsContext(drawable); 1906 GraphicsContext graphicsContext(platformGraphicsContext); 1907 1908 graphicsContext.translate(-contentsRect.x(), -contentsRect.y()); 1909 1910 WebCore::IntRect transformedContentsRect(contentsRect.x(), contentsRect.y(), contentsRect.width(), contentsRect.height()); 1911 1912 float widthScale = static_cast<float>(destinationSize.width()) / contentsRect.width(); 1913 float heightScale = static_cast<float>(destinationSize.height()) / contentsRect.height(); 1914 1915 // Don't scale the transformed content rect when the content is smaller than the destination 1916 if (widthScale < 1.0 && heightScale < 1.0) { 1917 TransformationMatrix matrix; 1918 matrix.scaleNonUniform(1.0 / widthScale, 1.0 / heightScale); 1919 transformedContentsRect = matrix.mapRect(transformedContentsRect); 1920 // We extract from the contentsRect but draw a slightly larger region than 1921 // we were told to, in order to avoid pixels being rendered only partially. 1922 const int atLeastOneDevicePixel = static_cast<int>(ceilf(std::max(1.0 / widthScale, 1.0 / heightScale))); 1923 transformedContentsRect.inflate(atLeastOneDevicePixel); 1924 } 1925 1926 if (widthScale != 1.0 && heightScale != 1.0) 1927 graphicsContext.scale(FloatSize(widthScale, heightScale)); 1928 1929 graphicsContext.clip(transformedContentsRect); 1930 m_client->frame()->view()->paintContents(&graphicsContext, transformedContentsRect); 1931 1932 delete platformGraphicsContext; 1933 } 1934 1935 void BackingStorePrivate::renderContents(BlackBerry::Platform::Graphics::Buffer* tileBuffer, 1936 const Platform::IntPoint& surfaceOffset, 1937 const Platform::IntRect& contentsRect) const 1938 { 1939 // If tileBuffer == 0, we render directly to the window. 1940 if (!m_webPage->isVisible() && tileBuffer) 1941 return; 1942 1901 bool BackingStorePrivate::renderContents(BlackBerry::Platform::Graphics::Buffer* targetBuffer, const Platform::IntRect& dstRect, double scale, const Platform::FloatPoint& documentRenderOrigin) const 1902 { 1943 1903 #if DEBUG_BACKINGSTORE 1944 1904 Platform::logAlways(Platform::LogLevelCritical, 1945 "BackingStorePrivate::renderContents t ileBuffer=0x%p surfaceOffset=%s contentsRect=%s",1946 t ileBuffer, surfaceOffset.toString().c_str(), contentsRect.toString().c_str());1905 "BackingStorePrivate::renderContents targetBuffer=0x%p dstRect=%s scale=%f documentRenderOrigin=%s", 1906 targetBuffer, dstRect.toString().c_str(), scale, documentRenderOrigin.toString().c_str()); 1947 1907 #endif 1948 1908 1949 1909 // It is up to callers of this method to perform layout themselves! 1950 1910 ASSERT(!m_webPage->d->mainFrame()->view()->needsLayout()); 1951 1952 Platform::IntSize contentsSize = m_client->contentsSize(); 1911 ASSERT(targetBuffer); 1912 1913 Platform::ViewportAccessor* viewportAccessor = m_webPage->webkitThreadViewportAccessor(); 1914 WebCore::FloatRect renderedFloatRect(documentRenderOrigin, viewportAccessor->toDocumentContents(dstRect.size(), scale)); 1915 WebCore::IntRect contentsRect(WebCore::IntPoint::zero(), m_client->contentsSize()); 1953 1916 Color backgroundColor(m_webPage->settings()->backgroundColor()); 1954 1917 1955 BlackBerry::Platform::Graphics::Buffer* targetBuffer = tileBuffer 1956 ? tileBuffer 1957 : buffer(); 1958 1959 if (contentsSize.isEmpty() 1960 || !Platform::IntRect(Platform::IntPoint(0, 0), m_client->transformedContentsSize()).contains(contentsRect) 1961 || backgroundColor.hasAlpha()) { 1918 if (contentsRect.isEmpty() 1919 || backgroundColor.hasAlpha() 1920 || !WebCore::FloatRect(contentsRect).contains(renderedFloatRect)) { 1962 1921 // Clear the area if it's not fully covered by (opaque) contents. 1963 BlackBerry::Platform::IntRect clearRect = BlackBerry::Platform::IntRect( 1964 contentsRect.x() - surfaceOffset.x(), contentsRect.y() - surfaceOffset.y(), 1965 contentsRect.width(), contentsRect.height()); 1966 1967 BlackBerry::Platform::Graphics::clearBuffer(targetBuffer, clearRect, 1922 BlackBerry::Platform::Graphics::clearBuffer(targetBuffer, dstRect, 1968 1923 backgroundColor.red(), backgroundColor.green(), 1969 1924 backgroundColor.blue(), backgroundColor.alpha()); 1970 1925 } 1971 1926 1972 if (contentsSize.isEmpty()) 1973 return; 1974 1975 BlackBerry::Platform::Graphics::Drawable* bufferDrawable = 1976 BlackBerry::Platform::Graphics::lockBufferDrawable(targetBuffer); 1977 1978 PlatformGraphicsContext* bufferPlatformGraphicsContext = bufferDrawable 1979 ? SurfacePool::globalSurfacePool()->createPlatformGraphicsContext(bufferDrawable) 1980 : 0; 1981 PlatformGraphicsContext* targetPlatformGraphicsContext = bufferPlatformGraphicsContext 1982 ? bufferPlatformGraphicsContext 1983 : SurfacePool::globalSurfacePool()->lockTileRenderingSurface(); 1984 1985 ASSERT(targetPlatformGraphicsContext); 1927 if (contentsRect.isEmpty()) 1928 return true; 1929 1930 Platform::Graphics::Drawable* bufferDrawable = Platform::Graphics::lockBufferDrawable(targetBuffer); 1931 Platform::Graphics::Buffer* drawingBuffer = 0; 1932 1933 if (bufferDrawable) 1934 drawingBuffer = targetBuffer; 1935 else { 1936 BBLOG(Platform::LogLevelWarn, "Using temporary buffer to paint contents, look into avoiding this."); 1937 1938 drawingBuffer = Platform::Graphics::createBuffer(dstRect.size(), Platform::Graphics::BackedWhenNecessary); 1939 if (!drawingBuffer) { 1940 Platform::logAlways(Platform::LogLevelWarn, "Could not create temporary buffer, expect bad things to happen."); 1941 return false; 1942 } 1943 bufferDrawable = Platform::Graphics::lockBufferDrawable(drawingBuffer); 1944 if (!bufferDrawable) { 1945 Platform::logAlways(Platform::LogLevelWarn, "Could not lock temporary buffer drawable, expect bad things to happen."); 1946 Platform::Graphics::destroyBuffer(drawingBuffer); 1947 return false; 1948 } 1949 } 1950 1951 PlatformGraphicsContext* platformGraphicsContext = SurfacePool::globalSurfacePool()->createPlatformGraphicsContext(bufferDrawable); 1952 ASSERT(platformGraphicsContext); 1986 1953 1987 1954 { 1988 GraphicsContext graphicsContext(targetPlatformGraphicsContext); 1989 1990 // Believe it or not this is important since the WebKit Skia backend 1991 // doesn't store the original state unless you call save first :P 1955 GraphicsContext graphicsContext(platformGraphicsContext); 1956 1957 // Clip the output to the destination pixels. 1992 1958 graphicsContext.save(); 1959 graphicsContext.clip(dstRect); 1993 1960 1994 1961 // Translate context according to offset. 1995 graphicsContext.translate(-surfaceOffset.x(), -surfaceOffset.y()); 1962 if (targetBuffer == drawingBuffer) 1963 graphicsContext.translate(-dstRect.x(), -dstRect.y()); 1996 1964 1997 1965 // Add our transformation matrix as the global transform. 1998 AffineTransform affineTransform( 1999 m_webPage->d->transformationMatrix()->a(), 2000 m_webPage->d->transformationMatrix()->b(), 2001 m_webPage->d->transformationMatrix()->c(), 2002 m_webPage->d->transformationMatrix()->d(), 2003 m_webPage->d->transformationMatrix()->e(), 2004 m_webPage->d->transformationMatrix()->f()); 2005 graphicsContext.concatCTM(affineTransform); 2006 2007 // Now that the matrix is applied we need untranformed contents coordinates. 2008 Platform::IntRect untransformedContentsRect = m_webPage->d->mapFromTransformed(contentsRect); 2009 2010 // We extract from the contentsRect but draw a slightly larger region than 2011 // we were told to, in order to avoid pixels being rendered only partially. 2012 const int atLeastOneDevicePixel = 2013 static_cast<int>(ceilf(1.0 / m_webPage->d->transformationMatrix()->a())); 2014 untransformedContentsRect.inflate(atLeastOneDevicePixel, atLeastOneDevicePixel); 2015 2016 // Make sure the untransformed rectangle for the (slightly larger than 2017 // initially requested) repainted region is within the bounds of the page. 2018 untransformedContentsRect.intersect(Platform::IntRect(Platform::IntPoint(0, 0), contentsSize)); 2019 2020 // Some WebKit painting backends *cough* Skia *cough* don't set this automatically 2021 // to the dirtyRect so do so here explicitly. 2022 graphicsContext.clip(untransformedContentsRect); 1966 graphicsContext.scale(WebCore::FloatSize(scale, scale)); 1967 graphicsContext.translate(-documentRenderOrigin.x(), -documentRenderOrigin.y()); 1968 1969 // Make sure the rectangle for the rendered rectangle is within the 1970 // bounds of the page. 1971 WebCore::IntRect renderedRect = enclosingIntRect(renderedFloatRect); 1972 renderedRect.intersect(contentsRect); 2023 1973 2024 1974 // Take care of possible left overflow on RTL page. 2025 1975 if (int leftOverFlow = m_client->frame()->view()->minimumScrollPosition().x()) { 2026 untransformedContentsRect.move(leftOverFlow, 0);1976 renderedRect.move(leftOverFlow, 0); 2027 1977 graphicsContext.translate(-leftOverFlow, 0); 2028 1978 } 2029 1979 2030 1980 // Let WebCore render the page contents into the drawing surface. 2031 m_client->frame()->view()->paintContents(&graphicsContext, untransformedContentsRect);1981 m_client->frame()->view()->paintContents(&graphicsContext, renderedRect); 2032 1982 2033 1983 graphicsContext.restore(); 2034 1984 } 2035 1985 2036 // Grab the requested region from the drawing surface into the tile image. 2037 2038 delete bufferPlatformGraphicsContext; 2039 2040 if (bufferDrawable) 2041 releaseBufferDrawable(targetBuffer); 2042 else { 2043 const Platform::IntPoint dstPoint(contentsRect.x() - surfaceOffset.x(), 2044 contentsRect.y() - surfaceOffset.y()); 2045 const Platform::IntRect dstRect(dstPoint, contentsRect.size()); 2046 const Platform::IntRect srcRect = dstRect; 2047 1986 SurfacePool::globalSurfacePool()->destroyPlatformGraphicsContext(platformGraphicsContext); 1987 Platform::Graphics::releaseBufferDrawable(drawingBuffer); 1988 1989 if (targetBuffer != drawingBuffer) { 2048 1990 // If we couldn't directly draw to the buffer, copy from the drawing surface. 2049 SurfacePool::globalSurfacePool()->releaseTileRenderingSurface(targetPlatformGraphicsContext); 2050 BlackBerry::Platform::Graphics::blitToBuffer(targetBuffer, dstRect, BlackBerry::Platform::Graphics::drawingSurface(), srcRect); 2051 } 1991 const Platform::IntRect srcRect(Platform::IntPoint::zero(), dstRect.size()); 1992 1993 Platform::Graphics::blitToBuffer(targetBuffer, dstRect, drawingBuffer, srcRect); 1994 Platform::Graphics::destroyBuffer(drawingBuffer); 1995 } 1996 1997 return true; 2052 1998 } 2053 1999 … … 2524 2470 } 2525 2471 2526 void BackingStore::drawContents(Platform::Graphics::Drawable* drawable, const Platform::IntRect& contentsRect, const Platform::IntSize& destinationSize) 2527 { 2528 d->renderContents(drawable, contentsRect, destinationSize); 2529 } 2530 2531 } 2532 } 2472 bool BackingStore::drawContents(Platform::Graphics::Buffer* buffer, const Platform::IntRect& dstRect, double scale, const Platform::FloatPoint& documentScrollPosition) 2473 { 2474 if (!buffer || dstRect.isEmpty()) 2475 return false; 2476 2477 d->requestLayoutIfNeeded(); 2478 2479 return d->renderContents(buffer, dstRect, scale, documentScrollPosition); 2480 } 2481 2482 } 2483 } -
trunk/Source/WebKit/blackberry/Api/BackingStore.h
r140191 r142037 21 21 22 22 #include "BlackBerryGlobal.h" 23 #include <BlackBerryPlatformGraphics.h>24 23 #include <BlackBerryPlatformMisc.h> 25 24 … … 35 34 namespace Platform { 36 35 class IntRect; 36 class FloatPoint; 37 38 namespace Graphics { 39 class Buffer; 40 } 37 41 } 38 42 } … … 75 79 void releaseOwnedBackingStoreMemory(); 76 80 77 void drawContents(Platform::Graphics::Drawable*, const Platform::IntRect& /*contentsRect*/, const Platform::IntSize& /*destinationSize*/);81 bool drawContents(BlackBerry::Platform::Graphics::Buffer*, const BlackBerry::Platform::IntRect& dstRect, double scale, const BlackBerry::Platform::FloatPoint& documentScrollPosition); 78 82 79 83 private: -
trunk/Source/WebKit/blackberry/Api/BackingStore_p.h
r138539 r142037 34 34 namespace WebCore { 35 35 class IntRect; 36 class FloatPoint; 36 37 class FloatRect; 37 38 class LayerRenderer; … … 306 307 307 308 // This takes transformed contents coordinates. 308 void renderContents(BlackBerry::Platform::Graphics::Buffer*, const Platform::IntPoint& surfaceOffset, const Platform::IntRect& contentsRect) const; 309 void renderContents(Platform::Graphics::Drawable* /*drawable*/, const Platform::IntRect& /*contentsRect*/, const Platform::IntSize& /*destinationSize*/) const; 309 bool renderContents(BlackBerry::Platform::Graphics::Buffer*, const BlackBerry::Platform::IntRect& dstRect, double scale, const BlackBerry::Platform::FloatPoint& documentScrollPosition) const; 310 310 311 311 void blitToWindow(const Platform::IntRect& dstRect, const BlackBerry::Platform::Graphics::Buffer* srcBuffer, const Platform::IntRect& srcRect, BlackBerry::Platform::Graphics::BlendMode, unsigned char globalAlpha); -
trunk/Source/WebKit/blackberry/ChangeLog
r142019 r142037 1 2013-02-06 Jakob Petsovits <jpetsovits@rim.com> 2 3 [BlackBerry] Refactor renderContents() for cleaner code. 4 https://bugs.webkit.org/show_bug.cgi?id=109059 5 RIM PR 280374 6 7 Reviewed by Rob Buis. 8 Internally reviewed by Arvid Nilsson. 9 10 The fact that we've got two renderContents() implementations 11 in BackingStore.cpp, one of which was tailored to just 12 being called from drawContents(), is a major annoyance. 13 14 With this patch, the regular renderContents() is modified 15 in a way so that drawContents() can make use of it as well. 16 This includes an API change for both functions which makes 17 it more flexible and enables further cleanups and improvements 18 to accuracy. The second, unloved renderContents() is removed. 19 20 The user-visible changes are improved (float) accuracy for 21 render offsets, clipping to exactly the dstRect that has 22 been specified, and the changed public drawContents() API. 23 24 * Api/BackingStore.cpp: 25 (BlackBerry::WebKit::BackingStorePrivate::renderDirectToWindow): 26 (BlackBerry::WebKit::BackingStorePrivate::render): 27 (BlackBerry::WebKit::BackingStorePrivate::renderContents): 28 (BlackBerry::WebKit::BackingStore::drawContents): 29 * Api/BackingStore.h: 30 (Platform): 31 (Graphics): 32 * Api/BackingStore_p.h: 33 (WebCore): 34 (BackingStorePrivate): 35 * WebKitSupport/SurfacePool.cpp: 36 (BlackBerry::WebKit::SurfacePool::SurfacePool): 37 (BlackBerry::WebKit::SurfacePool::initialize): 38 (BlackBerry::WebKit::SurfacePool::destroyPlatformGraphicsContext): 39 * WebKitSupport/SurfacePool.h: 40 (SurfacePool): 41 1 42 2013-02-06 Nima Ghanavatian <nghanavatian@rim.com> 2 43 -
trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.cpp
r138028 r142037 57 57 SurfacePool::SurfacePool() 58 58 : m_numberOfFrontBuffers(0) 59 , m_tileRenderingSurface(0)60 59 , m_initialized(false) 61 60 , m_buffersSuspended(false) … … 86 85 } 87 86 } 88 89 m_tileRenderingSurface = Platform::Graphics::drawingSurface();90 87 91 88 if (!m_numberOfFrontBuffers) … … 129 126 } 130 127 131 PlatformGraphicsContext* SurfacePool::lockTileRenderingSurface() const 132 { 133 if (!m_tileRenderingSurface) 134 return 0; 135 136 return createPlatformGraphicsContext(Platform::Graphics::lockBufferDrawable(m_tileRenderingSurface)); 137 } 138 139 void SurfacePool::releaseTileRenderingSurface(PlatformGraphicsContext* context) const 140 { 141 if (!m_tileRenderingSurface) 142 return; 143 144 delete context; 145 Platform::Graphics::releaseBufferDrawable(m_tileRenderingSurface); 128 void SurfacePool::destroyPlatformGraphicsContext(PlatformGraphicsContext* platformGraphicsContext) const 129 { 130 delete platformGraphicsContext; 146 131 } 147 132 -
trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.h
r138028 r142037 44 44 45 45 PlatformGraphicsContext* createPlatformGraphicsContext(BlackBerry::Platform::Graphics::Drawable*) const; 46 PlatformGraphicsContext* lockTileRenderingSurface() const; 47 void releaseTileRenderingSurface(PlatformGraphicsContext*) const; 46 void destroyPlatformGraphicsContext(PlatformGraphicsContext*) const; 48 47 49 48 // The surface pool will allocate as many back buffers as specified by … … 79 78 TileBufferList m_availableBackBufferPool; 80 79 unsigned m_numberOfFrontBuffers; 81 BlackBerry::Platform::Graphics::Buffer* m_tileRenderingSurface;82 80 bool m_initialized; // SurfacePool has been set up, with or without buffers. 83 81 bool m_buffersSuspended; // Buffer objects exist, but pixel memory has been freed.
Note: See TracChangeset
for help on using the changeset viewer.