Index: Source/platform/graphics/Gradient.cpp |
diff --git a/Source/platform/graphics/Gradient.cpp b/Source/platform/graphics/Gradient.cpp |
index ab3ac96cdaa7e9dd0126152b73766e29608b5c35..b9756bd59b2d5b10904c14dcd17c77b606618be8 100644 |
--- a/Source/platform/graphics/Gradient.cpp |
+++ b/Source/platform/graphics/Gradient.cpp |
@@ -36,6 +36,9 @@ |
#include "third_party/skia/include/core/SkShader.h" |
#include "third_party/skia/include/effects/SkGradientShader.h" |
+typedef Vector<SkScalar, 8> ColorStopOffsetVector; |
+typedef Vector<SkColor, 8> ColorStopColorVector; |
+ |
namespace WebCore { |
Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1) |
@@ -178,7 +181,7 @@ static size_t totalStopsNeeded(const Gradient::ColorStop* stopData, size_t count |
// enough to hold information for all stops, including the new endpoints if |
// stops at 0.0 and 1.0 aren't already included. |
static void fillStops(const Gradient::ColorStop* stopData, |
- size_t count, SkScalar* pos, SkColor* colors) |
+ size_t count, ColorStopOffsetVector& pos, ColorStopColorVector& colors) |
{ |
const Gradient::ColorStop* stop = stopData; |
size_t start = 0; |
@@ -223,11 +226,8 @@ SkShader* Gradient::shader() |
ASSERT(countUsed >= 2); |
ASSERT(countUsed >= m_stops.size()); |
- // FIXME: Why is all this manual pointer math needed?! |
- SkAutoMalloc storage(countUsed * (sizeof(SkColor) + sizeof(SkScalar))); |
- SkColor* colors = (SkColor*)storage.get(); |
- SkScalar* pos = (SkScalar*)(colors + countUsed); |
- |
+ ColorStopOffsetVector pos(countUsed); |
+ ColorStopColorVector colors(countUsed); |
fillStops(m_stops.data(), m_stops.size(), pos, colors); |
SkShader::TileMode tile = SkShader::kClamp_TileMode; |
@@ -248,13 +248,13 @@ SkShader* Gradient::shader() |
// Since the two-point radial gradient is slower than the plain radial, |
// only use it if we have to. |
if (m_p0 == m_p1 && m_r0 <= 0.0f) { |
- m_gradient = adoptRef(SkGradientShader::CreateRadial(m_p1, m_r1, colors, pos, static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace)); |
+ m_gradient = adoptRef(SkGradientShader::CreateRadial(m_p1, m_r1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace)); |
} else { |
// The radii we give to Skia must be positive. If we're given a |
// negative radius, ask for zero instead. |
SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0; |
SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0; |
- m_gradient = adoptRef(SkGradientShader::CreateTwoPointConical(m_p0, radius0, m_p1, radius1, colors, pos, static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace)); |
+ m_gradient = adoptRef(SkGradientShader::CreateTwoPointConical(m_p0, radius0, m_p1, radius1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace)); |
} |
if (aspectRatio() != 1) { |
@@ -267,7 +267,7 @@ SkShader* Gradient::shader() |
} |
} else { |
SkPoint pts[2] = { m_p0, m_p1 }; |
- m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors, pos, static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace)); |
+ m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace)); |
} |
if (!m_gradient) { |