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

Side by Side 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: Corrections Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « Source/platform/graphics/BitmapPattern.h ('k') | Source/platform/graphics/BitmapPatternBase.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "platform/graphics/BitmapPattern.h"
7
8 #include "platform/graphics/skia/SkiaUtils.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkColorShader.h"
11 #include <v8.h>
12
13 namespace blink {
14
15 BitmapPattern::BitmapPattern(PassRefPtr<Image> image, RepeatMode repeatMode)
16 : BitmapPatternBase(repeatMode, 0 )
17 {
18 if (image) {
19 // If image is animated, what about the pattern?
20 m_tileImage = image->nativeImageForCurrentFrame();
21
22 if (m_tileImage)
23 adjustExternalMemoryAllocated(m_tileImage->bitmap().getSafeSize());
24 }
25 }
26
27 PassRefPtr<SkShader> BitmapPattern::createShader()
28 {
29 if (!m_tileImage) {
30 return adoptRef(new SkColorShader(SK_ColorTRANSPARENT));
31 }
32
33 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio n);
34
35 if (isRepeatXY()) {
36 return adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkSh ader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
37 }
38
39 return BitmapPatternBase::createShader();
40 }
41
42 SkImageInfo BitmapPattern::getBitmapInfo()
43 {
44 return m_tileImage->bitmap().info();
45 }
46
47 void BitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint)
48 {
49 canvas.drawBitmap(m_tileImage->bitmap(), SkIntToScalar(0), SkIntToScalar(0), &paint);
50 }
51
52 } // namespace
OLDNEW
« no previous file with comments | « Source/platform/graphics/BitmapPattern.h ('k') | Source/platform/graphics/BitmapPatternBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698