Changeset 87336 in webkit
- Timestamp:
- May 25, 2011 4:54:02 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r87335 r87336 1 2011-05-25 Martin Robinson <mrobinson@igalia.com> 2 3 Reviewed by Dirk Schulze. 4 5 [Cairo] Move the global alpha property from GraphicsContext to PlatformContextCairo 6 https://bugs.webkit.org/show_bug.cgi?id=60185 7 8 Remove Cairo #ifdefs from GraphicsContext.h by pushing the global alpha 9 state into PlatformContextCairo. Since Cairo is the only platform that needs 10 to store this, this is the proper place for it. Change the image mask stack into 11 a more generic state stack that can keep track of the multiple bits of platform 12 specific state and properly handle save/restore pairs. 13 14 No new tests. This is just a code refactor. 15 16 * platform/graphics/GraphicsContext.h: Remove Cairo #ifdefs. 17 (WebCore::GraphicsContextState::GraphicsContextState): Ditto. 18 * platform/graphics/cairo/ContextShadowCairo.cpp: Access global alpha from PlatformContextCairo now. 19 (WebCore::ContextShadow::drawRectShadow): 20 * platform/graphics/cairo/FontCairo.cpp: Ditto. 21 (WebCore::Font::drawGlyphs): 22 * platform/graphics/cairo/GraphicsContextCairo.cpp: 23 (WebCore::setPlatformFill): Ditto. 24 (WebCore::setPlatformStroke): Ditto. 25 (WebCore::GraphicsContext::setAlpha): Ditto. 26 * platform/graphics/cairo/PlatformContextCairo.cpp: Moved ImageMaskInformation class from the 27 header file, since it can be private now. Abstract the image mask state and the global alpha 28 in a generic State class. 29 (WebCore::ImageMaskInformation::update): 30 (WebCore::ImageMaskInformation::isValid): 31 (WebCore::ImageMaskInformation::maskSurface): 32 (WebCore::ImageMaskInformation::maskRect): 33 (WebCore::PlatformContextCairo::State::State): Added. 34 (WebCore::PlatformContextCairo::PlatformContextCairo): Intialize the state 35 class when this class is constructed. 36 (WebCore::PlatformContextCairo::restore): Now pop the last state off the state stack. 37 (WebCore::PlatformContextCairo::~PlatformContextCairo): Added this so that we can forward 38 declare the State class in the header. 39 (WebCore::PlatformContextCairo::save): Push a new state onto the stack. 40 (WebCore::PlatformContextCairo::pushImageMask): Operate on the state stack now. 41 (WebCore::PlatformContextCairo::globalAlpha): Added. 42 (WebCore::PlatformContextCairo::setGlobalAlpha): Added. 43 (WebCore::PlatformContextCairo::drawSurfaceToContext: Call globalAlpha(). 44 * platform/graphics/cairo/PlatformContextCairo.h: Changed the image mask stack 45 into a more generic state stack, much like PlatformContextChromium. 46 1 47 2011-05-25 Mark Rowe <mrowe@apple.com> 2 48 -
trunk/Source/WebCore/platform/graphics/GraphicsContext.h
r85419 r87336 155 155 : strokeThickness(0) 156 156 , shadowBlur(0) 157 #if USE(CAIRO)158 , globalAlpha(1)159 #endif160 157 , textDrawingMode(TextModeFill) 161 158 , strokeColor(Color::black) … … 190 187 float shadowBlur; 191 188 192 #if USE(CAIRO)193 float globalAlpha;194 #endif195 189 TextDrawingModeFlags textDrawingMode; 196 190 … … 391 385 392 386 void setAlpha(float); 393 #if USE(CAIRO)394 float getAlpha();395 #endif396 387 397 388 void setCompositeOperation(CompositeOperator); -
trunk/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp
r83932 r87336 200 200 201 201 cairo_t* cr = context->platformContext()->cr(); 202 float globalAlpha = context->platformContext()->globalAlpha(); 202 203 203 204 // drawShadowedRect still does not work with rotations. … … 205 206 if ((!context->getCTM().isIdentityOrTranslationOrFlipped()) || (internalShadowWidth > rect.width()) 206 207 || (internalShadowHeight > rect.height()) || (m_type != BlurShadow)) { 207 drawRectShadowWithoutTiling(context, rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius, context->getAlpha());208 drawRectShadowWithoutTiling(context, rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius, globalAlpha); 208 209 return; 209 210 } … … 230 231 231 232 if ((shadowTemplateSize.width() * shadowTemplateSize.height() > m_sourceRect.width() * m_sourceRect.height())) { 232 drawRectShadowWithoutTiling(context, rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius, context->getAlpha());233 drawRectShadowWithoutTiling(context, rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius, globalAlpha); 233 234 return; 234 235 } … … 252 253 appendWebCorePathToCairoContext(m_layerContext, path); 253 254 254 cairo_set_source_rgba(m_layerContext, 0, 0, 0, context->getAlpha());255 cairo_set_source_rgba(m_layerContext, 0, 0, 0, globalAlpha); 255 256 cairo_fill(m_layerContext); 256 257 -
trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp
r82962 r87336 114 114 cairo_t* cr = platformContext->cr(); 115 115 cairo_save(cr); 116 117 float globalAlpha = platformContext->globalAlpha(); 118 116 119 prepareContextForGlyphDrawing(cr, font, point); 117 120 if (context->textDrawingMode() & TextModeFill) { 118 121 if (context->fillGradient()) { 119 122 cairo_set_source(cr, context->fillGradient()->platformGradient()); 120 if ( context->getAlpha() < 1.0f) {123 if (globalAlpha < 1) { 121 124 cairo_push_group(cr); 122 cairo_paint_with_alpha(cr, context->getAlpha());125 cairo_paint_with_alpha(cr, globalAlpha); 123 126 cairo_pop_group_to_source(cr); 124 127 } … … 127 130 cairo_pattern_t* pattern = context->fillPattern()->createPlatformPattern(affine); 128 131 cairo_set_source(cr, pattern); 129 if ( context->getAlpha() < 1.0f) {132 if (globalAlpha < 1) { 130 133 cairo_push_group(cr); 131 cairo_paint_with_alpha(cr, context->getAlpha());134 cairo_paint_with_alpha(cr, globalAlpha); 132 135 cairo_pop_group_to_source(cr); 133 136 } … … 136 139 float red, green, blue, alpha; 137 140 context->fillColor().getRGBA(red, green, blue, alpha); 138 cairo_set_source_rgba(cr, red, green, blue, alpha * context->getAlpha());141 cairo_set_source_rgba(cr, red, green, blue, alpha * globalAlpha); 139 142 } 140 143 drawGlyphsToContext(cr, font, glyphs, numGlyphs); … … 148 151 if (context->strokeGradient()) { 149 152 cairo_set_source(cr, context->strokeGradient()->platformGradient()); 150 if ( context->getAlpha() < 1.0f) {153 if (globalAlpha < 1) { 151 154 cairo_push_group(cr); 152 cairo_paint_with_alpha(cr, context->getAlpha());155 cairo_paint_with_alpha(cr, globalAlpha); 153 156 cairo_pop_group_to_source(cr); 154 157 } … … 157 160 cairo_pattern_t* pattern = context->strokePattern()->createPlatformPattern(affine); 158 161 cairo_set_source(cr, pattern); 159 if ( context->getAlpha() < 1.0f) {162 if (globalAlpha < 1) { 160 163 cairo_push_group(cr); 161 cairo_paint_with_alpha(cr, context->getAlpha());164 cairo_paint_with_alpha(cr, globalAlpha); 162 165 cairo_pop_group_to_source(cr); 163 166 } … … 166 169 float red, green, blue, alpha; 167 170 context->strokeColor().getRGBA(red, green, blue, alpha); 168 cairo_set_source_rgba(cr, red, green, blue, alpha * context->getAlpha());171 cairo_set_source_rgba(cr, red, green, blue, alpha * globalAlpha); 169 172 } 170 173 cairo_glyph_path(cr, glyphs, numGlyphs); -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
r87151 r87336 86 86 setSourceRGBAFromColor(cr, context->fillColor()); 87 87 cairo_clip_preserve(cr); 88 cairo_paint_with_alpha(cr, state.globalAlpha);88 cairo_paint_with_alpha(cr, context->platformContext()->globalAlpha()); 89 89 cairo_restore(cr); 90 90 if (pattern) … … 94 94 static inline void setPlatformStroke(GraphicsContext* context, cairo_t* cr) 95 95 { 96 float globalAlpha = context->platformContext()->globalAlpha(); 96 97 cairo_pattern_t* pattern = 0; 97 98 cairo_save(cr); … … 105 106 cairo_set_source(cr, state.strokeGradient->platformGradient()); 106 107 else { 107 Color strokeColor = colorWithOverrideAlpha(context->strokeColor().rgb(), context->strokeColor().alpha() / 255.f * state.globalAlpha);108 Color strokeColor = colorWithOverrideAlpha(context->strokeColor().rgb(), context->strokeColor().alpha() / 255.f * globalAlpha); 108 109 setSourceRGBAFromColor(cr, strokeColor); 109 110 } 110 if ( state.globalAlpha < 1.0f && (state.strokePattern || state.strokeGradient)) {111 if (globalAlpha < 1.0f && (state.strokePattern || state.strokeGradient)) { 111 112 cairo_push_group(cr); 112 cairo_paint_with_alpha(cr, state.globalAlpha);113 cairo_paint_with_alpha(cr, globalAlpha); 113 114 cairo_pop_group_to_source(cr); 114 115 } … … 1011 1012 void GraphicsContext::setAlpha(float alpha) 1012 1013 { 1013 m_state.globalAlpha = alpha; 1014 } 1015 1016 float GraphicsContext::getAlpha() 1017 { 1018 return m_state.globalAlpha; 1014 platformContext()->setGlobalAlpha(alpha); 1019 1015 } 1020 1016 -
trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp
r87151 r87336 1 1 /* 2 2 * Copyright (C) 2011 Igalia S.L. 3 * Copyright (c) 2008, Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 32 33 namespace WebCore { 33 34 35 // In Cairo image masking is immediate, so to emulate image clipping we must save masking 36 // details as part of the context state and apply them during platform restore. 37 class ImageMaskInformation { 38 public: 39 void update(cairo_surface_t* maskSurface, const FloatRect& maskRect) 40 { 41 m_maskSurface = maskSurface; 42 m_maskRect = maskRect; 43 } 44 45 bool isValid() const { return m_maskSurface; } 46 cairo_surface_t* maskSurface() const { return m_maskSurface.get(); } 47 const FloatRect& maskRect() const { return m_maskRect; } 48 49 private: 50 RefPtr<cairo_surface_t> m_maskSurface; 51 FloatRect m_maskRect; 52 }; 53 54 55 // Encapsulates the additional painting state information we store for each 56 // pushed graphics state. 57 class PlatformContextCairo::State { 58 public: 59 State() 60 : m_globalAlpha(1) 61 { 62 } 63 64 State(const State& state) 65 : m_globalAlpha(state.m_globalAlpha) 66 { 67 // We do not copy m_imageMaskInformation because otherwise it would be applied 68 // more than once during subsequent calls to restore(). 69 } 70 71 ImageMaskInformation m_imageMaskInformation; 72 float m_globalAlpha; 73 }; 74 34 75 PlatformContextCairo::PlatformContextCairo(cairo_t* cr) 35 76 : m_cr(cr) 36 77 { 78 m_stateStack.append(State()); 79 m_state = &m_stateStack.last(); 37 80 } 38 81 39 82 void PlatformContextCairo::restore() 40 83 { 41 const ImageMaskInformation& maskInformation = m_ maskImageStack.last();84 const ImageMaskInformation& maskInformation = m_state->m_imageMaskInformation; 42 85 if (maskInformation.isValid()) { 43 86 const FloatRect& maskRect = maskInformation.maskRect(); … … 45 88 cairo_mask_surface(m_cr.get(), maskInformation.maskSurface(), maskRect.x(), maskRect.y()); 46 89 } 47 m_maskImageStack.removeLast(); 90 91 m_stateStack.removeLast(); 92 ASSERT(!m_stateStack.isEmpty()); 93 m_state = &m_stateStack.last(); 48 94 49 95 cairo_restore(m_cr.get()); 50 96 } 51 97 98 PlatformContextCairo::~PlatformContextCairo() 99 { 100 } 101 52 102 void PlatformContextCairo::save() 53 103 { 54 m_maskImageStack.append(ImageMaskInformation()); 104 m_stateStack.append(State(*m_state)); 105 m_state = &m_stateStack.last(); 55 106 56 107 cairo_save(m_cr.get()); … … 61 112 // We must call savePlatformState at least once before we can use image masking, 62 113 // since we actually apply the mask in restorePlatformState. 63 ASSERT(!m_ maskImageStack.isEmpty());64 m_ maskImageStack.last().update(surface, rect);114 ASSERT(!m_stateStack.isEmpty()); 115 m_state->m_imageMaskInformation.update(surface, rect); 65 116 66 117 // Cairo doesn't support the notion of an image clip, so we push a group here … … 128 179 129 180 cairo_save(m_cr.get()); 130 drawPatternToCairoContext(m_cr.get(), pattern.get(), destRect, context->getAlpha());181 drawPatternToCairoContext(m_cr.get(), pattern.get(), destRect, globalAlpha()); 131 182 cairo_restore(m_cr.get()); 132 183 } 133 184 185 float PlatformContextCairo::globalAlpha() const 186 { 187 return m_state->m_globalAlpha; 188 } 189 190 void PlatformContextCairo::setGlobalAlpha(float globalAlpha) 191 { 192 m_state->m_globalAlpha = globalAlpha; 193 } 134 194 135 195 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h
r87151 r87336 33 33 namespace WebCore { 34 34 35 // In Cairo image masking is immediate, so to emulate image clipping we must save masking36 // details as part of the context state and apply them during platform restore.37 class ImageMaskInformation {38 public:39 void update(cairo_surface_t* maskSurface, const FloatRect& maskRect)40 {41 m_maskSurface = maskSurface;42 m_maskRect = maskRect;43 }44 45 bool isValid() const { return m_maskSurface; }46 cairo_surface_t* maskSurface() const { return m_maskSurface.get(); }47 const FloatRect& maskRect() const { return m_maskRect; }48 49 private:50 RefPtr<cairo_surface_t> m_maskSurface;51 FloatRect m_maskRect;52 };53 54 35 // Much like PlatformContextSkia in the Skia port, this class holds information that 55 36 // would normally be private to GraphicsContext, except that we want to allow access … … 61 42 public: 62 43 PlatformContextCairo(cairo_t*); 44 ~PlatformContextCairo(); 63 45 64 46 cairo_t* cr() { return m_cr.get(); } … … 67 49 void save(); 68 50 void restore(); 51 void setGlobalAlpha(float); 52 float globalAlpha() const; 53 69 54 void pushImageMask(cairo_surface_t*, const FloatRect&); 70 55 void drawSurfaceToContext(cairo_surface_t*, const FloatRect& destRect, const FloatRect& srcRect, GraphicsContext*); … … 75 60 private: 76 61 RefPtr<cairo_t> m_cr; 77 Vector<ImageMaskInformation> m_maskImageStack; 62 63 class State; 64 State* m_state; 65 WTF::Vector<State> m_stateStack; 66 78 67 InterpolationQuality m_imageInterpolationQuality; 79 68 };
Note: See TracChangeset
for help on using the changeset viewer.