| Index: Source/platform/graphics/BitmapPattern.cpp
|
| diff --git a/Source/platform/graphics/Pattern.cpp b/Source/platform/graphics/BitmapPattern.cpp
|
| similarity index 74%
|
| copy from Source/platform/graphics/Pattern.cpp
|
| copy to Source/platform/graphics/BitmapPattern.cpp
|
| index 3d7c0acf95791118ba0c3523330de2f3db0fa311..7344644ca6635820a6b172e8293c2d0e4451d307 100644
|
| --- a/Source/platform/graphics/Pattern.cpp
|
| +++ b/Source/platform/graphics/BitmapPattern.cpp
|
| @@ -26,45 +26,36 @@
|
| */
|
|
|
| #include "config.h"
|
| -#include "platform/graphics/Pattern.h"
|
| +#include "platform/graphics/BitmapPattern.h"
|
| +
|
|
|
| -#include <v8.h>
|
| #include "SkCanvas.h"
|
| #include "SkColorShader.h"
|
| #include "platform/graphics/skia/SkiaUtils.h"
|
| -
|
| +#include <v8.h>
|
|
|
| namespace WebCore {
|
|
|
| -Pattern::Pattern(PassRefPtr<Image> image, bool repeatX, bool repeatY)
|
| - : m_repeatX(repeatX)
|
| - , m_repeatY(repeatY)
|
| - , m_externalMemoryAllocated(0)
|
| +BitmapPattern::BitmapPattern(PassRefPtr<Image> image, bool repeatX, bool repeatY)
|
| +: Pattern(repeatX, repeatY)
|
| {
|
| if (image) {
|
| m_tileImage = image->nativeImageForCurrentFrame();
|
| }
|
| }
|
|
|
| -Pattern::~Pattern()
|
| -{
|
| - if (m_externalMemoryAllocated)
|
| - v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_externalMemoryAllocated);
|
| -}
|
| -
|
| -SkShader* Pattern::shader()
|
| +PassRefPtr<SkShader> BitmapPattern::createShader()
|
| {
|
| - if (m_pattern)
|
| - return m_pattern.get();
|
| -
|
| SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation);
|
|
|
| + RefPtr<SkShader> shader;
|
| +
|
| // If we don't have a bitmap, return a transparent shader.
|
| - if (!m_tileImage)
|
| - m_pattern = adoptRef(new SkColorShader(SK_ColorTRANSPARENT));
|
| - else if (m_repeatX && m_repeatY)
|
| - m_pattern = adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
|
| - else {
|
| + if (!m_tileImage) {
|
| + shader = adoptRef(new SkColorShader(SK_ColorTRANSPARENT));
|
| + } else if (m_repeatX && m_repeatY) {
|
| + shader = adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
|
| + } else {
|
| // Skia does not have a "draw the tile only once" option. Clamp_TileMode
|
| // repeats the last line of the image after drawing one tile. To avoid
|
| // filling the space with arbitrary pixels, this workaround forces the
|
| @@ -90,20 +81,13 @@ SkShader* Pattern::shader()
|
| SkCanvas canvas(bm2);
|
| canvas.drawBitmap(m_tileImage->bitmap(), 0, 0);
|
| bm2.setImmutable();
|
| - m_pattern = adoptRef(SkShader::CreateBitmapShader(bm2, tileModeX, tileModeY, &localMatrix));
|
| + shader = adoptRef(SkShader::CreateBitmapShader(bm2, tileModeX, tileModeY, &localMatrix));
|
|
|
| // Clamp to int, since that's what the adjust function takes.
|
| - m_externalMemoryAllocated = static_cast<int>(std::min(static_cast<size_t>(INT_MAX), bm2.getSafeSize()));
|
| + m_externalMemoryAllocated = static_cast<int> (std::min(static_cast<size_t> (INT_MAX), bm2.getSafeSize()));
|
| v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externalMemoryAllocated);
|
| }
|
| - return m_pattern.get();
|
| -}
|
| -
|
| -void Pattern::setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation)
|
| -{
|
| - m_patternSpaceTransformation = patternSpaceTransformation;
|
| - if (m_pattern)
|
| - m_pattern.clear();
|
| + return shader;
|
| }
|
|
|
| -}
|
| +} // namespace
|
|
|