Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: Source/platform/graphics/BitmapPattern.cpp

Issue 358893002: Use newImageSnapshot() to get an image from a Canvas (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Bitmap caching for Shaders/Patterns from StaticBitmapImage/SkImage Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/graphics/BitmapPattern.cpp
diff --git a/Source/platform/graphics/BitmapPattern.cpp b/Source/platform/graphics/BitmapPattern.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e8e63340472f50cb8b8e626e1521ff91c4e8740e
--- /dev/null
+++ b/Source/platform/graphics/BitmapPattern.cpp
@@ -0,0 +1,48 @@
+// 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/BitmapPattern.h"
+
+#include "platform/graphics/skia/SkiaUtils.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkColorShader.h"
+#include <v8.h>
+
+namespace blink {
+
+BitmapPattern::BitmapPattern(PassRefPtr<Image> image, bool repeatX, bool repeatY)
+: BitmapBackedPattern(repeatX, repeatY, image.get() ? image->nativeImageForCurrentFrame()->bitmap().getSafeSize() : 0 )
+{
+ if (image) {
+ m_tileImage = image->nativeImageForCurrentFrame();
+ }
+}
+
+PassRefPtr<SkShader> BitmapPattern::createShader(SkShader::ShaderLocation preferredLocation)
+{
+ if (!m_tileImage) {
+ return adoptRef(new SkColorShader(SK_ColorTRANSPARENT));
+ }
+
+ SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation);
+
+ if (m_repeatX && m_repeatY) {
+ return adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
+ }
+
+ return BitmapBackedPattern::createShader(preferredLocation);
+}
+
+SkImageInfo BitmapPattern::getBitmapInfo()
+{
+ return m_tileImage->bitmap().info();
+}
+
+void BitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint)
+{
+ canvas.drawBitmap(m_tileImage->bitmap(), SkIntToScalar(0), SkIntToScalar(0), &paint);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698