Commit 268b841c authored by darin@apple.com's avatar darin@apple.com

Reviewed by Mitz.

        - http://bugs.webkit.org/show_bug.cgi?id=15945
          speed up GraphicsContextCG typical case by skipping roundToDevicePixels

        * platform/graphics/cg/GraphicsContextCG.cpp:
        (WebCore::GraphicsContext::restorePlatformState): Clear the flag since we no
        longer know if the transform is identity or not.
        (WebCore::GraphicsContext::strokeArc): Removed an extra set of redundant
        CGContextSave/RestoreGState.
        (WebCore::GraphicsContext::beginTransparencyLayer): Clear the flag since we no
        longer know if the transform is identity or not.
        (WebCore::GraphicsContext::endTransparencyLayer): Ditto.
        (WebCore::GraphicsContext::scale): Ditto.
        (WebCore::GraphicsContext::rotate): Ditto.
        (WebCore::GraphicsContext::translate): Ditto.
        (WebCore::GraphicsContext::concatCTM): Ditto.
        (WebCore::GraphicsContext::roundToDevicePixels): Return quickly if the transform
        is known to be identity, and record that fact when we discover it otherwise.

        * platform/graphics/cg/GraphicsContextPlatformPrivate.h:
        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
        Added a m_userToDeviceTransformKnownToBeIdentity flag, initialized to false.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27700 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5c1c7586
2007-11-11 Darin Adler <darin@apple.com>
Reviewed by Mitz.
- http://bugs.webkit.org/show_bug.cgi?id=15945
speed up GraphicsContextCG typical case by skipping roundToDevicePixels
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::restorePlatformState): Clear the flag since we no
longer know if the transform is identity or not.
(WebCore::GraphicsContext::strokeArc): Removed an extra set of redundant
CGContextSave/RestoreGState.
(WebCore::GraphicsContext::beginTransparencyLayer): Clear the flag since we no
longer know if the transform is identity or not.
(WebCore::GraphicsContext::endTransparencyLayer): Ditto.
(WebCore::GraphicsContext::scale): Ditto.
(WebCore::GraphicsContext::rotate): Ditto.
(WebCore::GraphicsContext::translate): Ditto.
(WebCore::GraphicsContext::concatCTM): Ditto.
(WebCore::GraphicsContext::roundToDevicePixels): Return quickly if the transform
is known to be identity, and record that fact when we discover it otherwise.
* platform/graphics/cg/GraphicsContextPlatformPrivate.h:
(WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
Added a m_userToDeviceTransformKnownToBeIdentity flag, initialized to false.
2007-11-11 Darin Adler <darin@apple.com>
Reviewed by Mitz.
......
......@@ -30,13 +30,12 @@
#if PLATFORM(CG)
#include "AffineTransform.h"
#include "GraphicsContextPlatformPrivate.h"
#include "KURL.h"
#include "Path.h"
#include <CoreGraphics/CGPDFContext.h>
#include <wtf/MathExtras.h>
#include <GraphicsContextPlatformPrivate.h> // FIXME: Temporary.
using namespace std;
namespace WebCore {
......@@ -106,6 +105,7 @@ void GraphicsContext::restorePlatformState()
// restore of the secondary context (in GraphicsContextPlatformPrivate.h).
CGContextRestoreGState(platformContext());
m_data->restore();
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
// Draws a filled rectangle with a stroked border.
......@@ -321,8 +321,6 @@ void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSp
default:
break;
}
CGContextSaveGState(context);
if (patWidth) {
// Example: 80 pixels with a width of 30 pixels.
......@@ -363,7 +361,6 @@ void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSp
}
CGContextStrokePath(context);
CGContextRestoreGState(context);
CGContextRestoreGState(context);
}
......@@ -503,6 +500,7 @@ void GraphicsContext::beginTransparencyLayer(float opacity)
CGContextSetAlpha(context, opacity);
CGContextBeginTransparencyLayer(context, 0);
m_data->beginTransparencyLayer();
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::endTransparencyLayer()
......@@ -513,6 +511,7 @@ void GraphicsContext::endTransparencyLayer()
CGContextEndTransparencyLayer(context);
CGContextRestoreGState(context);
m_data->endTransparencyLayer();
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::setShadow(const IntSize& size, int blur, const Color& color)
......@@ -644,6 +643,7 @@ void GraphicsContext::scale(const FloatSize& size)
return;
CGContextScaleCTM(platformContext(), size.width(), size.height());
m_data->scale(size);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::rotate(float angle)
......@@ -652,6 +652,7 @@ void GraphicsContext::rotate(float angle)
return;
CGContextRotateCTM(platformContext(), angle);
m_data->rotate(angle);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::translate(float x, float y)
......@@ -660,6 +661,7 @@ void GraphicsContext::translate(float x, float y)
return;
CGContextTranslateCTM(platformContext(), x, y);
m_data->translate(x, y);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::concatCTM(const AffineTransform& transform)
......@@ -668,6 +670,7 @@ void GraphicsContext::concatCTM(const AffineTransform& transform)
return;
CGContextConcatCTM(platformContext(), transform);
m_data->concatCTM(transform);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect)
......@@ -676,9 +679,15 @@ FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect)
// affine transform matrix to device space can mess with this conversion if we have a
// rotating image like the hands of the world clock widget. We just need the scale, so
// we get the affine transform matrix and extract the scale.
if (m_data->m_userToDeviceTransformKnownToBeIdentity)
return rect;
CGAffineTransform deviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(platformContext());
if (CGAffineTransformIsIdentity(deviceMatrix))
if (CGAffineTransformIsIdentity(deviceMatrix)) {
m_data->m_userToDeviceTransformKnownToBeIdentity = true;
return rect;
}
float deviceScaleX = sqrtf(deviceMatrix.a * deviceMatrix.a + deviceMatrix.b * deviceMatrix.b);
float deviceScaleY = sqrtf(deviceMatrix.c * deviceMatrix.c + deviceMatrix.d * deviceMatrix.d);
......
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -23,21 +23,19 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if PLATFORM(WIN)
#include <CoreGraphics/CGContext.h>
#endif
namespace WebCore
{
namespace WebCore {
class GraphicsContextPlatformPrivate {
public:
GraphicsContextPlatformPrivate(CGContextRef cgContext)
: m_cgContext(cgContext)
: m_cgContext(cgContext)
#if PLATFORM(WIN)
, m_hdc(0)
, m_transparencyCount(0)
, m_hdc(0)
, m_transparencyCount(0)
#endif
, m_userToDeviceTransformKnownToBeIdentity(false)
{
CGContextRetain(m_cgContext);
}
......@@ -59,7 +57,9 @@ public:
void concatCTM(const AffineTransform&) {}
void beginTransparencyLayer() {}
void endTransparencyLayer() {}
#else
#endif
#if PLATFORM(WIN)
// On Windows, we need to update the HDC for form controls to draw in the right place.
void save();
void restore();
......@@ -71,13 +71,16 @@ public:
void concatCTM(const AffineTransform&);
void beginTransparencyLayer() { m_transparencyCount++; }
void endTransparencyLayer() { m_transparencyCount--; }
#endif
#if PLATFORM(WIN)
HDC m_hdc;
unsigned m_transparencyCount;
#endif
CGContextRef m_cgContext;
IntRect m_focusRingClip; // Work around CG bug in focus ring clipping.
bool m_userToDeviceTransformKnownToBeIdentity;
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment