Diff
Modified: trunk/Source/WebCore/ChangeLog (119306 => 119307)
--- trunk/Source/WebCore/ChangeLog 2012-06-02 01:26:45 UTC (rev 119306)
+++ trunk/Source/WebCore/ChangeLog 2012-06-02 01:38:39 UTC (rev 119307)
@@ -1,3 +1,34 @@
+2012-06-01 Tim Horton <[email protected]>
+
+ Cleanup GeneratorGeneratedImage/Gradient changes from r117858
+ https://bugs.webkit.org/show_bug.cgi?id=88063
+
+ Reviewed by Simon Fraser.
+
+ No new tests, code cleanup.
+
+ * platform/graphics/Generator.h:
+ (WebCore::Generator::hash): hash() should be const.
+ * platform/graphics/GeneratorGeneratedImage.cpp:
+ (WebCore::GeneratorGeneratedImage::drawPattern): Minor cleanup.
+ * platform/graphics/Gradient.cpp:
+ (WebCore::Gradient::Gradient): Rename m_hashCache to m_cachedHash.
+ (WebCore::Gradient::addColorStop): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::sortStopsIfNecessary): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::setSpreadMethod): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::setGradientSpaceTransform): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::hash): Use intHash instead of the pair hasher. Add compile time size checks
+ for structures being passed to StringHasher.
+ * platform/graphics/Gradient.h:
+ (WebCore::Gradient::setP0): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::setP1): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::setStartRadius): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::setEndRadius): Rename clearHashCache to invalidateHash.
+ (WebCore::Gradient::invalidateHash): Rename clearHashCache to invalidateHash.
+ * platform/graphics/GraphicsContext.cpp:
+ (WebCore::scalesMatch): Added. Determine if the scale of two AffineTransforms match.
+ (WebCore::GraphicsContext::isCompatibleWithBuffer): Make use of scalesMatch to simplify the logic.
+
2012-06-01 Raymond Toy <[email protected]>
Remove RefInfo class
Modified: trunk/Source/WebCore/platform/graphics/Generator.h (119306 => 119307)
--- trunk/Source/WebCore/platform/graphics/Generator.h 2012-06-02 01:26:45 UTC (rev 119306)
+++ trunk/Source/WebCore/platform/graphics/Generator.h 2012-06-02 01:38:39 UTC (rev 119307)
@@ -39,7 +39,7 @@
virtual void fill(GraphicsContext*, const FloatRect&) = 0;
virtual void adjustParametersForTiledDrawing(IntSize& /* size */, FloatRect& /* srcRect */) { }
- virtual unsigned hash() = 0;
+ virtual unsigned hash() const = 0;
};
} //namespace
Modified: trunk/Source/WebCore/platform/graphics/GeneratorGeneratedImage.cpp (119306 => 119307)
--- trunk/Source/WebCore/platform/graphics/GeneratorGeneratedImage.cpp 2012-06-02 01:26:45 UTC (rev 119306)
+++ trunk/Source/WebCore/platform/graphics/GeneratorGeneratedImage.cpp 2012-06-02 01:38:39 UTC (rev 119307)
@@ -62,18 +62,13 @@
unsigned generatorHash = m_generator->hash();
- if (!m_cachedImageBuffer
- || m_cachedGeneratorHash != generatorHash
- || m_cachedAdjustedSize != adjustedSize
- || !destContext->isCompatibleWithBuffer(m_cachedImageBuffer.get())) {
- // Create a BitmapImage and call drawPattern on it.
+ if (!m_cachedImageBuffer || m_cachedGeneratorHash != generatorHash || m_cachedAdjustedSize != adjustedSize || !destContext->isCompatibleWithBuffer(m_cachedImageBuffer.get())) {
m_cachedImageBuffer = destContext->createCompatibleBuffer(adjustedSize);
if (!m_cachedImageBuffer)
return;
// Fill with the generated image.
- GraphicsContext* graphicsContext = m_cachedImageBuffer->context();
- graphicsContext->fillRect(FloatRect(FloatPoint(), adjustedSize), *m_generator.get());
+ m_cachedImageBuffer->context()->fillRect(FloatRect(FloatPoint(), adjustedSize), *m_generator);
m_cachedGeneratorHash = generatorHash;
m_cachedAdjustedSize = adjustedSize;
Modified: trunk/Source/WebCore/platform/graphics/GeneratorGeneratedImage.h (119306 => 119307)
--- trunk/Source/WebCore/platform/graphics/GeneratorGeneratedImage.h 2012-06-02 01:26:45 UTC (rev 119306)
+++ trunk/Source/WebCore/platform/graphics/GeneratorGeneratedImage.h 2012-06-02 01:38:39 UTC (rev 119307)
@@ -38,10 +38,7 @@
static const int generatedImageCacheClearDelay = 1;
-class GeneratedImageCacheTimer;
-
class GeneratorGeneratedImage : public GeneratedImage {
- friend class GeneratedImageCacheTimer;
public:
static PassRefPtr<GeneratorGeneratedImage> create(PassRefPtr<Generator> generator, const IntSize& size)
{
Modified: trunk/Source/WebCore/platform/graphics/Gradient.cpp (119306 => 119307)
--- trunk/Source/WebCore/platform/graphics/Gradient.cpp 2012-06-02 01:26:45 UTC (rev 119306)
+++ trunk/Source/WebCore/platform/graphics/Gradient.cpp 2012-06-02 01:38:39 UTC (rev 119307)
@@ -33,6 +33,8 @@
#include <wtf/StringHasher.h>
#include <wtf/UnusedParam.h>
+using WTF::intHash;
+
namespace WebCore {
Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1)
@@ -45,7 +47,7 @@
, m_stopsSorted(false)
, m_lastStop(0)
, m_spreadMethod(SpreadMethodPad)
- , m_hashCache(0)
+ , m_cachedHash(0)
{
platformInit();
}
@@ -60,7 +62,7 @@
, m_stopsSorted(false)
, m_lastStop(0)
, m_spreadMethod(SpreadMethodPad)
- , m_hashCache(0)
+ , m_cachedHash(0)
{
platformInit();
}
@@ -104,7 +106,7 @@
m_stopsSorted = false;
platformDestroy();
- clearHashCache();
+ invalidateHash();
}
void Gradient::addColorStop(const Gradient::ColorStop& stop)
@@ -114,7 +116,7 @@
m_stopsSorted = false;
platformDestroy();
- clearHashCache();
+ invalidateHash();
}
static inline bool compareStops(const Gradient::ColorStop& a, const Gradient::ColorStop& b)
@@ -134,7 +136,7 @@
std::stable_sort(m_stops.begin(), m_stops.end(), compareStops);
- clearHashCache();
+ invalidateHash();
}
void Gradient::getColor(float value, float* r, float* g, float* b, float* a) const
@@ -224,7 +226,7 @@
m_spreadMethod = spreadMethod;
- clearHashCache();
+ invalidateHash();
}
void Gradient::setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation)
@@ -235,7 +237,7 @@
m_gradientSpaceTransformation = gradientSpaceTransformation;
setPlatformGradientSpaceTransform(gradientSpaceTransformation);
- clearHashCache();
+ invalidateHash();
}
#if !USE(SKIA) && !USE(CAIRO)
@@ -244,10 +246,10 @@
}
#endif
-unsigned Gradient::hash()
+unsigned Gradient::hash() const
{
- if (m_hashCache)
- return m_hashCache;
+ if (m_cachedHash)
+ return m_cachedHash;
struct {
AffineTransform gradientSpaceTransformation;
@@ -260,7 +262,12 @@
GradientSpreadMethod spreadMethod;
bool radial;
} parameters;
+
+ // StringHasher requires that the memory it hashes be a multiple of two in size.
+ COMPILE_ASSERT(!(sizeof(parameters) % 2), Gradient_parameters_size_should_be_multiple_of_two);
+ COMPILE_ASSERT(!(sizeof(ColorStop) % 2), Color_stop_size_should_be_multiple_of_two);
+ // Ensure that any padding in the struct is zero-filled, so it will not affect the hash value.
memset(¶meters, 0, sizeof(parameters));
parameters.gradientSpaceTransformation = m_gradientSpaceTransformation;
@@ -274,15 +281,11 @@
parameters.radial = m_radial;
unsigned parametersHash = StringHasher::hashMemory(¶meters, sizeof(parameters));
-
- ColorStop * stopData = m_stops.data();
- unsigned stopHash = StringHasher::hashMemory(stopData, m_stops.size() * sizeof(ColorStop));
-
- std::pair<unsigned, unsigned> hashes(parametersHash, stopHash);
-
- m_hashCache = DefaultHash<std::pair<unsigned, unsigned> >::Hash::hash(hashes);
+ unsigned stopHash = StringHasher::hashMemory(m_stops.data(), m_stops.size() * sizeof(ColorStop));
- return m_hashCache;
+ m_cachedHash = intHash((static_cast<uint64_t>(parametersHash) << 32) | stopHash);
+
+ return m_cachedHash;
}
} //namespace
Modified: trunk/Source/WebCore/platform/graphics/Gradient.h (119306 => 119307)
--- trunk/Source/WebCore/platform/graphics/Gradient.h 2012-06-02 01:26:45 UTC (rev 119306)
+++ trunk/Source/WebCore/platform/graphics/Gradient.h 2012-06-02 01:38:39 UTC (rev 119307)
@@ -104,7 +104,7 @@
m_p0 = p;
- clearHashCache();
+ invalidateHash();
}
void setP1(const FloatPoint& p)
@@ -114,7 +114,7 @@
m_p1 = p;
- clearHashCache();
+ invalidateHash();
}
float startRadius() const { return m_r0; }
@@ -127,7 +127,7 @@
m_r0 = r;
- clearHashCache();
+ invalidateHash();
}
void setEndRadius(float r)
@@ -137,7 +137,7 @@
m_r1 = r;
- clearHashCache();
+ invalidateHash();
}
float aspectRatio() const { return m_aspectRatio; }
@@ -172,8 +172,8 @@
void setPlatformGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
- virtual unsigned hash() OVERRIDE;
- void clearHashCache() { m_hashCache = 0; }
+ virtual unsigned hash() const OVERRIDE;
+ void invalidateHash() { m_cachedHash = 0; }
#if USE(CG)
void paint(CGContextRef);
@@ -205,7 +205,7 @@
GradientSpreadMethod m_spreadMethod;
AffineTransform m_gradientSpaceTransformation;
- unsigned m_hashCache;
+ mutable unsigned m_cachedHash;
PlatformGradient m_gradient;
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (119306 => 119307)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp 2012-06-02 01:26:45 UTC (rev 119306)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp 2012-06-02 01:38:39 UTC (rev 119307)
@@ -761,6 +761,11 @@
}
}
+static bool scalesMatch(AffineTransform a, AffineTransform b)
+{
+ return a.xScale() == b.xScale() && a.yScale() == b.yScale();
+}
+
PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& size) const
{
// Make the buffer larger if the context's transform is scaling it so we need a higher
@@ -782,16 +787,9 @@
bool GraphicsContext::isCompatibleWithBuffer(ImageBuffer* buffer) const
{
- AffineTransform localTransform = getCTM();
- AffineTransform bufferTransform = buffer->context()->getCTM();
+ GraphicsContext* bufferContext = buffer->context();
- if (localTransform.xScale() != bufferTransform.xScale() || localTransform.yScale() != bufferTransform.yScale())
- return false;
-
- if (isAcceleratedContext() != buffer->context()->isAcceleratedContext())
- return false;
-
- return true;
+ return scalesMatch(getCTM(), bufferContext->getCTM()) && isAcceleratedContext() == bufferContext->isAcceleratedContext();
}
#if !USE(CG)