Changeset 115385 in webkit
- Timestamp:
- Apr 26, 2012 4:03:06 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 2 added
- 17 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r115383 r115385 1 2012-04-26 Martin Robinson <mrobinson@igalia.com> 2 3 [Cairo] Wrap cairo surfaces in a class when storing native images 4 https://bugs.webkit.org/show_bug.cgi?id=83611 5 6 Reviewed by Alejandro G. Castro. 7 8 No new tests. This is just a refactoring. This shouldn't change 9 functionality. 10 11 Added class that wraps Cairo images surfaces to serve as the "native image" 12 type for the Cairo platform. This will allow the addition of caching resampled 13 images as well as versions of the image for non-image Cairo backends. Also 14 split out BitmapImageCairo.cpp from ImageCairo.cpp since these classes are 15 defined in two headers. 16 17 * GNUmakefile.list.am: Added new files. 18 * platform/graphics/BitmapImage.h: Added a factory method that takes an image surface to 19 reduce code churn. 20 * platform/graphics/ImageSource.h: NativeImagePtr is now NativeImageCairo*. 21 (WebCore): 22 * platform/graphics/cairo/BitmapImageCairo.cpp: Copied from Source/WebCore/platform/graphics/cairo/ImageCairo.cpp. 23 * platform/graphics/cairo/GraphicsContext3DCairo.cpp: Updated to reflect use of NativeImageCairo. 24 * platform/graphics/cairo/ImageCairo.cpp: Ditto. 25 * platform/graphics/cairo/NativeImageCairo.cpp: Added. 26 * platform/graphics/cairo/NativeImageCairo.h: Added. 27 * platform/graphics/cairo/PatternCairo.cpp: Updated to reflect use of NativeImageCairo. 28 * platform/graphics/gtk/ImageGtk.cpp: Ditto. 29 * platform/image-decoders/cairo/ImageDecoderCairo.cpp: Ditto. 30 1 31 2012-04-26 Mark Hahnenberg <mhahnenberg@apple.com> 2 32 -
trunk/Source/WebCore/GNUmakefile.list.am
r115274 r115385 3109 3109 Source/WebCore/platform/graphics/DashArray.h \ 3110 3110 Source/WebCore/platform/graphics/Extensions3D.h \ 3111 Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp \ 3111 3112 Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp \ 3112 3113 Source/WebCore/platform/graphics/cairo/CairoUtilities.h \ … … 3119 3120 Source/WebCore/platform/graphics/cairo/ImageCairo.cpp \ 3120 3121 Source/WebCore/platform/graphics/cairo/IntRectCairo.cpp \ 3122 Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp \ 3123 Source/WebCore/platform/graphics/cairo/NativeImageCairo.h \ 3121 3124 Source/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp \ 3122 3125 Source/WebCore/platform/graphics/cairo/OwnPtrCairo.h \ -
trunk/Source/WebCore/PlatformEfl.cmake
r114269 r115385 120 120 LIST(APPEND WebCore_SOURCES 121 121 platform/cairo/WidgetBackingStoreCairo.cpp 122 platform/graphics/cairo/BitmapImageCairo.cpp 122 123 platform/graphics/cairo/CairoUtilities.cpp 123 124 platform/graphics/cairo/FontCairo.cpp … … 126 127 platform/graphics/cairo/ImageBufferCairo.cpp 127 128 platform/graphics/cairo/ImageCairo.cpp 129 platform/graphics/cairo/NativeImageCairo.cpp 128 130 platform/graphics/cairo/OwnPtrCairo.cpp 129 131 platform/graphics/cairo/PathCairo.cpp -
trunk/Source/WebCore/platform/graphics/BitmapImage.h
r113624 r115385 161 161 #endif 162 162 163 #if USE(CAIRO) 164 static PassRefPtr<BitmapImage> create(cairo_surface_t*); 165 #endif 166 163 167 #if PLATFORM(GTK) 164 168 virtual GdkPixbuf* getGdkPixbuf(); -
trunk/Source/WebCore/platform/graphics/ImageSource.h
r114683 r115385 47 47 QT_END_NAMESPACE 48 48 #elif USE(CAIRO) 49 struct _cairo_surface; 50 typedef struct _cairo_surface cairo_surface_t; 49 #include "NativeImageCairo.h" 51 50 #elif USE(SKIA) 52 51 namespace WebCore { … … 91 90 #endif 92 91 #elif USE(CAIRO) 93 typedef cairo_surface_t* NativeImagePtr;92 typedef WebCore::NativeImageCairo* NativeImagePtr; 94 93 #elif USE(SKIA) 95 94 typedef WebCore::NativeImageSkia* NativeImagePtr; -
trunk/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp
r115383 r115385 29 29 #include "BitmapImage.h" 30 30 31 #if USE(CAIRO) 32 33 #include "AffineTransform.h" 34 #include "CairoUtilities.h" 35 #include "Color.h" 36 #include "FloatRect.h" 37 #include "GraphicsContext.h" 31 #include "ImageObserver.h" 32 #include "NativeImageCairo.h" 38 33 #include "PlatformContextCairo.h" 39 #include "ImageBuffer.h"40 #include "ImageObserver.h"41 #include "RefPtrCairo.h"42 34 #include <cairo.h> 43 #include <math.h>44 #include <wtf/OwnPtr.h>45 35 46 36 namespace WebCore { 47 37 48 bool FrameData::clear(bool clearMetadata)38 PassRefPtr<BitmapImage> BitmapImage::create(cairo_surface_t* surface) 49 39 { 50 if (clearMetadata) 51 m_haveMetadata = false; 52 53 if (m_frame) { 54 cairo_surface_destroy(m_frame); 55 m_frame = 0; 56 return true; 57 } 58 return false; 40 return BitmapImage::create(new NativeImageCairo(surface)); 59 41 } 60 42 61 BitmapImage::BitmapImage( cairo_surface_t* surface, ImageObserver* observer)43 BitmapImage::BitmapImage(NativeImageCairo* nativeImage, ImageObserver* observer) 62 44 : Image(observer) 63 45 , m_currentFrame(0) … … 79 61 initPlatformData(); 80 62 81 // TODO: check to be sure this is an image surface 82 63 cairo_surface_t* surface = nativeImage->surface(); 83 64 int width = cairo_image_surface_get_width(surface); 84 65 int height = cairo_image_surface_get_height(surface); … … 87 68 88 69 m_frames.grow(1); 89 m_frames[0].m_frame = surface;70 m_frames[0].m_frame = nativeImage; 90 71 m_frames[0].m_hasAlpha = cairo_surface_get_content(surface) != CAIRO_CONTENT_COLOR; 91 72 m_frames[0].m_haveMetadata = true; … … 98 79 FloatRect dstRect(dst); 99 80 100 if (dstRect.width() == 0.0f || dstRect.height() == 0.0f || 101 srcRect.width() == 0.0f || srcRect.height() == 0.0f) 81 if (!dstRect.width() || !dstRect.height() || !srcRect.width() || !srcRect.height()) 102 82 return; 103 83 104 84 startAnimation(); 105 85 106 cairo_surface_t* image = frameAtIndex(m_currentFrame);107 if (! image) // If it's too early we won't have an image yet.86 NativeImageCairo* nativeImage = frameAtIndex(m_currentFrame); 87 if (!nativeImage) // If it's too early we won't have an image yet. 108 88 return; 109 89 … … 120 100 else 121 101 context->setCompositeOperation(op); 122 context->platformContext()->drawSurfaceToContext( image, dstRect, srcRect, context);102 context->platformContext()->drawSurfaceToContext(nativeImage->surface(), dstRect, srcRect, context); 123 103 124 104 context->restore(); 125 126 if (imageObserver())127 imageObserver()->didDraw(this);128 }129 130 void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const AffineTransform& patternTransform,131 const FloatPoint& phase, ColorSpace colorSpace, CompositeOperator op, const FloatRect& destRect)132 {133 cairo_surface_t* image = nativeImageForCurrentFrame();134 if (!image) // If it's too early we won't have an image yet.135 return;136 137 cairo_t* cr = context->platformContext()->cr();138 drawPatternToCairoContext(cr, image, size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect);139 105 140 106 if (imageObserver()) … … 150 116 return; 151 117 152 cairo_surface_t* frameSurface = frameAtIndex(0);153 if (! frameSurface)118 NativeImageCairo* nativeImage = frameAtIndex(m_currentFrame); 119 if (!nativeImage) // If it's too early we won't have an image yet. 154 120 return; 155 121 156 ASSERT(cairo_surface_get_type(frameSurface) == CAIRO_SURFACE_TYPE_IMAGE); 122 cairo_surface_t* surface = nativeImage->surface(); 123 ASSERT(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE); 157 124 158 int width = cairo_image_surface_get_width( frameSurface);159 int height = cairo_image_surface_get_height( frameSurface);125 int width = cairo_image_surface_get_width(surface); 126 int height = cairo_image_surface_get_height(surface); 160 127 161 128 if (width != 1 || height != 1) 162 129 return; 163 130 164 unsigned* pixelColor = reinterpret_cast<unsigned*>(cairo_image_surface_get_data( frameSurface));131 unsigned* pixelColor = reinterpret_cast<unsigned*>(cairo_image_surface_get_data(surface)); 165 132 m_solidColor = colorFromPremultipliedARGB(*pixelColor); 166 133 … … 168 135 } 169 136 137 bool FrameData::clear(bool clearMetadata) 138 { 139 if (clearMetadata) 140 m_haveMetadata = false; 141 142 if (m_frame) { 143 delete m_frame; 144 m_frame = 0; 145 return true; 146 } 147 return false; 170 148 } 171 149 172 #endif // USE(CAIRO) 150 } // namespace WebCore 151 -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp
r109609 r115385 158 158 if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0)) 159 159 return false; 160 imageSurface = decoder.createFrameAtIndex(0) ;160 imageSurface = decoder.createFrameAtIndex(0)->surface(); 161 161 } else { 162 imageSurface = image->nativeImageForCurrentFrame() ;162 imageSurface = image->nativeImageForCurrentFrame()->surface(); 163 163 if (!premultiplyAlpha) 164 164 alphaOp = AlphaDoUnmultiply; -
trunk/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp
r102404 r115385 27 27 28 28 #include "config.h" 29 #include " BitmapImage.h"29 #include "Image.h" 30 30 31 31 #if USE(CAIRO) … … 34 34 #include "CairoUtilities.h" 35 35 #include "Color.h" 36 #include "FloatRect.h"37 36 #include "GraphicsContext.h" 37 #include "ImageObserver.h" 38 #include "NativeImageCairo.h" 38 39 #include "PlatformContextCairo.h" 39 #include "ImageBuffer.h"40 #include "ImageObserver.h"41 #include "RefPtrCairo.h"42 40 #include <cairo.h> 43 41 #include <math.h> 44 #include <wtf/OwnPtr.h>45 42 46 43 namespace WebCore { 47 44 48 bool FrameData::clear(bool clearMetadata) 45 void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const AffineTransform& patternTransform, 46 const FloatPoint& phase, ColorSpace colorSpace, CompositeOperator op, const FloatRect& destRect) 49 47 { 50 if (clearMetadata) 51 m_haveMetadata = false; 52 53 if (m_frame) { 54 cairo_surface_destroy(m_frame); 55 m_frame = 0; 56 return true; 57 } 58 return false; 59 } 60 61 BitmapImage::BitmapImage(cairo_surface_t* surface, ImageObserver* observer) 62 : Image(observer) 63 , m_currentFrame(0) 64 , m_frames(0) 65 , m_frameTimer(0) 66 , m_repetitionCount(cAnimationNone) 67 , m_repetitionCountStatus(Unknown) 68 , m_repetitionsComplete(0) 69 , m_decodedSize(0) 70 , m_frameCount(1) 71 , m_isSolidColor(false) 72 , m_checkedForSolidColor(false) 73 , m_animationFinished(true) 74 , m_allDataReceived(true) 75 , m_haveSize(true) 76 , m_sizeAvailable(true) 77 , m_haveFrameCount(true) 78 { 79 initPlatformData(); 80 81 // TODO: check to be sure this is an image surface 82 83 int width = cairo_image_surface_get_width(surface); 84 int height = cairo_image_surface_get_height(surface); 85 m_decodedSize = width * height * 4; 86 m_size = IntSize(width, height); 87 88 m_frames.grow(1); 89 m_frames[0].m_frame = surface; 90 m_frames[0].m_hasAlpha = cairo_surface_get_content(surface) != CAIRO_CONTENT_COLOR; 91 m_frames[0].m_haveMetadata = true; 92 checkForSolidColor(); 93 } 94 95 void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op) 96 { 97 FloatRect srcRect(src); 98 FloatRect dstRect(dst); 99 100 if (dstRect.width() == 0.0f || dstRect.height() == 0.0f || 101 srcRect.width() == 0.0f || srcRect.height() == 0.0f) 102 return; 103 104 startAnimation(); 105 106 cairo_surface_t* image = frameAtIndex(m_currentFrame); 48 NativeImageCairo* image = nativeImageForCurrentFrame(); 107 49 if (!image) // If it's too early we won't have an image yet. 108 50 return; 109 51 110 if (mayFillWithSolidColor()) { 111 fillWithSolidColor(context, dstRect, solidColor(), styleColorSpace, op); 112 return; 113 } 114 115 context->save(); 116 117 // Set the compositing operation. 118 if (op == CompositeSourceOver && !frameHasAlphaAtIndex(m_currentFrame)) 119 context->setCompositeOperation(CompositeCopy); 120 else 121 context->setCompositeOperation(op); 122 context->platformContext()->drawSurfaceToContext(image, dstRect, srcRect, context); 123 124 context->restore(); 52 cairo_t* cr = context->platformContext()->cr(); 53 drawPatternToCairoContext(cr, image->surface(), size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect); 125 54 126 55 if (imageObserver()) … … 128 57 } 129 58 130 void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const AffineTransform& patternTransform,131 const FloatPoint& phase, ColorSpace colorSpace, CompositeOperator op, const FloatRect& destRect)132 {133 cairo_surface_t* image = nativeImageForCurrentFrame();134 if (!image) // If it's too early we won't have an image yet.135 return;136 137 cairo_t* cr = context->platformContext()->cr();138 drawPatternToCairoContext(cr, image, size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect);139 140 if (imageObserver())141 imageObserver()->didDraw(this);142 }143 144 void BitmapImage::checkForSolidColor()145 {146 m_isSolidColor = false;147 m_checkedForSolidColor = true;148 149 if (frameCount() > 1)150 return;151 152 cairo_surface_t* frameSurface = frameAtIndex(0);153 if (!frameSurface)154 return;155 156 ASSERT(cairo_surface_get_type(frameSurface) == CAIRO_SURFACE_TYPE_IMAGE);157 158 int width = cairo_image_surface_get_width(frameSurface);159 int height = cairo_image_surface_get_height(frameSurface);160 161 if (width != 1 || height != 1)162 return;163 164 unsigned* pixelColor = reinterpret_cast<unsigned*>(cairo_image_surface_get_data(frameSurface));165 m_solidColor = colorFromPremultipliedARGB(*pixelColor);166 167 m_isSolidColor = true;168 }169 170 59 } 171 60 -
trunk/Source/WebCore/platform/graphics/cairo/PatternCairo.cpp
r95901 r115385 29 29 #include "AffineTransform.h" 30 30 #include "GraphicsContext.h" 31 32 31 #include <cairo.h> 33 32 … … 36 35 cairo_pattern_t* Pattern::createPlatformPattern(const AffineTransform&) const 37 36 { 38 cairo_surface_t* surface = tileImage()->nativeImageForCurrentFrame();39 if (! surface)37 NativeImageCairo* image = tileImage()->nativeImageForCurrentFrame(); 38 if (!image) 40 39 return 0; 41 40 42 cairo_pattern_t* pattern = cairo_pattern_create_for_surface( surface);41 cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image->surface()); 43 42 44 43 // cairo merges patter space and user space itself -
trunk/Source/WebCore/platform/graphics/gtk/ImageGtk.cpp
r108206 r115385 113 113 GdkPixbuf* BitmapImage::getGdkPixbuf() 114 114 { 115 cairo_surface_t* frame = frameAtIndex(currentFrame()); 116 if (!frame) 117 return 0; 118 return cairoImageSurfaceToGdkPixbuf(frame); 115 NativeImageCairo* image = nativeImageForCurrentFrame(); 116 return image ? cairoImageSurfaceToGdkPixbuf(image->surface()) : 0; 119 117 } 120 118 -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
r114992 r115385 490 490 bytesPerLine = qtImage.bytesPerLine(); 491 491 #elif USE(CAIRO) 492 imageData = reinterpret_cast<const char*>(cairo_image_surface_get_data(frameImage)); 493 bytesPerLine = cairo_image_surface_get_stride(frameImage); 492 cairo_surface_t* surface = frameImage->surface(); 493 imageData = reinterpret_cast<const char*>(cairo_image_surface_get_data(surface)); 494 bytesPerLine = cairo_image_surface_get_stride(surface); 494 495 #endif 495 496 -
trunk/Source/WebCore/platform/gtk/DragImageGtk.cpp
r113486 r115385 76 76 DragImageRef createDragImageFromImage(Image* image, RespectImageOrientationEnum) 77 77 { 78 return cairo_surface_reference(image->nativeImageForCurrentFrame()); 78 NativeImageCairo* nativeImage = image->nativeImageForCurrentFrame(); 79 return nativeImage ? cairo_surface_reference(nativeImage->surface()) : 0; 79 80 } 80 81 -
trunk/Source/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp
r95901 r115385 33 33 NativeImagePtr ImageFrame::asNewNativeImage() const 34 34 { 35 return cairo_image_surface_create_for_data( 36 reinterpret_cast<unsigned char*>(const_cast<PixelData*>( 37 m_bytes)), CAIRO_FORMAT_ARGB32, width(), height(), 38 width() * sizeof(PixelData)); 35 return new NativeImageCairo(cairo_image_surface_create_for_data( 36 reinterpret_cast<unsigned char*>(const_cast<PixelData*>(m_bytes)), 37 CAIRO_FORMAT_ARGB32, width(), height(), width() * sizeof(PixelData))); 39 38 } 40 39 -
trunk/Source/WebKit/efl/ChangeLog
r115341 r115385 1 2012-04-26 Martin Robinson <mrobinson@igalia.com> 2 3 [Cairo] Wrap cairo surfaces in a class when storing native images 4 https://bugs.webkit.org/show_bug.cgi?id=83611 5 6 Reviewed by Alejandro G. Castro. 7 8 * ewk/ewk_history.cpp: Updated to reflect addition of NativeImageCario. 9 * ewk/ewk_settings.cpp: Ditto. 10 1 11 2012-04-26 Christophe Dumez <christophe.dumez@intel.com> 2 12 -
trunk/Source/WebKit/efl/ewk/ewk_history.cpp
r109205 r115385 342 342 return 0; 343 343 } 344 return icon->nativeImageForCurrentFrame(); 344 345 WebCore::NativeImageCairo* nativeImage = icon->nativeImageForCurrentFrame(); 346 return nativeImage ? nativeImage->surface() : 0; 345 347 } 346 348 … … 350 352 EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0); 351 353 WebCore::Image* icon = WebCore::iconDatabase().synchronousIconForPageURL(core->url(), WebCore::IntSize(16, 16)); 352 cairo_surface_t* surface;353 354 354 355 if (!icon) { … … 357 358 } 358 359 359 surface = icon->nativeImageForCurrentFrame();360 return ewk_util_image_from_cairo_surface_add(canvas, surface);360 WebCore::NativeImageCairo* nativeImage = icon->nativeImageForCurrentFrame(); 361 return nativeImage ? ewk_util_image_from_cairo_surface_add(canvas, nativeImage->surface()) : 0; 361 362 } 362 363 -
trunk/Source/WebKit/efl/ewk/ewk_settings.cpp
r113173 r115385 226 226 } 227 227 228 return icon->nativeImageForCurrentFrame(); 228 WebCore::NativeImageCairo* nativeImage = icon->nativeImageForCurrentFrame(); 229 return nativeImage ? nativeImage->surface() : 0; 229 230 } 230 231 … … 236 237 WebCore::KURL kurl(WebCore::KURL(), WTF::String::fromUTF8(url)); 237 238 WebCore::Image* icon = WebCore::iconDatabase().synchronousIconForPageURL(kurl.string(), WebCore::IntSize(16, 16)); 238 cairo_surface_t* surface;239 239 240 240 if (!icon) { … … 243 243 } 244 244 245 surface = icon->nativeImageForCurrentFrame();246 return ewk_util_image_from_cairo_surface_add(canvas, surface);245 WebCore::NativeImageCairo* nativeImage = icon->nativeImageForCurrentFrame(); 246 return nativeImage ? ewk_util_image_from_cairo_surface_add(canvas, nativeImage->surface()) : 0; 247 247 } 248 248 -
trunk/Source/WebKit2/ChangeLog
r115369 r115385 1 2012-04-26 Martin Robinson <mrobinson@igalia.com> 2 3 [Cairo] Wrap cairo surfaces in a class when storing native images 4 https://bugs.webkit.org/show_bug.cgi?id=83611 5 6 Reviewed by Alejandro G. Castro. 7 8 * Shared/gtk/ArgumentCodersGtk.cpp: Updated to reflect the addition of NativeImageCairo. 9 1 10 2012-04-26 Jon Lee <jonlee@apple.com> 2 11 -
trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp
r106117 r115385 72 72 return false; 73 73 74 cairo_surface_t* surface = image->nativeImageForCurrentFrame(); 75 if (!surface) 76 return false; 77 74 NativeImageCairo* nativeImage = image->nativeImageForCurrentFrame(); 75 if (!nativeImage) 76 return false; 77 78 cairo_surface_t* surface = nativeImage->surface(); 78 79 pixbuf = adoptGRef(gdk_pixbuf_get_from_surface(surface, 0, 0, 79 80 cairo_image_surface_get_width(surface),
Note: See TracChangeset
for help on using the changeset viewer.