Changeset 79877 in webkit
- Timestamp:
- Feb 28, 2011 10:03:29 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 added
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r79876 r79877 1 2011-02-25 Adrienne Walker <enne@google.com> 2 3 Reviewed by James Robinson. 4 5 [chromium] Abstract "pixels with a graphics context" into its own class 6 https://bugs.webkit.org/show_bug.cgi?id=55259 7 8 This creates new PlatformCanvas/PlatformImage classes which wrap 9 all of the #ifdef Skia/Cg warts from the compositor. All classes 10 (LayerTilerChromium, ContentLayerChromium, and ImageLayerChromium) are 11 modified to use these abstractions. 12 13 Tests: LayoutTests/compositing 14 15 * WebCore.gypi: 16 * platform/graphics/chromium/ContentLayerChromium.cpp: 17 (WebCore::ContentLayerChromium::updateContentsIfDirty): 18 (WebCore::ContentLayerChromium::resizeUploadBuffer): 19 (WebCore::ContentLayerChromium::updateTextureIfNeeded): 20 (WebCore::ContentLayerChromium::updateTexture): 21 (WebCore::ContentLayerChromium::draw): 22 * platform/graphics/chromium/ContentLayerChromium.h: 23 * platform/graphics/chromium/ImageLayerChromium.cpp: 24 (WebCore::ImageLayerChromium::updateContentsIfDirty): 25 (WebCore::ImageLayerChromium::updateTextureIfNeeded): 26 * platform/graphics/chromium/ImageLayerChromium.h: 27 * platform/graphics/chromium/LayerTilerChromium.cpp: 28 (WebCore::LayerTilerChromium::contentRectToTileIndices): 29 (WebCore::LayerTilerChromium::update): 30 (WebCore::LayerTilerChromium::updateFromPixels): 31 * platform/graphics/chromium/LayerTilerChromium.h: 32 * platform/graphics/chromium/PlatformCanvas.cpp: Added. 33 (WebCore::PlatformCanvas::PlatformCanvas): 34 (WebCore::PlatformCanvas::~PlatformCanvas): 35 (WebCore::PlatformCanvas::resize): 36 (WebCore::PlatformCanvas::AutoLocker::AutoLocker): 37 (WebCore::PlatformCanvas::AutoLocker::~AutoLocker): 38 (WebCore::PlatformCanvas::Painter::Painter): 39 (WebCore::PlatformCanvas::Painter::~Painter): 40 * platform/graphics/chromium/PlatformCanvas.h: Added. 41 (WebCore::PlatformCanvas::AutoLocker::pixels): 42 (WebCore::PlatformCanvas::Painter::context): 43 (WebCore::PlatformCanvas::size): 44 * platform/graphics/chromium/PlatformImage.cpp: Copied from Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp. 45 (WebCore::PlatformImage::PlatformImage): 46 (WebCore::PlatformImage::updateFromImage): 47 * platform/graphics/chromium/PlatformImage.h: Added. 48 (WebCore::PlatformImage::pixels): 49 (WebCore::PlatformImage::size): 50 1 51 2011-02-28 Sheriff Bot <webkit.review.bot@gmail.com> 2 52 -
trunk/Source/WebCore/WebCore.gypi
r79861 r79877 2623 2623 'platform/graphics/chromium/MediaPlayerPrivateChromium.h', 2624 2624 'platform/graphics/chromium/PlatformIcon.h', 2625 'platform/graphics/chromium/PlatformCanvas.cpp', 2626 'platform/graphics/chromium/PlatformCanvas.h', 2627 'platform/graphics/chromium/PlatformImage.cpp', 2628 'platform/graphics/chromium/PlatformImage.h', 2625 2629 'platform/graphics/chromium/PluginLayerChromium.cpp', 2626 2630 'platform/graphics/chromium/PluginLayerChromium.h', -
trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
r79659 r79877 41 41 #include "RenderLayerBacking.h" 42 42 43 #if USE(SKIA)44 #include "NativeImageSkia.h"45 #include "PlatformContextSkia.h"46 #include "SkColorPriv.h"47 #include "skia/ext/platform_canvas.h"48 #elif PLATFORM(CG)49 #include <CoreGraphics/CGBitmapContext.h>50 #endif51 52 43 namespace WebCore { 53 44 … … 137 128 138 129 // If we need to resize the upload buffer we have to repaint everything. 139 if (m_ uploadBufferSize!= visibleRectInLayerCoords.size()) {130 if (m_canvas.size() != visibleRectInLayerCoords.size()) { 140 131 resizeUploadBuffer(visibleRectInLayerCoords.size()); 141 132 m_dirtyRect = boundsRect; … … 162 153 // If the texture needs to be reallocated then we must redraw the entire 163 154 // contents of the layer. 164 if (m_ uploadBufferSize!= bounds()) {155 if (m_canvas.size() != bounds()) { 165 156 resizeUploadBuffer(bounds()); 166 157 dirtyRect = boundsRect; … … 176 167 return; 177 168 178 #if USE(SKIA) 179 OwnPtr<PlatformContextSkia> skiaContext; 180 181 skiaContext.set(new PlatformContextSkia(m_uploadPixelCanvas.get())); 182 183 // This is needed to get text to show up correctly. 184 skiaContext->setDrawingToImageBuffer(true); 185 186 GraphicsContext graphicsContext(reinterpret_cast<PlatformGraphicsContext*>(skiaContext.get())); 187 188 #elif PLATFORM(CG) 189 // FIXME: Do we need to clear the dirty rectangle in the upload buffer? 190 RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); 191 size_t rowBytes = m_uploadBufferSize.width() * 4; 192 RetainPtr<CGContextRef> contextCG(AdoptCF, CGBitmapContextCreate(m_uploadPixelData->data(), 193 m_uploadBufferSize.width(), m_uploadBufferSize.height(), 8, rowBytes, 194 colorSpace.get(), 195 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); 196 CGContextTranslateCTM(contextCG.get(), 0, m_uploadBufferSize.height()); 197 CGContextScaleCTM(contextCG.get(), 1, -1); 198 199 GraphicsContext graphicsContext(contextCG.get()); 200 #else 201 #error "Need to implement for your platform." 202 #endif 203 204 graphicsContext.save(); 205 graphicsContext.translate(-paintingOffset.x(), -paintingOffset.y()); 206 graphicsContext.clearRect(dirtyRect); 207 graphicsContext.clip(dirtyRect); 208 209 m_owner->paintGraphicsLayerContents(graphicsContext, dirtyRect); 210 graphicsContext.restore(); 211 } 212 213 void ContentLayerChromium::resizeUploadBufferForImage(const IntSize& size) 214 { 215 size_t bufferSize = size.width() * size.height() * 4; 216 m_uploadPixelData = new Vector<uint8_t>(bufferSize); 217 #if PLATFORM(CG) 218 memset(m_uploadPixelData->data(), 0, bufferSize); 219 #endif 220 m_uploadBufferSize = size; 221 } 169 PlatformCanvas::Painter painter(&m_canvas); 170 painter.context()->save(); 171 painter.context()->translate(-paintingOffset.x(), -paintingOffset.y()); 172 painter.context()->clearRect(dirtyRect); 173 painter.context()->clip(dirtyRect); 174 175 m_owner->paintGraphicsLayerContents(*painter.context(), dirtyRect); 176 painter.context()->restore(); 177 } 178 222 179 void ContentLayerChromium::resizeUploadBuffer(const IntSize& size) 223 180 { 224 #if USE(SKIA) 225 m_uploadPixelCanvas = new skia::PlatformCanvas(size.width(), size.height(), false); 226 m_uploadBufferSize = size; 227 #else 228 resizeUploadBufferForImage(size); 229 #endif 230 } 231 232 #if USE(SKIA) 233 class SkBitmapConditionalAutoLockerPixels { 234 WTF_MAKE_NONCOPYABLE(SkBitmapConditionalAutoLockerPixels); 235 public: 236 SkBitmapConditionalAutoLockerPixels() 237 : m_bitmap(0) 238 { 239 } 240 241 ~SkBitmapConditionalAutoLockerPixels() 242 { 243 if (m_bitmap) 244 m_bitmap->unlockPixels(); 245 } 246 247 void lockPixels(const SkBitmap* bitmap) 248 { 249 bitmap->lockPixels(); 250 m_bitmap = bitmap; 251 } 252 253 private: 254 const SkBitmap* m_bitmap; 255 }; 256 #endif 181 m_canvas.resize(size); 182 } 257 183 258 184 void ContentLayerChromium::updateTextureIfNeeded() 259 185 { 260 uint8_t* pixels = 0; 261 #if USE(SKIA) 262 SkBitmapConditionalAutoLockerPixels locker; 263 #endif 264 if (!m_uploadUpdateRect.isEmpty()) { 265 #if USE(SKIA) 266 if (m_uploadPixelCanvas) { 267 const SkBitmap& bitmap = m_uploadPixelCanvas->getDevice()->accessBitmap(false); 268 locker.lockPixels(&bitmap); 269 // FIXME: do we need to support more image configurations? 270 if (bitmap.config() == SkBitmap::kARGB_8888_Config) 271 pixels = static_cast<uint8_t*>(bitmap.getPixels()); 272 } 273 #endif 274 if (m_uploadPixelData) 275 pixels = m_uploadPixelData->data(); 276 } 277 186 PlatformCanvas::AutoLocker locker(&m_canvas); 187 updateTexture(locker.pixels(), m_canvas.size()); 188 } 189 190 void ContentLayerChromium::updateTexture(const uint8_t* pixels, const IntSize& size) 191 { 278 192 if (!pixels) 279 193 return; … … 284 198 285 199 // If we have to allocate a new texture we have to upload the full contents. 286 if (!m_contentsTexture->isValid( m_uploadBufferSize, GraphicsContext3D::RGBA))287 m_uploadUpdateRect = IntRect(IntPoint(0, 0), m_uploadBufferSize);288 289 if (!m_contentsTexture->reserve( m_uploadBufferSize, GraphicsContext3D::RGBA)) {200 if (!m_contentsTexture->isValid(size, GraphicsContext3D::RGBA)) 201 m_uploadUpdateRect = IntRect(IntPoint(0, 0), size); 202 203 if (!m_contentsTexture->reserve(size, GraphicsContext3D::RGBA)) { 290 204 m_skipsDraw = true; 291 205 return; 292 206 } 293 207 294 IntRect srcRect = IntRect(IntPoint(0, 0), m_uploadBufferSize);208 IntRect srcRect = IntRect(IntPoint(0, 0), size); 295 209 if (requiresClippedUpdateRect()) 296 210 srcRect = m_visibleRectInLayerCoords; 297 211 298 const size_t destStride = m_uploadUpdateRect.width() * 4;212 const size_t destStride = size.width() * 4; 299 213 const size_t srcStride = srcRect.width() * 4; 300 214 301 uint8_t* uploadPixels = pixels + srcStride * m_uploadUpdateRect.x();215 const uint8_t* uploadPixels = pixels + srcStride * m_uploadUpdateRect.x(); 302 216 Vector<uint8_t> uploadBuffer; 303 217 if (srcStride != destStride) { … … 305 219 for (int row = 0; row < m_uploadUpdateRect.height(); ++row) { 306 220 size_t srcOffset = (m_uploadUpdateRect.y() + row) * srcStride + m_uploadUpdateRect.x() * 4; 307 ASSERT(srcOffset + destStride <= static_cast<size_t>( m_uploadBufferSize.width() * m_uploadBufferSize.height() * 4));221 ASSERT(srcOffset + destStride <= static_cast<size_t>(size.width() * size.height() * 4)); 308 222 size_t destOffset = row * destStride; 309 223 ASSERT(destOffset + destStride <= uploadBuffer.size()); … … 327 241 void ContentLayerChromium::draw() 328 242 { 329 updateTextureIfNeeded();330 331 243 if (m_skipsDraw) 332 244 return; -
trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h
r79578 r79877 36 36 37 37 #include "LayerChromium.h" 38 #include "PlatformCanvas.h" 38 39 #include "TextureManager.h" 39 40 … … 65 66 bool requiresClippedUpdateRect() const; 66 67 void resizeUploadBuffer(const IntSize&); 67 void resizeUploadBufferForImage(const IntSize&);68 68 69 69 OwnPtr<LayerTexture> m_contentsTexture; 70 70 bool m_skipsDraw; 71 71 72 // The size of the upload buffer (also the size of our backing texture).73 IntSize m_uploadBufferSize;74 72 // The portion of the upload buffer that has a pending update, in the coordinates of the texture. 75 73 IntRect m_uploadUpdateRect; 76 // On platforms using Skia, we use the skia::PlatformCanvas for content layers 77 // and the m_uploadPixelData buffer for image layers. 78 // FIXME: We should be using memory we control for all uploads. 79 #if USE(SKIA) 80 OwnPtr<skia::PlatformCanvas> m_uploadPixelCanvas; 81 #endif 82 OwnPtr<Vector<uint8_t> > m_uploadPixelData; 74 75 virtual void updateTextureIfNeeded(); 76 void updateTexture(const uint8_t* pixels, const IntSize&); 83 77 84 78 private: 85 void updateTextureIfNeeded();79 PlatformCanvas m_canvas; 86 80 87 81 IntRect m_visibleRectInLayerCoords; -
trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp
r79578 r79877 39 39 #include "LayerTexture.h" 40 40 41 #if USE(SKIA)42 #include "NativeImageSkia.h"43 #include "PlatformContextSkia.h"44 #endif45 46 #if PLATFORM(CG)47 #include <CoreGraphics/CGBitmapContext.h>48 #include <CoreGraphics/CGContext.h>49 #include <CoreGraphics/CGImage.h>50 #include <wtf/RetainPtr.h>51 #endif52 53 41 namespace WebCore { 54 42 … … 85 73 } 86 74 87 NativeImagePtr nativeImage = m_contents->nativeImageForCurrentFrame(); 75 m_decodedImage.updateFromImage(m_contents->nativeImageForCurrentFrame()); 76 } 88 77 89 #if USE(SKIA) 90 // The layer contains an Image. 91 NativeImageSkia* skiaImage = static_cast<NativeImageSkia*>(nativeImage); 92 const SkBitmap* skiaBitmap = skiaImage; 93 IntSize bitmapSize(skiaBitmap->width(), skiaBitmap->height()); 94 ASSERT(skiaBitmap); 95 #elif PLATFORM(CG) 96 // NativeImagePtr is a CGImageRef on Mac OS X. 97 int width = CGImageGetWidth(nativeImage); 98 int height = CGImageGetHeight(nativeImage); 99 IntSize bitmapSize(width, height); 100 #endif 101 102 if (m_uploadBufferSize != bitmapSize) 103 resizeUploadBufferForImage(bitmapSize); 104 m_uploadUpdateRect = IntRect(IntPoint(0, 0), bitmapSize); 105 106 #if USE(SKIA) 107 SkAutoLockPixels lock(*skiaBitmap); 108 // FIXME: do we need to support more image configurations? 109 ASSERT(skiaBitmap->config()== SkBitmap::kARGB_8888_Config); 110 skiaBitmap->copyPixelsTo(m_uploadPixelData->data(), m_uploadPixelData->size()); 111 #elif PLATFORM(CG) 112 // FIXME: we should get rid of this temporary copy where possible. 113 int tempRowBytes = width * 4; 114 // Note we do not zero this vector since we are going to 115 // completely overwrite its contents with the image below. 116 // Try to reuse the color space from the image to preserve its colors. 117 // Some images use a color space (such as indexed) unsupported by the bitmap context. 118 RetainPtr<CGColorSpaceRef> colorSpaceReleaser; 119 CGColorSpaceRef colorSpace = CGImageGetColorSpace(nativeImage); 120 CGColorSpaceModel colorSpaceModel = CGColorSpaceGetModel(colorSpace); 121 switch (colorSpaceModel) { 122 case kCGColorSpaceModelMonochrome: 123 case kCGColorSpaceModelRGB: 124 case kCGColorSpaceModelCMYK: 125 case kCGColorSpaceModelLab: 126 case kCGColorSpaceModelDeviceN: 127 break; 128 default: 129 colorSpaceReleaser.adoptCF(CGColorSpaceCreateDeviceRGB()); 130 colorSpace = colorSpaceReleaser.get(); 131 break; 132 } 133 RetainPtr<CGContextRef> tempContext(AdoptCF, CGBitmapContextCreate(m_uploadPixelData->data(), 134 width, height, 8, tempRowBytes, 135 colorSpace, 136 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); 137 CGContextSetBlendMode(tempContext.get(), kCGBlendModeCopy); 138 CGContextDrawImage(tempContext.get(), 139 CGRectMake(0, 0, static_cast<CGFloat>(width), static_cast<CGFloat>(height)), 140 nativeImage); 141 #else 142 #error "Need to implement for your platform." 143 #endif 78 void ImageLayerChromium::updateTextureIfNeeded() 79 { 80 updateTexture(m_decodedImage.pixels(), m_decodedImage.size()); 144 81 } 145 82 -
trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.h
r73663 r79877 36 36 37 37 #include "ContentLayerChromium.h" 38 #include "PlatformImage.h" 38 39 39 40 #if PLATFORM(CG) … … 56 57 57 58 private: 59 virtual void updateTextureIfNeeded(); 60 58 61 ImageLayerChromium(GraphicsLayerChromium* owner); 59 62 63 PlatformImage m_decodedImage; 60 64 RefPtr<Image> m_contents; 61 65 }; -
trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.cpp
r79578 r79877 36 36 #include "LayerTexture.h" 37 37 38 #if USE(SKIA)39 #include "NativeImageSkia.h"40 #include "PlatformContextSkia.h"41 #elif PLATFORM(CG)42 #include <CoreGraphics/CGBitmapContext.h>43 #endif44 45 38 #include <wtf/PassOwnArrayPtr.h> 46 39 … … 149 142 left = m_tilingData.tileXIndexFromSrcCoord(layerRect.x()); 150 143 top = m_tilingData.tileYIndexFromSrcCoord(layerRect.y()); 151 right = m_tilingData.tileXIndexFromSrcCoord(layerRect.maxX() );152 bottom = m_tilingData.tileYIndexFromSrcCoord(layerRect.maxY() );144 right = m_tilingData.tileXIndexFromSrcCoord(layerRect.maxX() - 1); 145 bottom = m_tilingData.tileYIndexFromSrcCoord(layerRect.maxY() - 1); 153 146 } 154 147 … … 271 264 272 265 const IntRect paintRect = layerRectToContentRect(dirtyLayerRect); 273 GraphicsContext3D* context = layerRendererContext(); 274 #if USE(SKIA) 275 OwnPtr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas(paintRect.width(), paintRect.height(), false)); 276 OwnPtr<PlatformContextSkia> skiaContext(new PlatformContextSkia(canvas.get())); 277 OwnPtr<GraphicsContext> graphicsContext(new GraphicsContext(reinterpret_cast<PlatformGraphicsContext*>(skiaContext.get()))); 278 279 // Bring the canvas into the coordinate system of the paint rect. 280 canvas->translate(static_cast<SkScalar>(-paintRect.x()), static_cast<SkScalar>(-paintRect.y())); 281 282 painter.paint(*graphicsContext, paintRect); 283 284 // Get the contents of the updated rect. 285 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false); 286 ASSERT(bitmap.width() == paintRect.width() && bitmap.height() == paintRect.height()); 287 if (bitmap.width() != paintRect.width() || bitmap.height() != paintRect.height()) 288 CRASH(); 289 uint8_t* paintPixels = static_cast<uint8_t*>(bitmap.getPixels()); 290 if (!paintPixels) 291 CRASH(); 292 #elif PLATFORM(CG) 293 Vector<uint8_t> canvasPixels; 294 int rowBytes = 4 * paintRect.width(); 295 canvasPixels.resize(rowBytes * paintRect.height()); 296 memset(canvasPixels.data(), 0, canvasPixels.size()); 297 RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); 298 RetainPtr<CGContextRef> m_cgContext; 299 m_cgContext.adoptCF(CGBitmapContextCreate(canvasPixels.data(), 300 paintRect.width(), paintRect.height(), 8, rowBytes, 301 colorSpace.get(), 302 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); 303 CGContextTranslateCTM(m_cgContext.get(), 0, paintRect.height()); 304 CGContextScaleCTM(m_cgContext.get(), 1, -1); 305 OwnPtr<GraphicsContext> m_graphicsContext(new GraphicsContext(m_cgContext.get())); 306 307 // Bring the CoreGraphics context into the coordinate system of the paint rect. 308 CGContextTranslateCTM(m_cgContext.get(), -paintRect.x(), -paintRect.y()); 309 painter.paint(*m_graphicsContext, paintRect); 310 311 // Get the contents of the updated rect. 312 ASSERT(static_cast<int>(CGBitmapContextGetWidth(m_cgContext.get())) == paintRect.width() && static_cast<int>(CGBitmapContextGetHeight(m_cgContext.get())) == paintRect.height()); 313 uint8_t* paintPixels = static_cast<uint8_t*>(canvasPixels.data()); 314 #else 315 #error "Need to implement for your platform." 316 #endif 317 266 267 m_canvas.resize(paintRect.size()); 268 PlatformCanvas::Painter canvasPainter(&m_canvas); 269 canvasPainter.context()->translate(-paintRect.x(), -paintRect.y()); 270 painter.paint(*canvasPainter.context(), paintRect); 271 272 PlatformCanvas::AutoLocker locker(&m_canvas); 273 updateFromPixels(paintRect, locker.pixels()); 274 } 275 276 void LayerTilerChromium::updateFromPixels(const IntRect& paintRect, const uint8_t* paintPixels) 277 { 318 278 // Painting could cause compositing to get turned off, which may cause the tiler to become invalidated mid-update. 319 279 if (!m_tiles.size()) 320 280 return; 321 281 282 GraphicsContext3D* context = layerRendererContext(); 283 284 int left, top, right, bottom; 285 contentRectToTileIndices(paintRect, left, top, right, bottom); 322 286 for (int j = top; j <= bottom; ++j) { 323 287 for (int i = left; i <= right; ++i) { … … 359 323 CRASH(); 360 324 361 uint8_t* pixelSource;325 const uint8_t* pixelSource; 362 326 if (paintRect.width() == sourceRect.width() && !paintOffset.x()) 363 327 pixelSource = &paintPixels[4 * paintOffset.y() * paintRect.width()]; -
trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.h
r79043 r79877 32 32 #include "LayerChromium.h" 33 33 #include "LayerTexture.h" 34 #include "PlatformCanvas.h" 34 35 #include "TilingData.h" 35 36 #include <wtf/OwnArrayPtr.h> … … 57 58 void invalidateEntireLayer(); 58 59 void update(TilePaintInterface& painter, const IntRect& contentRect); 60 void updateFromPixels(const IntRect& paintRect, const uint8_t* pixels); 59 61 void draw(const IntRect& contentRect); 60 62 … … 126 128 Vector<OwnPtr<Tile> > m_unusedTiles; 127 129 130 PlatformCanvas m_canvas; 131 128 132 // Cache a tile-sized pixel buffer to draw into. 129 133 OwnArrayPtr<uint8_t> m_tilePixels; -
trunk/Source/WebCore/platform/graphics/chromium/PlatformImage.cpp
r79876 r79877 1 1 /* 2 * Copyright (C) 201 0Google Inc. All rights reserved.2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are6 * met:5 * modification, are permitted provided that the following conditions 6 * are met: 7 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 17 13 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 24 */ 30 25 31 26 #include "config.h" 32 27 33 #if USE(ACCELERATED_COMPOSITING) 34 35 #include "ImageLayerChromium.h" 36 37 #include "Image.h" 38 #include "LayerRendererChromium.h" 39 #include "LayerTexture.h" 28 #include "PlatformImage.h" 40 29 41 30 #if USE(SKIA) 42 31 #include "NativeImageSkia.h" 43 32 #include "PlatformContextSkia.h" 44 #endif 45 46 #if PLATFORM(CG) 33 #elif PLATFORM(CG) 47 34 #include <CoreGraphics/CGBitmapContext.h> 48 35 #include <CoreGraphics/CGContext.h> 49 36 #include <CoreGraphics/CGImage.h> 50 37 #include <wtf/RetainPtr.h> 38 #else 39 #error "Need to implement for your platform" 51 40 #endif 52 41 53 42 namespace WebCore { 54 43 55 PassRefPtr<ImageLayerChromium> ImageLayerChromium::create(GraphicsLayerChromium* owner) 56 { 57 return adoptRef(new ImageLayerChromium(owner)); 58 } 59 60 ImageLayerChromium::ImageLayerChromium(GraphicsLayerChromium* owner) 61 : ContentLayerChromium(owner) 62 , m_contents(0) 44 PlatformImage::PlatformImage() 63 45 { 64 46 } 65 47 66 void ImageLayerChromium::setContents(Image* contents)48 void PlatformImage::updateFromImage(NativeImagePtr nativeImage) 67 49 { 68 // Check if the image has changed.69 if (m_contents == contents)70 return;71 m_contents = contents;72 setNeedsDisplay();73 }74 75 void ImageLayerChromium::updateContentsIfDirty()76 {77 ASSERT(layerRenderer());78 79 // FIXME: Remove this test when tiled layers are implemented.80 if (requiresClippedUpdateRect()) {81 // Use the base version of updateContents which draws a subset of the82 // image to a bitmap, as the pixel contents can't be uploaded directly.83 ContentLayerChromium::updateContentsIfDirty();84 return;85 }86 87 NativeImagePtr nativeImage = m_contents->nativeImageForCurrentFrame();88 89 50 #if USE(SKIA) 90 51 // The layer contains an Image. 91 52 NativeImageSkia* skiaImage = static_cast<NativeImageSkia*>(nativeImage); 92 53 const SkBitmap* skiaBitmap = skiaImage; 54 93 55 IntSize bitmapSize(skiaBitmap->width(), skiaBitmap->height()); 94 56 ASSERT(skiaBitmap); … … 100 62 #endif 101 63 102 if (m_uploadBufferSize != bitmapSize) 103 resizeUploadBufferForImage(bitmapSize); 104 m_uploadUpdateRect = IntRect(IntPoint(0, 0), bitmapSize); 64 size_t bufferSize = bitmapSize.width() * bitmapSize.height() * 4; 65 if (m_size != bitmapSize) { 66 m_pixelData = adoptArrayPtr(new uint8_t[bufferSize]); 67 memset(m_pixelData.get(), 0, bufferSize); 68 m_size = bitmapSize; 69 } 105 70 106 71 #if USE(SKIA) … … 108 73 // FIXME: do we need to support more image configurations? 109 74 ASSERT(skiaBitmap->config()== SkBitmap::kARGB_8888_Config); 110 skiaBitmap->copyPixelsTo(m_ uploadPixelData->data(), m_uploadPixelData->size());75 skiaBitmap->copyPixelsTo(m_pixelData.get(), bufferSize); 111 76 #elif PLATFORM(CG) 112 77 // FIXME: we should get rid of this temporary copy where possible. … … 131 96 break; 132 97 } 133 RetainPtr<CGContextRef> tempContext(AdoptCF, CGBitmapContextCreate(m_ uploadPixelData->data(),98 RetainPtr<CGContextRef> tempContext(AdoptCF, CGBitmapContextCreate(m_pixelData.get(), 134 99 width, height, 8, tempRowBytes, 135 100 colorSpace, … … 144 109 } 145 110 146 } 147 #endif // USE(ACCELERATED_COMPOSITING) 111 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.