Title: [88469] trunk/Source/WebCore
Revision
88469
Author
[email protected]
Date
2011-06-09 11:51:46 -0700 (Thu, 09 Jun 2011)

Log Message

2011-06-09  Cary Clark  <[email protected]>

        Reviewed by Eric Seidel.

        Create local CG context for Mac UI elements when Skia is renderer
        https://bugs.webkit.org/show_bug.cgi?id=62213

        When building Mac Chrome using Skia as the WebKit renderer,
        add state to LocalCurrentGraphicsContext to convert the SkCanvas
        context passed by WebKit into the CGContext needed by UI
        rendering.

        No new tests.  The define typo in question is
        not yet enabled, so this change has no functional
        impact.

        * platform/mac/LocalCurrentGraphicsContext.h:
        Add SkiaBitLocker to create and release the converted CGContext.
        Add ContextContainer, a class for Skia to create and release
        the converted CGContext. If Skia is not used, the class has no effect.

        * platform/mac/LocalCurrentGraphicsContext.mm:
        (WebCore::LocalCurrentGraphicsContext::LocalCurrentGraphicsContext):
        When building with Skia, create the CGContext before passing it on.

        (WebCore::LocalCurrentGraphicsContext::cgContext):
        Get the CGContext from the SkiaBitLocker, or the saved context,
        as appropriate.

        * rendering/RenderThemeMac.mm:
        Get the CGContext from Skia conversion or native, as appropriate.
        Use the LocalCurrentGraphicsContext if there is one. Otherwise,
        add a ContextContainer to house the SkCanvas to CGContext conversion.

        (WebCore::RenderThemeMac::paintCapsLockIndicator):
        (WebCore::RenderThemeMac::paintProgressBar):
        (WebCore::RenderThemeMac::paintMenuListButtonGradients):
        (WebCore::RenderThemeMac::paintSliderTrack):
        (WebCore::RenderThemeMac::paintMediaFullscreenButton):
        (WebCore::RenderThemeMac::paintMediaMuteButton):
        (WebCore::RenderThemeMac::paintMediaPlayButton):
        (WebCore::RenderThemeMac::paintMediaSeekBackButton):
        (WebCore::RenderThemeMac::paintMediaSeekForwardButton):
        (WebCore::RenderThemeMac::paintMediaSliderTrack):
        (WebCore::RenderThemeMac::paintMediaSliderThumb):
        (WebCore::RenderThemeMac::paintMediaRewindButton):
        (WebCore::RenderThemeMac::paintMediaReturnToRealtimeButton):
        (WebCore::RenderThemeMac::paintMediaToggleClosedCaptionsButton):
        (WebCore::RenderThemeMac::paintMediaControlsBackground):
        (WebCore::RenderThemeMac::paintMediaCurrentTime):
        (WebCore::RenderThemeMac::paintMediaTimeRemaining):
        (WebCore::RenderThemeMac::paintMediaVolumeSliderContainer):
        (WebCore::RenderThemeMac::paintMediaVolumeSliderTrack):
        (WebCore::RenderThemeMac::paintMediaVolumeSliderThumb):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (88468 => 88469)


