Show
Ignore:
Timestamp:
04/23/07 07:16:40 (21 months ago)
Author:
bdash
Message:

2007-04-23 Alp Toker <alp@atoker.com>

Reviewed by Mark.

Further implementation and checks. The opacity layer code is not so beautiful
but gets the job done with fewer complications than maintaining our own stack.

  • platform/graphics/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContext::translate): (WebCore::GraphicsContext::setPlatformStrokeThickness): (WebCore::GraphicsContext::beginTransparencyLayer): (WebCore::GraphicsContext::endTransparencyLayer): (WebCore::GraphicsContext::setCompositeOperation): (WebCore::GraphicsContext::rotate): (WebCore::GraphicsContext::scale):
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r21022 r21035  
    6666 
    6767    cairo_t* context; 
     68    cairo_user_data_key_t opacityKey; 
    6869}; 
    6970 
     
    469470void GraphicsContext::translate(float x, float y) 
    470471{ 
     472    if (paintingDisabled()) 
     473        return; 
    471474    cairo_t* context = m_data->context; 
    472475    cairo_translate(context, x, y); 
     
    495498void GraphicsContext::setPlatformStrokeThickness(float strokeThickness) 
    496499{ 
     500    if (paintingDisabled()) 
     501        return; 
    497502    cairo_set_line_width(m_data->context, strokeThickness); 
    498503} 
     
    565570} 
    566571 
    567 void GraphicsContext::beginTransparencyLayer(float) 
    568 { 
    569     notImplemented(); 
     572void GraphicsContext::beginTransparencyLayer(float opacity) 
     573{ 
     574    if (paintingDisabled()) 
     575        return; 
     576 
     577    ASSERT(opacity >= 0 && opacity <= 1); 
     578 
     579    cairo_t* context = m_data->context; 
     580    cairo_push_group(context); 
     581    // We insert the opacity into a Cairo surface data slot. 
     582    // Rather than passing a pointer, we store the opacity value directly. 
     583    void* odata = reinterpret_cast<void*>(static_cast<unsigned int>(opacity * UINT_MAX)); 
     584    cairo_surface_set_user_data(cairo_get_target(context), &m_data->opacityKey, odata, NULL); 
    570585} 
    571586 
    572587void GraphicsContext::endTransparencyLayer() 
    573588{ 
    574     notImplemented(); 
     589    if (paintingDisabled()) 
     590        return; 
     591 
     592    cairo_t* context = m_data->context; 
     593    void* odata = cairo_surface_get_user_data(cairo_get_target(context), &m_data->opacityKey); 
     594    float opacity = static_cast<float>(reinterpret_cast<unsigned int>(odata)) / UINT_MAX; 
     595 
     596    ASSERT(opacity >= 0 && opacity <= 1); 
     597 
     598    cairo_pop_group_to_source(context); 
     599    cairo_paint_with_alpha(context, opacity); 
    575600} 
    576601 
     
    675700void GraphicsContext::setCompositeOperation(CompositeOperator op) 
    676701{ 
     702    if (paintingDisabled()) 
     703        return; 
    677704    cairo_set_operator(m_data->context, toCairoOperator(op)); 
    678705} 
     
    683710} 
    684711 
    685 void GraphicsContext::rotate(float) 
    686 { 
    687     notImplemented(); 
    688 } 
    689  
    690 void GraphicsContext::scale(const FloatSize&) 
    691 { 
    692     notImplemented(); 
     712void GraphicsContext::rotate(float angle) 
     713{ 
     714    if (paintingDisabled()) 
     715        return; 
     716    cairo_rotate(m_data->context, angle); 
     717} 
     718 
     719void GraphicsContext::scale(const FloatSize& size) 
     720{ 
     721    if (paintingDisabled()) 
     722        return; 
     723    cairo_scale(m_data->context, size.width(), size.height()); 
    693724} 
    694725