Changeset 83044 in webkit
- Timestamp:
- Apr 6, 2011 7:16:03 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r83043 r83044 1 2011-04-06 Martin Robinson <mrobinson@igalia.com> 2 3 Reviewed by Xan Lopez. 4 5 [Cairo] Hide the details of image masking in PlatformContextCairo 6 https://bugs.webkit.org/show_bug.cgi?id=57878 7 8 No new tests. This is just a refactor. 9 10 * platform/graphics/GraphicsContext.h: 11 * platform/graphics/cairo/GraphicsContextCairo.cpp: 12 (WebCore::GraphicsContext::savePlatformState): Call into PlatformContextCairo now to 13 do the actual cairo_save. Remove information about image masking. 14 (WebCore::GraphicsContext::restorePlatformState): Call into PlatformContextCairo now to 15 do the actual cairo_restore. Remove information about image masking. 16 * platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h: 17 * platform/graphics/cairo/ImageBufferCairo.cpp: 18 (WebCore::ImageBuffer::clip): Use PlatformContextCairo here now. 19 * platform/graphics/cairo/PlatformContextCairo.cpp: 20 (WebCore::PlatformContextCairo::restore): Added. 21 (WebCore::PlatformContextCairo::save): Added. 22 (WebCore::PlatformContextCairo::pushImageMask): Added. 23 * platform/graphics/cairo/PlatformContextCairo.h: 24 (WebCore::ImageMaskInformation::update): Moved from GraphicsContextPlatformPrivateCairo.h. 25 (WebCore::ImageMaskInformation::isValid): Ditto. 26 (WebCore::ImageMaskInformation::maskSurface): Ditto. 27 (WebCore::ImageMaskInformation::maskRect): Ditto. 28 1 29 2011-04-02 Diego Gonzalez <diegohcg@webkit.org> 2 30 -
trunk/Source/WebCore/platform/graphics/GraphicsContext.h
r82962 r83044 493 493 #if PLATFORM(CAIRO) 494 494 GraphicsContext(cairo_t*); 495 void pushImageMask(cairo_surface_t*, const FloatRect&);496 495 #endif 497 496 -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
r82962 r83044 236 236 void GraphicsContext::savePlatformState() 237 237 { 238 cairo_save(platformContext()->cr());238 platformContext()->save(); 239 239 m_data->save(); 240 240 m_data->shadowStack.append(m_data->shadow); 241 m_data->maskImageStack.append(ImageMaskInformation());242 241 } 243 242 244 243 void GraphicsContext::restorePlatformState() 245 244 { 246 cairo_t* cr = platformContext()->cr();247 248 const ImageMaskInformation& maskInformation = m_data->maskImageStack.last();249 if (maskInformation.isValid()) {250 const FloatRect& maskRect = maskInformation.maskRect();251 cairo_pop_group_to_source(cr);252 cairo_mask_surface(cr, maskInformation.maskSurface(), maskRect.x(), maskRect.y());253 }254 m_data->maskImageStack.removeLast();255 256 245 if (m_data->shadowStack.isEmpty()) 257 246 m_data->shadow = ContextShadow(); … … 261 250 } 262 251 263 cairo_restore(cr);252 platformContext()->restore(); 264 253 m_data->restore(); 265 254 } … … 1192 1181 } 1193 1182 1194 void GraphicsContext::pushImageMask(cairo_surface_t* surface, const FloatRect& rect)1195 {1196 // We must call savePlatformState at least once before we can use image masking,1197 // since we actually apply the mask in restorePlatformState.1198 ASSERT(!m_data->maskImageStack.isEmpty());1199 m_data->maskImageStack.last().update(surface, rect);1200 1201 // Cairo doesn't support the notion of an image clip, so we push a group here1202 // and then paint it to the surface with an image mask (which is an immediate1203 // operation) during restorePlatformState.1204 1205 // We want to allow the clipped elements to composite with the surface as it1206 // is now, but they are isolated in another group. To make this work, we're1207 // going to blit the current surface contents onto the new group once we push it.1208 cairo_t* cr = platformContext()->cr();1209 cairo_surface_t* currentTarget = cairo_get_target(cr);1210 cairo_surface_flush(currentTarget);1211 1212 // Pushing a new group ensures that only things painted after this point are clipped.1213 cairo_push_group(cr);1214 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);1215 1216 cairo_set_source_surface(cr, currentTarget, 0, 0);1217 cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());1218 cairo_fill(cr);1219 }1220 1221 1183 } // namespace WebCore 1222 1184 -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
r82962 r83044 47 47 48 48 namespace WebCore { 49 50 // In Cairo image masking is immediate, so to emulate image clipping we must save masking51 // details as part of the context state and apply it during platform restore.52 class ImageMaskInformation {53 public:54 void update(cairo_surface_t* maskSurface, const FloatRect& maskRect)55 {56 m_maskSurface = maskSurface;57 m_maskRect = maskRect;58 }59 60 bool isValid() const { return m_maskSurface; }61 cairo_surface_t* maskSurface() const { return m_maskSurface.get(); }62 const FloatRect& maskRect() const { return m_maskRect; }63 64 private:65 RefPtr<cairo_surface_t> m_maskSurface;66 FloatRect m_maskRect;67 };68 49 69 50 class GraphicsContextPlatformPrivate { … … 122 103 ContextShadow shadow; 123 104 Vector<ContextShadow> shadowStack; 124 Vector<ImageMaskInformation> maskImageStack;125 105 126 106 #if PLATFORM(GTK) -
trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
r82962 r83044 118 118 void ImageBuffer::clip(GraphicsContext* context, const FloatRect& maskRect) const 119 119 { 120 context->p ushImageMask(m_data.m_surface, maskRect);120 context->platformContext()->pushImageMask(m_data.m_surface, maskRect); 121 121 } 122 122 -
trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp
r82962 r83044 36 36 } 37 37 38 void PlatformContextCairo::restore() 39 { 40 const ImageMaskInformation& maskInformation = m_maskImageStack.last(); 41 if (maskInformation.isValid()) { 42 const FloatRect& maskRect = maskInformation.maskRect(); 43 cairo_pop_group_to_source(m_cr.get()); 44 cairo_mask_surface(m_cr.get(), maskInformation.maskSurface(), maskRect.x(), maskRect.y()); 45 } 46 m_maskImageStack.removeLast(); 47 48 cairo_restore(m_cr.get()); 49 } 50 51 void PlatformContextCairo::save() 52 { 53 m_maskImageStack.append(ImageMaskInformation()); 54 55 cairo_save(m_cr.get()); 56 } 57 58 void PlatformContextCairo::pushImageMask(cairo_surface_t* surface, const FloatRect& rect) 59 { 60 // We must call savePlatformState at least once before we can use image masking, 61 // since we actually apply the mask in restorePlatformState. 62 ASSERT(!m_data->maskImageStack.isEmpty()); 63 m_maskImageStack.last().update(surface, rect); 64 65 // Cairo doesn't support the notion of an image clip, so we push a group here 66 // and then paint it to the surface with an image mask (which is an immediate 67 // operation) during restorePlatformState. 68 69 // We want to allow the clipped elements to composite with the surface as it 70 // is now, but they are isolated in another group. To make this work, we're 71 // going to blit the current surface contents onto the new group once we push it. 72 cairo_surface_t* currentTarget = cairo_get_target(m_cr.get()); 73 cairo_surface_flush(currentTarget); 74 75 // Pushing a new group ensures that only things painted after this point are clipped. 76 cairo_push_group(m_cr.get()); 77 cairo_set_operator(m_cr.get(), CAIRO_OPERATOR_SOURCE); 78 79 cairo_set_source_surface(m_cr.get(), currentTarget, 0, 0); 80 cairo_rectangle(m_cr.get(), rect.x(), rect.y(), rect.width(), rect.height()); 81 cairo_fill(m_cr.get()); 82 } 83 84 38 85 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h
r82962 r83044 32 32 namespace WebCore { 33 33 34 // In Cairo image masking is immediate, so to emulate image clipping we must save masking 35 // details as part of the context state and apply them during platform restore. 36 class ImageMaskInformation { 37 public: 38 void update(cairo_surface_t* maskSurface, const FloatRect& maskRect) 39 { 40 m_maskSurface = maskSurface; 41 m_maskRect = maskRect; 42 } 43 44 bool isValid() const { return m_maskSurface; } 45 cairo_surface_t* maskSurface() const { return m_maskSurface.get(); } 46 const FloatRect& maskRect() const { return m_maskRect; } 47 48 private: 49 RefPtr<cairo_surface_t> m_maskSurface; 50 FloatRect m_maskRect; 51 }; 52 34 53 // Much like PlatformContextSkia in the Skia port, this class holds information that 35 54 // would normally be private to GraphicsContext, except that we want to allow access … … 41 60 public: 42 61 PlatformContextCairo(cairo_t*); 62 43 63 cairo_t* cr() { return m_cr.get(); } 44 64 void setCr(cairo_t* cr) { m_cr = cr; } 45 65 66 void save(); 67 void restore(); 68 void pushImageMask(cairo_surface_t*, const FloatRect&); 69 46 70 private: 47 71 RefPtr<cairo_t> m_cr; 72 Vector<ImageMaskInformation> m_maskImageStack; 48 73 }; 49 74
Note: See TracChangeset
for help on using the changeset viewer.