--- trunk/Source/WebCore/ChangeLog	2011-06-09 18:47:27 UTC (rev 88468)
+++ trunk/Source/WebCore/ChangeLog	2011-06-09 18:51:46 UTC (rev 88469)
@@ -1,3 +1,58 @@
+2011-06-09  Cary Clark  <[email protected]>
+
+        Reviewed by Eric Seidel.
+
+        Create local CG context for Mac UI elements when Skia is renderer
+        https://bugs.webkit.org/show_bug.cgi?id=62213
+
+        When building Mac Chrome using Skia as the WebKit renderer,
+        add state to LocalCurrentGraphicsContext to convert the SkCanvas
+        context passed by WebKit into the CGContext needed by UI
+        rendering.
+
+        No new tests.  The define typo in question is
+        not yet enabled, so this change has no functional
+        impact.
+
+        * platform/mac/LocalCurrentGraphicsContext.h:
+        Add SkiaBitLocker to create and release the converted CGContext.
+        Add ContextContainer, a class for Skia to create and release
+        the converted CGContext. If Skia is not used, the class has no effect.
+
+        * platform/mac/LocalCurrentGraphicsContext.mm:
+        (WebCore::LocalCurrentGraphicsContext::LocalCurrentGraphicsContext):
+        When building with Skia, create the CGContext before passing it on.
+
+        (WebCore::LocalCurrentGraphicsContext::cgContext):
+        Get the CGContext from the SkiaBitLocker, or the saved context,
+        as appropriate.
+
+        * rendering/RenderThemeMac.mm:
+        Get the CGContext from Skia conversion or native, as appropriate.
+        Use the LocalCurrentGraphicsContext if there is one. Otherwise,
+        add a ContextContainer to house the SkCanvas to CGContext conversion.
+
+        (WebCore::RenderThemeMac::paintCapsLockIndicator):
+        (WebCore::RenderThemeMac::paintProgressBar):
+        (WebCore::RenderThemeMac::paintMenuListButtonGradients):
+        (WebCore::RenderThemeMac::paintSliderTrack):
+        (WebCore::RenderThemeMac::paintMediaFullscreenButton):
+        (WebCore::RenderThemeMac::paintMediaMuteButton):
+        (WebCore::RenderThemeMac::paintMediaPlayButton):
+        (WebCore::RenderThemeMac::paintMediaSeekBackButton):
+        (WebCore::RenderThemeMac::paintMediaSeekForwardButton):
+        (WebCore::RenderThemeMac::paintMediaSliderTrack):
+        (WebCore::RenderThemeMac::paintMediaSliderThumb):
+        (WebCore::RenderThemeMac::paintMediaRewindButton):
+        (WebCore::RenderThemeMac::paintMediaReturnToRealtimeButton):
+        (WebCore::RenderThemeMac::paintMediaToggleClosedCaptionsButton):
+        (WebCore::RenderThemeMac::paintMediaControlsBackground):
+        (WebCore::RenderThemeMac::paintMediaCurrentTime):
+        (WebCore::RenderThemeMac::paintMediaTimeRemaining):
+        (WebCore::RenderThemeMac::paintMediaVolumeSliderContainer):
+        (WebCore::RenderThemeMac::paintMediaVolumeSliderTrack):
+        (WebCore::RenderThemeMac::paintMediaVolumeSliderThumb):
+
 2011-06-02  Jer Noble  <[email protected]>
 
         Reviewed by Maciej Stachowiak.

Modified: trunk/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.h (88468 => 88469)


--- trunk/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.h	2011-06-09 18:47:27 UTC (rev 88468)
+++ trunk/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.h	2011-06-09 18:51:46 UTC (rev 88469)
@@ -17,8 +17,13 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#include "GraphicsContext.h"
 #include <wtf/Noncopyable.h>
 
+#if USE(SKIA)
+#include "skia/ext/skia_utils_mac.h"
+#endif
+
 #ifdef __OBJC__
 @class NSGraphicsContext;
 #else
@@ -27,8 +32,6 @@
 
 namespace WebCore {
 
-class GraphicsContext;
-    
 // This class automatically saves and restores the current NSGraphicsContext for
 // functions which call out into AppKit and rely on the currentContext being set
 class LocalCurrentGraphicsContext {
@@ -36,10 +39,38 @@
 public:
     LocalCurrentGraphicsContext(GraphicsContext* graphicsContext);
     ~LocalCurrentGraphicsContext();
-
+    CGContextRef cgContext();
 private:
     GraphicsContext* m_savedGraphicsContext;
     NSGraphicsContext* m_savedNSGraphicsContext;
+#if USE(SKIA)
+    gfx::SkiaBitLocker m_skiaBitLocker;
+#endif
 };
 
+class ContextContainer {
+    WTF_MAKE_NONCOPYABLE(ContextContainer);
+public:
+#if USE(SKIA)
+    ContextContainer(GraphicsContext*);
+    
+    // This synchronizes the CGContext to reflect the current SkCanvas state.
+    // The implementation may not return the same CGContext each time.
+    CGContextRef context() { return m_skiaBitLocker.cgContext(); }
+#else
+    ContextContainer(GraphicsContext* graphicsContext)
+        : m_graphicsContext(graphicsContext->platformContext())
+    {
+    }
+
+    CGContextRef context() { return m_graphicsContext; }
+#endif
+private:
+#if USE(SKIA)
+    gfx::SkiaBitLocker m_skiaBitLocker;
+#else
+    PlatformGraphicsContext* m_graphicsContext;
+#endif
+};
+
 }

Modified: trunk/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.mm (88468 => 88469)


