Changeset 28971 in webkit
- Timestamp:
- Dec 23, 2007 7:04:19 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r28970 r28971 1 2007-12-23 Alp Toker <alp@atoker.com> 2 3 Reviewed by Holger Freyther. 4 5 http://bugs.webkit.org/show_bug.cgi?id=15382 6 [CAIRO] Canvas pattern support 7 8 http://bugs.webkit.org/show_bug.cgi?id=16577 9 Merge Cairo enhancements from Apollo project 10 11 Add support for canvas patterns. 12 13 Make Image::nativeImageForCurrentFrame() public. 14 15 Fix some typos along the way. 16 17 The globalAlpha canvas fixes are not included in this patch as 18 they're slightly more intrusive and may conflict conceptually with 19 GraphicsContext::setAlpha(). 20 21 * html/CanvasPattern.cpp: 22 (WebCore::CanvasPattern::CanvasPattern): 23 (WebCore::CanvasPattern::~CanvasPattern): 24 (WebCore::CanvasPattern::createPattern): 25 * html/CanvasPattern.h: 26 (WebCore::CanvasPattern::platformImage): 27 * html/CanvasRenderingContext2D.cpp: 28 (WebCore::CanvasRenderingContext2D::setShadow): 29 (WebCore::CanvasRenderingContext2D::applyShadow): 30 (WebCore::CanvasRenderingContext2D::drawImage): 31 (WebCore::CanvasRenderingContext2D::createPattern): 32 (WebCore::CanvasRenderingContext2D::applyStrokePattern): 33 (WebCore::CanvasRenderingContext2D::applyFillPattern): 34 * platform/graphics/Image.h: 35 (WebCore::Image::nativeImageForCurrentFrame): 36 1 37 2007-12-23 Kevin Ollivier <kevino@theolliviers.com> 2 38 -
trunk/WebCore/html/CanvasPattern.cpp
r25124 r28971 74 74 } 75 75 76 #elif PLATFORM(CAIRO) 77 78 CanvasPattern::CanvasPattern(cairo_surface_t* surface, bool repeatX, bool repeatY) 79 : m_platformImage(surface) 80 , m_cachedImage(0) 81 , m_repeatX(repeatX) 82 , m_repeatY(repeatY) 83 { 84 } 85 76 86 #endif 77 87 78 88 CanvasPattern::CanvasPattern(CachedImage* cachedImage, bool repeatX, bool repeatY) 79 89 : 80 #if PLATFORM(CG) 90 #if PLATFORM(CG) || PLATFORM(CAIRO) 81 91 m_platformImage(0) 82 92 , … … 92 102 CanvasPattern::~CanvasPattern() 93 103 { 104 #if PLATFORM(CAIRO) 105 if (m_platformImage) 106 cairo_surface_destroy(m_platformImage); 107 #endif 94 108 if (m_cachedImage) 95 109 m_cachedImage->deref(this); … … 169 183 } 170 184 171 #endif 172 173 } 185 #elif PLATFORM(CAIRO) 186 187 cairo_pattern_t* CanvasPattern::createPattern(const cairo_matrix_t& m) 188 { 189 cairo_surface_t* surface = 0; 190 if (m_platformImage) { 191 surface = m_platformImage; 192 } else { 193 if (!m_cachedImage) 194 return 0; 195 Image* image = m_cachedImage->image(); 196 if (!image) 197 return 0; 198 surface = image->nativeImageForCurrentFrame(); 199 } 200 201 if (!surface) 202 return 0; 203 204 cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface); 205 cairo_pattern_set_matrix(pattern, &m); 206 if (m_repeatX || m_repeatY) 207 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); 208 return pattern; 209 } 210 211 #endif 212 213 } -
trunk/WebCore/html/CanvasPattern.h
r27776 r28971 33 33 #include <wtf/RetainPtr.h> 34 34 #include <ApplicationServices/ApplicationServices.h> 35 #elif PLATFORM(CAIRO) 36 #include <cairo.h> 35 37 #endif 36 38 … … 48 50 #if PLATFORM(CG) 49 51 CanvasPattern(CGImageRef, bool repeatX, bool repeatY); 52 #elif PLATFORM(CAIRO) 53 CanvasPattern(cairo_surface_t*, bool repeatX, bool repeatY); 50 54 #endif 51 55 CanvasPattern(CachedImage*, bool repeatX, bool repeatY); … … 54 58 #if PLATFORM(CG) 55 59 CGImageRef platformImage() const { return m_platformImage.get(); } 60 #elif PLATFORM(CAIRO) 61 cairo_surface_t* platformImage() const { return m_platformImage; } 56 62 #endif 57 63 CachedImage* cachedImage() const { return m_cachedImage; } … … 59 65 #if PLATFORM(CG) 60 66 CGPatternRef createPattern(const CGAffineTransform&); 67 #elif PLATFORM(CAIRO) 68 cairo_pattern_t* createPattern(const cairo_matrix_t&); 61 69 #endif 62 70 … … 64 72 #if PLATFORM(CG) 65 73 const RetainPtr<CGImageRef> m_platformImage; 74 #elif PLATFORM(CAIRO) 75 cairo_surface_t* const m_platformImage; 66 76 #endif 67 77 CachedImage* const m_cachedImage; -
trunk/WebCore/html/CanvasRenderingContext2D.cpp
r28944 r28971 726 726 // FIXME: Do this through platform-independent GraphicsContext API. 727 727 #if PLATFORM(CG) 728 RGBA32 rgba = 0; // default is transpar ant black728 RGBA32 rgba = 0; // default is transparent black 729 729 CSSParser::parseColor(rgba, color); 730 730 const CGFloat components[4] = { … … 817 817 // FIXME: Do this through platform-independent GraphicsContext API. 818 818 #if PLATFORM(CG) 819 RGBA32 rgba = 0; // default is transpar ant black819 RGBA32 rgba = 0; // default is transparent black 820 820 if (!state().m_shadowColor.isEmpty()) 821 821 CSSParser::parseColor(rgba, state().m_shadowColor); … … 978 978 return; 979 979 willDraw(dstRect); 980 981 float iw = cairo_image_surface_get_width(image); 982 float ih = cairo_image_surface_get_height(image); 983 984 if (sourceRect.x() == 0 && sourceRect.y() == 0 && iw == sourceRect.width() && ih == sourceRect.height()) { 985 cairo_t* cr = c->platformContext(); 986 cairo_save(cr); 987 cairo_set_source_surface(cr, image, srcRect.x(), srcRect.y()); 988 cairo_surface_destroy(image); 989 cairo_rectangle(cr, dstRect.x(), dstRect.y(), dstRect.width(), dstRect.height()); 990 cairo_fill(cr); 991 cairo_restore(cr); 992 } else 993 notImplemented(); 994 980 cairo_t* cr = c->platformContext(); 981 cairo_save(cr); 982 cairo_set_source_surface(cr, image, srcRect.x(), srcRect.y()); 983 cairo_surface_destroy(image); 984 cairo_rectangle(cr, dstRect.x(), dstRect.y(), dstRect.width(), dstRect.height()); 985 cairo_fill(cr); 986 cairo_restore(cr); 995 987 #endif 996 988 } … … 1069 1061 CGImageRelease(image); 1070 1062 return pattern; 1063 #elif PLATFORM(CAIRO) 1064 cairo_surface_t* surface = canvas->createPlatformImage(); 1065 if (!surface) 1066 return 0; 1067 PassRefPtr<CanvasPattern> pattern = new CanvasPattern(surface, repeatX, repeatY); 1068 cairo_surface_destroy(surface); 1069 return pattern; 1071 1070 #else 1072 1071 notImplemented(); … … 1122 1121 fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyStrokePattern\n"); 1123 1122 #elif PLATFORM(CAIRO) 1124 notImplemented(); 1123 CanvasPattern* pattern = state().m_strokeStyle->pattern(); 1124 if (!pattern) 1125 return; 1126 1127 cairo_t* cr = c->platformContext(); 1128 cairo_matrix_t m; 1129 cairo_get_matrix(cr, &m); 1130 1131 cairo_pattern_t* platformPattern = pattern->createPattern(m); 1132 if (!platformPattern) 1133 return; 1134 1135 cairo_set_source(cr, platformPattern); 1136 cairo_pattern_destroy(platformPattern); 1125 1137 #endif 1126 1138 state().m_appliedStrokePattern = true; … … 1159 1171 #elif PLATFORM(QT) 1160 1172 fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyFillPattern\n"); 1173 #elif PLATFORM(CAIRO) 1174 CanvasPattern* pattern = state().m_fillStyle->pattern(); 1175 if (!pattern) 1176 return; 1177 1178 cairo_t* cr = c->platformContext(); 1179 cairo_matrix_t m; 1180 cairo_get_matrix(cr, &m); 1181 1182 cairo_pattern_t* platformPattern = pattern->createPattern(m); 1183 if (!platformPattern) 1184 return; 1185 1186 cairo_set_source(cr, platformPattern); 1187 cairo_pattern_destroy(platformPattern); 1161 1188 #endif 1162 1189 state().m_appliedFillPattern = true; -
trunk/WebCore/platform/graphics/Image.h
r28871 r28971 112 112 113 113 enum TileRule { StretchTile, RoundTile, RepeatTile }; 114 115 virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; } 114 116 115 117 #if PLATFORM(MAC) … … 147 149 virtual Color solidColor() const { return Color(); } 148 150 149 virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; }150 151 151 virtual void startAnimation() { } 152 152
Note: See TracChangeset
for help on using the changeset viewer.