2007-04-23 Alp Toker <alp@atoker.com>
authorbdash <bdash@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Apr 2007 14:16:40 +0000 (14:16 +0000)
committerbdash <bdash@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Apr 2007 14:16:40 +0000 (14:16 +0000)
        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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@21035 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

index ec5adf3..9e0fa56 100644 (file)
@@ -1,3 +1,19 @@
+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):
+
 2007-04-23  Darin Adler  <darin@apple.com>
 
         Reviewed by Hyatt.
index 4436cdf..702eddb 100644 (file)
@@ -65,6 +65,7 @@ public:
     ~GraphicsContextPlatformPrivate();
 
     cairo_t* context;
+    cairo_user_data_key_t opacityKey;
 };
 
 static inline void setColor(cairo_t* cr, const Color& col)
@@ -468,6 +469,8 @@ FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect)
 
 void GraphicsContext::translate(float x, float y)
 {
+    if (paintingDisabled())
+        return;
     cairo_t* context = m_data->context;
     cairo_translate(context, x, y);
 }
@@ -494,6 +497,8 @@ void GraphicsContext::setPlatformStrokeColor(const Color& col)
 
 void GraphicsContext::setPlatformStrokeThickness(float strokeThickness)
 {
+    if (paintingDisabled())
+        return;
     cairo_set_line_width(m_data->context, strokeThickness);
 }
 
@@ -564,14 +569,34 @@ void GraphicsContext::clearShadow()
     notImplemented();
 }
 
-void GraphicsContext::beginTransparencyLayer(float)
+void GraphicsContext::beginTransparencyLayer(float opacity)
 {
-    notImplemented();
+    if (paintingDisabled())
+        return;
+
+    ASSERT(opacity >= 0 && opacity <= 1);
+
+    cairo_t* context = m_data->context;
+    cairo_push_group(context);
+    // We insert the opacity into a Cairo surface data slot.
+    // Rather than passing a pointer, we store the opacity value directly.
+    void* odata = reinterpret_cast<void*>(static_cast<unsigned int>(opacity * UINT_MAX));
+    cairo_surface_set_user_data(cairo_get_target(context), &m_data->opacityKey, odata, NULL);
 }
 
 void GraphicsContext::endTransparencyLayer()
 {
-    notImplemented();
+    if (paintingDisabled())
+        return;
+
+    cairo_t* context = m_data->context;
+    void* odata = cairo_surface_get_user_data(cairo_get_target(context), &m_data->opacityKey);
+    float opacity = static_cast<float>(reinterpret_cast<unsigned int>(odata)) / UINT_MAX;
+
+    ASSERT(opacity >= 0 && opacity <= 1);
+
+    cairo_pop_group_to_source(context);
+    cairo_paint_with_alpha(context, opacity);
 }
 
 void GraphicsContext::clearRect(const FloatRect&)
@@ -674,6 +699,8 @@ static inline cairo_operator_t toCairoOperator(CompositeOperator op)
 
 void GraphicsContext::setCompositeOperation(CompositeOperator op)
 {
+    if (paintingDisabled())
+        return;
     cairo_set_operator(m_data->context, toCairoOperator(op));
 }
 
@@ -682,14 +709,18 @@ void GraphicsContext::clip(const Path&)
     notImplemented();
 }
 
-void GraphicsContext::rotate(float)
+void GraphicsContext::rotate(float angle)
 {
-    notImplemented();
+    if (paintingDisabled())
+        return;
+    cairo_rotate(m_data->context, angle);
 }
 
-void GraphicsContext::scale(const FloatSize&)
+void GraphicsContext::scale(const FloatSize& size)
 {
-    notImplemented();
+    if (paintingDisabled())
+        return;
+    cairo_scale(m_data->context, size.width(), size.height());
 }
 
 void GraphicsContext::clipOut(const IntRect&)