--- trunk/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.mm	2011-06-09 18:47:27 UTC (rev 88468)
+++ trunk/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.mm	2011-06-09 18:51:46 UTC (rev 88469)
@@ -20,23 +20,31 @@
 #include "config.h"
 #include "LocalCurrentGraphicsContext.h"
 
-#include "GraphicsContext.h"
 #include <AppKit/NSGraphicsContext.h>
 
+#if USE(SKIA)
+#include "platform_canvas.h"
+#include "PlatformContextSkia.h"
+#endif
+
 namespace WebCore {
 
 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext* graphicsContext)
+#if USE(SKIA)
+    : m_skiaBitLocker(graphicsContext->platformContext()->canvas())
+#endif
 {
     m_savedGraphicsContext = graphicsContext;
     graphicsContext->save();
-    
-    if (graphicsContext->platformContext() == [[NSGraphicsContext currentContext] graphicsPort]) {
+
+    CGContextRef cgContext = this->cgContext();
+    if (cgContext == [[NSGraphicsContext currentContext] graphicsPort]) {
         m_savedNSGraphicsContext = 0;
         return;
     }
     
     m_savedNSGraphicsContext = [[NSGraphicsContext currentContext] retain];
-    NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphicsPort:graphicsContext->platformContext() flipped:YES];
+    NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES];
     [NSGraphicsContext setCurrentContext:newContext];
 }
 
@@ -50,4 +58,23 @@
     }
 }
 
+CGContextRef LocalCurrentGraphicsContext::cgContext()
+{
+#if USE(SKIA)
+    // This synchronizes the CGContext to reflect the current SkCanvas state.
+    // The implementation may not return the same CGContext each time.
+    CGContextRef cgContext = m_skiaBitLocker.cgContext();
+#else
+    CGContextRef cgContext = m_savedGraphicsContext->platformContext();
+#endif
+    return cgContext;
 }
+
+#if USE(SKIA)
+ContextContainer::ContextContainer(GraphicsContext* graphicsContext) 
+    : m_skiaBitLocker(graphicsContext->platformContext()->canvas())
+{
+}
+#endif
+
+}

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (88468 => 88469)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2011-06-09 18:47:27 UTC (rev 88468)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2011-06-09 18:51:46 UTC (rev 88469)
@@ -721,7 +721,7 @@
         return true;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawCapsLockIndicator(paintInfo.context->platformContext(), r);
+    wkDrawCapsLockIndicator(localContext.cgContext(), r);
     
     return false;
 }
@@ -944,7 +944,9 @@
     if (!imageBuffer)
         return true;
 
-    HIThemeDrawTrack(&trackInfo, 0, imageBuffer->context()->platformContext(), kHIThemeOrientationNormal);
+    ContextContainer cgContextContainer(imageBuffer->context());
+    CGContextRef cgContext = cgContextContainer.context();
+    HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal);
 
     GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
@@ -1015,7 +1017,8 @@
     if (r.isEmpty())
         return;
 
-    CGContextRef context = paintInfo.context->platformContext();
+    ContextContainer cgContextContainer(paintInfo.context);
+    CGContextRef context = cgContextContainer.context();
 
     GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
@@ -1046,6 +1049,7 @@
         GraphicsContextStateSaver stateSaver(*paintInfo.context);
         CGContextClipToRect(context, r);
         paintInfo.context->addRoundedRectClip(border);
+        context = cgContextContainer.context();
         CGContextDrawShading(context, mainShading.get());
     }
     
@@ -1053,6 +1057,7 @@
         GraphicsContextStateSaver stateSaver(*paintInfo.context);
         CGContextClipToRect(context, topGradient);
         paintInfo.context->addRoundedRectClip(RoundedIntRect(enclosingIntRect(topGradient), border.radii().topLeft(), border.radii().topRight(), IntSize(), IntSize()));
+        context = cgContextContainer.context();
         CGContextDrawShading(context, topShading.get());
     }
     
@@ -1060,6 +1065,7 @@
         GraphicsContextStateSaver stateSaver(*paintInfo.context);
         CGContextClipToRect(context, bottomGradient);
         paintInfo.context->addRoundedRectClip(RoundedIntRect(enclosingIntRect(bottomGradient), IntSize(), IntSize(), border.radii().bottomLeft(), border.radii().bottomRight()));
+        context = cgContextContainer.context();
         CGContextDrawShading(context, bottomShading.get());
     }
 
@@ -1067,6 +1073,7 @@
         GraphicsContextStateSaver stateSaver(*paintInfo.context);
         CGContextClipToRect(context, r);
         paintInfo.context->addRoundedRectClip(border);
