Changeset 67123 in webkit
- Timestamp:
- Sep 9, 2010 4:15:29 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r67122 r67123 1 2010-09-09 Vincent Scheib <scheib@chromium.org> 2 3 Reviewed by James Robinson. 4 5 [Chromium] Minimize uploads in canvas 2d mixed mode rendering 6 https://bugs.webkit.org/show_bug.cgi?id=45476 7 8 No new tests - change is for performance, logic fixes only apparent when running hardware acceleration. 9 10 - Enumeration values fixed, "CavasWillDraw" -> "CanvasDidDraw". 11 - markDirtyRect() plumbed through GraphicsContext to PlatformContextSkia. 12 - Texture::updateSubRect() added to allow uploading only a dirty rect. 13 - Logic fix in ImageBuffer::draw(), caused canvas to canvas copies to be incorrect. 14 15 * html/canvas/CanvasRenderingContext2D.cpp: 16 (WebCore::CanvasRenderingContext2D::setAllAttributesToDefault): 17 (WebCore::CanvasRenderingContext2D::strokeRect): 18 (WebCore::CanvasRenderingContext2D::drawImage): 19 (WebCore::CanvasRenderingContext2D::didDraw): 20 - Logic fix for drawingContext()->markDirtyRect() call. 21 (WebCore::CanvasRenderingContext2D::putImageData): 22 (WebCore::CanvasRenderingContext2D::drawTextInternal): 23 - Logic fix for calls to "didDraw()", use peer method first. 24 * html/canvas/CanvasRenderingContext2D.h: 25 * platform/graphics/GraphicsContext.cpp: 26 (WebCore::GraphicsContext::drawImageBuffer): 27 (WebCore::GraphicsContext::markDirtyRect): 28 * platform/graphics/GraphicsContext.h: 29 * platform/graphics/gpu/Texture.cpp: 30 (WebCore::Texture::create): 31 (WebCore::Texture::load): 32 (WebCore::Texture::updateSubRect): 33 * platform/graphics/gpu/Texture.h: 34 * platform/graphics/gpu/TilingData.h: 35 (WebCore::TilingData::borderTexels): 36 * platform/graphics/skia/GraphicsContextSkia.cpp: 37 (WebCore::GraphicsContext::clipConvexPolygon): 38 (WebCore::GraphicsContext::markDirtyRect): 39 * platform/graphics/skia/ImageBufferSkia.cpp: 40 (WebCore::ImageBuffer::draw): 41 * platform/graphics/skia/PlatformContextSkia.cpp: 42 (WebCore::PlatformContextSkia::State::cloneInheritedProperties): 43 (WebCore::PlatformContextSkia::drawRect): 44 (WebCore::PlatformContextSkia::setFillColor): 45 (WebCore::PlatformContextSkia::setStrokeColor): 46 (WebCore::PlatformContextSkia::markDirtyRect): 47 (WebCore::PlatformContextSkia::uploadSoftwareToHardware): 48 * platform/graphics/skia/PlatformContextSkia.h: 49 1 50 2010-09-08 Darin Adler <darin@apple.com> 2 51 -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r66988 r67123 26 26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 */ 30 30 … … 220 220 } 221 221 222 void CanvasRenderingContext2D::setAllAttributesToDefault() 222 void CanvasRenderingContext2D::setAllAttributesToDefault() 223 223 { 224 224 state().m_globalAlpha = 1; … … 944 944 if (!validateRectForCanvas(x, y, width, height)) 945 945 return; 946 946 947 947 if (!(lineWidth >= 0)) 948 948 return; … … 1277 1277 if (!state().m_invertibleCTM) 1278 1278 return; 1279 1279 1280 1280 FloatRect sourceRect = c->roundToDevicePixels(srcRect); 1281 1281 FloatRect destRect = c->roundToDevicePixels(dstRect); … … 1511 1511 1512 1512 FloatRect dirtyRect = r; 1513 if (options & Canvas WillDrawApplyTransform) {1513 if (options & CanvasDidDrawApplyTransform) { 1514 1514 AffineTransform ctm = state().m_transform; 1515 1515 dirtyRect = ctm.mapRect(r); 1516 1516 } 1517 1517 1518 if (options & Canvas WillDrawApplyShadow && alphaChannel(state().m_shadowColor)) {1518 if (options & CanvasDidDrawApplyShadow && alphaChannel(state().m_shadowColor)) { 1519 1519 // The shadow gets applied after transformation 1520 1520 FloatRect shadowRect(dirtyRect); … … 1524 1524 } 1525 1525 1526 if (options & Canvas WillDrawApplyClip) {1526 if (options & CanvasDidDrawApplyClip) { 1527 1527 // FIXME: apply the current clip to the rectangle. Unfortunately we can't get the clip 1528 1528 // back out of the GraphicsContext, so to take clip into account for incremental painting, … … 1530 1530 } 1531 1531 1532 #if ENABLE(ACCELERATED_2D_CANVAS) 1533 if (isAccelerated()) 1534 drawingContext()->markDirtyRect(enclosingIntRect(dirtyRect)); 1535 #endif 1532 1536 #if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING) 1533 1537 // If we are drawing to hardware and we have a composited layer, just call rendererContentChanged(). … … 1659 1663 1660 1664 buffer->putUnmultipliedImageData(data, sourceRect, destPoint); 1661 didDraw(sourceRect, 0); // ignore transform, shadow and clip1665 didDraw(sourceRect, CanvasDidDrawApplyNone); // ignore transform, shadow and clip 1662 1666 } 1663 1667 … … 1879 1883 1880 1884 if (fill) 1881 canvas()->didDraw(textRect);1885 didDraw(textRect); 1882 1886 else { 1883 1887 // When stroking text, pointy miters can extend outside of textRect, so we 1884 1888 // punt and dirty the whole canvas. 1885 canvas()->didDraw(FloatRect(0, 0, canvas()->width(), canvas()->height()));1889 didDraw(FloatRect(0, 0, canvas()->width(), canvas()->height())); 1886 1890 } 1887 1891 -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.h
r66746 r67123 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 … … 265 265 void applyShadow(); 266 266 267 enum CanvasWillDrawOption { 268 CanvasWillDrawApplyTransform = 1, 269 CanvasWillDrawApplyShadow = 1 << 1, 270 CanvasWillDrawApplyClip = 1 << 2, 271 CanvasWillDrawApplyAll = 0xffffffff 267 enum CanvasDidDrawOption { 268 CanvasDidDrawApplyNone = 0, 269 CanvasDidDrawApplyTransform = 1, 270 CanvasDidDrawApplyShadow = 1 << 1, 271 CanvasDidDrawApplyClip = 1 << 2, 272 CanvasDidDrawApplyAll = 0xffffffff 272 273 }; 273 274 274 void didDraw(const FloatRect&, unsigned options = Canvas WillDrawApplyAll);275 void didDraw(const FloatRect&, unsigned options = CanvasDidDrawApplyAll); 275 276 276 277 GraphicsContext* drawingContext() const; -
trunk/WebCore/platform/graphics/GraphicsContext.cpp
r66746 r67123 468 468 if (paintingDisabled() || !image) 469 469 return; 470 470 471 471 float tsw = src.width(); 472 472 float tsh = src.height(); … … 490 490 491 491 image->draw(this, styleColorSpace, dest, src, op, useLowQualityScale); 492 492 493 493 if (useLowQualityScale) 494 494 restore(); … … 578 578 579 579 void GraphicsContext::syncSoftwareCanvas() 580 { 581 } 582 583 void GraphicsContext::markDirtyRect(const IntRect&) 580 584 { 581 585 } -
trunk/WebCore/platform/graphics/GraphicsContext.h
r66746 r67123 22 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 25 */ 26 26 … … 425 425 void setSharedGraphicsContext3D(SharedGraphicsContext3D*, DrawingBuffer*, const IntSize&); 426 426 void syncSoftwareCanvas(); 427 void markDirtyRect(const IntRect&); // Hints that a portion of the backing store is dirty. 427 428 428 429 private: -
trunk/WebCore/platform/graphics/gpu/Texture.cpp
r66746 r67123 33 33 #include "Texture.h" 34 34 35 #include "FloatRect.h" 35 36 #include "GraphicsContext3D.h" 36 37 #include "IntRect.h" 37 38 39 #include <algorithm> 38 40 #include <wtf/OwnArrayPtr.h> 41 42 using namespace std; 39 43 40 44 namespace WebCore { … … 83 87 int maxTextureSize = 0; 84 88 context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize); 85 86 89 TilingData tiling(maxTextureSize, width, height, true); 87 90 int numTiles = tiling.numTiles(); … … 138 141 void Texture::load(void* pixels) 139 142 { 143 updateSubRect(pixels, IntRect(0, 0, m_tiles.totalSizeX(), m_tiles.totalSizeY())); 144 } 145 146 void Texture::updateSubRect(void* pixels, const IntRect updateRect) 147 { 140 148 uint32_t* pixels32 = static_cast<uint32_t*>(pixels); 141 149 unsigned int glFormat = 0; … … 147 155 // FIXME: This could use PBO's to save doing an extra copy here. 148 156 } 149 OwnArrayPtr<uint32_t> tempBuff(new uint32_t[m_tiles.maxTextureSize() * m_tiles.maxTextureSize()]); 150 151 for (int i = 0; i < m_tiles.numTiles(); i++) { 152 IntRect tileBoundsWithBorder = m_tiles.tileBoundsWithBorder(i); 153 157 int tempBuffSize = // Temporary buffer size is the smaller of the max texture size or the updateRect 158 min(m_tiles.maxTextureSize(), m_tiles.borderTexels() + updateRect.width()) * 159 min(m_tiles.maxTextureSize(), m_tiles.borderTexels() + updateRect.height()); 160 OwnArrayPtr<uint32_t> tempBuff(new uint32_t[tempBuffSize]); 161 162 for (int tile = 0; tile < m_tiles.numTiles(); tile++) { 163 // Intersect with tile 164 IntRect tileBoundsWithBorder = m_tiles.tileBoundsWithBorder(tile); 165 166 IntRect updateRectIntersected = updateRect; 167 updateRectIntersected.intersect(tileBoundsWithBorder); 168 169 IntRect dstRect = updateRectIntersected; 170 dstRect.move(-tileBoundsWithBorder.x(), -tileBoundsWithBorder.y()); 171 172 if (updateRectIntersected.isEmpty()) 173 continue; 174 175 // Copy sub rectangle out of larger pixel data 154 176 uint32_t* uploadBuff = 0; 155 177 if (swizzle) { 156 178 uploadBuff = copySubRect<true>( 157 pixels32, tileBoundsWithBorder.x(), tileBoundsWithBorder.y(),158 tempBuff.get(), tileBoundsWithBorder.width(), tileBoundsWithBorder.height(), m_tiles.totalSizeX());179 pixels32, updateRectIntersected.x(), updateRectIntersected.y(), 180 tempBuff.get(), updateRectIntersected.width(), updateRectIntersected.height(), m_tiles.totalSizeX()); 159 181 } else { 160 182 uploadBuff = copySubRect<false>( 161 pixels32, tileBoundsWithBorder.x(), tileBoundsWithBorder.y(), 162 tempBuff.get(), tileBoundsWithBorder.width(), tileBoundsWithBorder.height(), m_tiles.totalSizeX()); 163 } 164 165 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_tileTextureIds->at(i)); 166 m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, 167 tileBoundsWithBorder.width(), 168 tileBoundsWithBorder.height(), glFormat, glType, uploadBuff); 183 pixels32, updateRectIntersected.x(), updateRectIntersected.y(), 184 tempBuff.get(), updateRectIntersected.width(), updateRectIntersected.height(), m_tiles.totalSizeX()); 185 } 186 187 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_tileTextureIds->at(tile)); 188 m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0 /* level */, 189 dstRect.x(), 190 dstRect.y(), 191 updateRectIntersected.width(), 192 updateRectIntersected.height(), glFormat, glType, uploadBuff); 169 193 } 170 194 } -
trunk/WebCore/platform/graphics/gpu/Texture.h
r66248 r67123 42 42 class GraphicsContext3D; 43 43 44 class IntRect; 45 44 46 class Texture : public RefCounted<Texture> { 45 47 public: … … 49 51 void bindTile(int tile); 50 52 void load(void* pixels); 53 void updateSubRect(void* pixels, const IntRect); 51 54 Format format() const { return m_format; } 52 55 const TilingData& tiles() const { return m_tiles; } -
trunk/WebCore/platform/graphics/gpu/TilingData.h
r66248 r67123 45 45 int totalSizeX() const { return m_totalSizeX; } 46 46 int totalSizeY() const { return m_totalSizeY; } 47 int borderTexels() const { return m_borderTexels; } 47 48 48 49 int numTiles() const { return numTilesX() * numTilesY(); } -
trunk/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
r67039 r67123 1 1 /* 2 2 * Copyright (c) 2006, Google Inc. All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are 6 6 * met: 7 * 7 * 8 8 * * Redistributions of source code must retain the above copyright 9 9 * notice, this list of conditions and the following disclaimer. … … 15 15 * contributors may be used to endorse or promote products derived from 16 16 * this software without specific prior written permission. 17 * 17 * 18 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT … … 66 66 { 67 67 int sign = SkExtractSign(value); 68 68 69 69 value = SkApplySign(value, sign); 70 70 if (value >= max) … … 500 500 if (numPoints <= 1) 501 501 return; 502 502 503 503 // FIXME: IMPLEMENT!! 504 504 } … … 1251 1251 } 1252 1252 1253 void GraphicsContext::markDirtyRect(const IntRect& rect) 1254 { 1255 platformContext()->markDirtyRect(rect); 1256 } 1257 1253 1258 } // namespace WebCore -
trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
r67003 r67123 118 118 destRectFlipped.setY(destRect.y() + destRect.height()); 119 119 destRectFlipped.setHeight(-destRect.height()); 120 context->platformContext()->prepareForHardwareDraw(); 120 121 context->platformContext()->gpuCanvas()->drawTexturedRect(sourceTexture, m_size, srcRect, destRectFlipped, styleColorSpace, op); 121 122 return; -
trunk/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
r67003 r67123 1 1 /* 2 2 * Copyright (c) 2008, Google Inc. All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are 6 6 * met: 7 * 7 * 8 8 * * Redistributions of source code must retain the above copyright 9 9 * notice, this list of conditions and the following disclaimer. … … 15 15 * contributors may be used to endorse or promote products derived from 16 16 * this software without specific prior written permission. 17 * 17 * 18 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT … … 188 188 189 189 // Everything is inherited except for the clip paths. 190 state.m_antiAliasClipPaths.clear(); 190 state.m_antiAliasClipPaths.clear(); 191 191 192 192 return state; … … 340 340 SkColor oldFillColor = m_state->m_fillColor; 341 341 342 // setFillColor() will set the shader to NULL, so save a ref to it now. 342 // setFillColor() will set the shader to NULL, so save a ref to it now. 343 343 SkShader* oldFillShader = m_state->m_fillShader; 344 344 oldFillShader->safeRef(); … … 465 465 { 466 466 m_state->m_fillColor = color; 467 setFillShader( NULL);467 setFillShader(0); 468 468 } 469 469 … … 486 486 { 487 487 m_state->m_strokeColor = strokeColor; 488 setStrokeShader( NULL);488 setStrokeShader(0); 489 489 } 490 490 … … 803 803 } 804 804 805 void PlatformContextSkia::markDirtyRect(const IntRect& rect) 806 { 807 if (!m_useGPU) 808 return; 809 810 switch (m_backingStoreState) { 811 case Software: 812 case Mixed: 813 m_softwareDirtyRect.unite(rect); 814 return; 815 case Hardware: 816 return; 817 default: 818 ASSERT_NOT_REACHED(); 819 } 820 } 821 805 822 void PlatformContextSkia::uploadSoftwareToHardware(CompositeOperator op) const 806 823 { … … 810 827 if (!m_uploadTexture || m_uploadTexture->tiles().totalSizeX() < bitmap.width() || m_uploadTexture->tiles().totalSizeY() < bitmap.height()) 811 828 m_uploadTexture = context->createTexture(Texture::BGRA8, bitmap.width(), bitmap.height()); 812 m_uploadTexture->load(bitmap.getPixels()); 813 IntRect rect(0, 0, bitmap.width(), bitmap.height());829 830 m_uploadTexture->updateSubRect(bitmap.getPixels(), m_softwareDirtyRect); 814 831 AffineTransform identity; 815 gpuCanvas()->drawTexturedRect(m_uploadTexture.get(), rect, rect, identity, 1.0, DeviceColorSpace, op); 832 gpuCanvas()->drawTexturedRect(m_uploadTexture.get(), m_softwareDirtyRect, m_softwareDirtyRect, identity, 1.0, DeviceColorSpace, op); 833 m_softwareDirtyRect.setWidth(0); // Clear dirty rect. 816 834 } 817 835 -
trunk/WebCore/platform/graphics/skia/PlatformContextSkia.h
r67003 r67123 1 1 /* 2 2 * Copyright (c) 2008, Google Inc. All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are 6 6 * met: 7 * 7 * 8 8 * * Redistributions of source code must retain the above copyright 9 9 * notice, this list of conditions and the following disclaimer. … … 15 15 * contributors may be used to endorse or promote products derived from 16 16 * this software without specific prior written permission. 17 * 17 * 18 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT … … 195 195 // Call to force the skia::PlatformCanvas to contain all rendering results. 196 196 void syncSoftwareCanvas() const; 197 void markDirtyRect(const IntRect& rect); 197 198 198 199 private: … … 223 224 SkPath m_path; 224 225 225 // Stores image sizes for a hint to compute image resampling modes. 226 // Stores image sizes for a hint to compute image resampling modes. 226 227 // Values are used in ImageSkia.cpp 227 228 IntSize m_imageResamplingHintSrcSize; … … 234 235 mutable enum { None, Software, Mixed, Hardware } m_backingStoreState; 235 236 mutable RefPtr<Texture> m_uploadTexture; 237 mutable IntRect m_softwareDirtyRect; 236 238 }; 237 239
Note: See TracChangeset
for help on using the changeset viewer.