| Index: Source/platform/graphics/StaticBitmapPattern.cpp
|
| diff --git a/Source/platform/graphics/StaticBitmapPattern.cpp b/Source/platform/graphics/StaticBitmapPattern.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..847f8ebb9b355d435ea7b6d1c48ad2e2eb63aa68
|
| --- /dev/null
|
| +++ b/Source/platform/graphics/StaticBitmapPattern.cpp
|
| @@ -0,0 +1,55 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "platform/graphics/StaticBitmapPattern.h"
|
| +
|
| +#include "platform/graphics/skia/SkiaUtils.h"
|
| +#include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "third_party/skia/include/core/SkColorShader.h"
|
| +#include "third_party/skia/include/core/SkImage.h"
|
| +#include <v8.h>
|
| +
|
| +namespace blink {
|
| +
|
| +PassRefPtr<Pattern> StaticBitmapPattern::create(PassRefPtr<Image> tileImage, bool repeatX, bool repeatY)
|
| +{
|
| + return adoptRef(new StaticBitmapPattern(tileImage->image(), repeatX, repeatY));
|
| +}
|
| +
|
| +StaticBitmapPattern::StaticBitmapPattern(PassRefPtr<SkImage> image, bool repeatX, bool repeatY)
|
| +: BitmapBackedPattern(repeatX, repeatY, image ? image->width() * image->height() * 4 : 0)
|
| +{
|
| + m_tileImage = image;
|
| +}
|
| +
|
| +StaticBitmapPattern::~StaticBitmapPattern() { }
|
| +
|
| +PassRefPtr<SkShader> StaticBitmapPattern::createShader(SkShader::ShaderLocation preferredLocation)
|
| +{
|
| + // If we have no image, return null
|
| + if (!m_tileImage) {
|
| + return adoptRef(new SkColorShader(SK_ColorTRANSPARENT));
|
| + }
|
| +
|
| + SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation);
|
| +
|
| + if (m_repeatX && m_repeatY) {
|
| + return adoptRef(m_tileImage->newShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix, preferredLocation));
|
| + }
|
| +
|
| + return BitmapBackedPattern::createShader(preferredLocation);
|
| +}
|
| +
|
| +SkImageInfo StaticBitmapPattern::getBitmapInfo()
|
| +{
|
| + return SkImageInfo::MakeN32Premul(m_tileImage->width(), m_tileImage->height());
|
| +}
|
| +
|
| +void StaticBitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint)
|
| +{
|
| + m_tileImage->draw(&canvas, SkIntToScalar(0), SkIntToScalar(0), &paint);
|
| +}
|
| +
|
| +} // namespace
|
|
|