+        context = cgContextContainer.context();
         CGContextDrawShading(context, leftShading.get());
         CGContextDrawShading(context, rightShading.get());
     }
@@ -1268,7 +1275,7 @@
     }
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    CGContextRef context = paintInfo.context->platformContext();
+    CGContextRef context = localContext.cgContext();
     CGColorSpaceRef cspace = deviceRGBColorSpaceRef();
 
     GraphicsContextStateSaver stateSaver(*paintInfo.context);
@@ -1284,6 +1291,7 @@
 
     IntSize radius(trackRadius, trackRadius);
     paintInfo.context->addRoundedRectClip(RoundedIntRect(bounds, radius, radius, radius, radius));
+    context = localContext.cgContext();
     CGContextDrawShading(context, mainShading.get());
     
     return false;
@@ -1719,7 +1727,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaFullscreenButton, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaFullscreenButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1732,7 +1740,7 @@
 
     if (MediaControlMuteButtonElement* btn = static_cast<MediaControlMuteButtonElement*>(node)) {
         LocalCurrentGraphicsContext localContext(paintInfo.context);
-        wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+        wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
 
     }
     return false;
@@ -1747,7 +1755,7 @@
 
     if (MediaControlPlayButtonElement* btn = static_cast<MediaControlPlayButtonElement*>(node)) {
         LocalCurrentGraphicsContext localContext(paintInfo.context);
-        wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+        wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     }
     return false;
 }
@@ -1759,7 +1767,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaSeekBackButton, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaSeekBackButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1770,7 +1778,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaSeekForwardButton, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaSeekForwardButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1793,9 +1801,11 @@
     if (isnan(duration))
         duration = 0;
  
+    ContextContainer cgContextContainer(paintInfo.context);
+    CGContextRef context = cgContextContainer.context();
     GraphicsContextStateSaver stateSaver(*paintInfo.context);
     FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
-    wkDrawMediaSliderTrack(mediaControllerTheme(), paintInfo.context->platformContext(), unzoomedRect, 
+    wkDrawMediaSliderTrack(mediaControllerTheme(), context, unzoomedRect, 
         timeLoaded, currentTime, duration, getMediaUIPartStateFlags(node));
     return false;
 }
@@ -1807,7 +1817,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaSliderThumb, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaSliderThumb, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
     
@@ -1818,7 +1828,7 @@
         return false;
     
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaRewindButton, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaRewindButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1829,7 +1839,7 @@
         return false;
     
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaReturnToRealtimeButton, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaReturnToRealtimeButton, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1844,7 +1854,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(btn->displayType(), mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
 
     return false;
 }
@@ -1856,7 +1866,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaTimelineContainer, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaTimelineContainer, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1866,9 +1876,10 @@
     if (!node)
         return false;
 
+    ContextContainer cgContextContainer(paintInfo.context);
     GraphicsContextStateSaver stateSaver(*paintInfo.context);
     FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
-    wkDrawMediaUIPart(MediaCurrentTimeDisplay, mediaControllerTheme(), paintInfo.context->platformContext(), unzoomedRect, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaCurrentTimeDisplay, mediaControllerTheme(), cgContextContainer.context(), unzoomedRect, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1878,9 +1889,10 @@
     if (!node)
         return false;
 
+    ContextContainer cgContextContainer(paintInfo.context);
     GraphicsContextStateSaver stateSaver(*paintInfo.context);
     FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
-    wkDrawMediaUIPart(MediaTimeRemainingDisplay, mediaControllerTheme(), paintInfo.context->platformContext(), unzoomedRect, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaTimeRemainingDisplay, mediaControllerTheme(), cgContextContainer.context(), unzoomedRect, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1891,7 +1903,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaVolumeSliderContainer, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaVolumeSliderContainer, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
 
@@ -1902,7 +1914,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaVolumeSlider, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaVolumeSlider, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
     
@@ -1913,7 +1925,7 @@
         return false;
 
     LocalCurrentGraphicsContext localContext(paintInfo.context);
-    wkDrawMediaUIPart(MediaVolumeSliderThumb, mediaControllerTheme(), paintInfo.context->platformContext(), r, getMediaUIPartStateFlags(node));
+    wkDrawMediaUIPart(MediaVolumeSliderThumb, mediaControllerTheme(), localContext.cgContext(), r, getMediaUIPartStateFlags(node));
     return false;
 }
     
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to