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

Side by Side Diff: Source/platform/graphics/StaticBitmapPattern.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 unified diff | Download patch
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/StaticBitmapPattern.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 "third_party/skia/include/core/SkImage.h"
12 #include <v8.h>
13
14 namespace blink {
15
16 PassRefPtr<Pattern> StaticBitmapPattern::create(PassRefPtr<Image> tileImage, boo l repeatX, bool repeatY)
17 {
18 return adoptRef(new StaticBitmapPattern(tileImage->image(), repeatX, repeatY ));
19 }
20
21 StaticBitmapPattern::StaticBitmapPattern(PassRefPtr<SkImage> image, bool repeatX , bool repeatY)
22 : BitmapBackedPattern(repeatX, repeatY, image ? image->width() * image->height() * 4 : 0)
23 {
24 m_tileImage = image;
25 }
26
27 StaticBitmapPattern::~StaticBitmapPattern() { }
28
29 PassRefPtr<SkShader> StaticBitmapPattern::createShader(SkShader::ShaderLocation preferredLocation)
30 {
31 // If we have no image, return null
32 if (!m_tileImage) {
33 return adoptRef(new SkColorShader(SK_ColorTRANSPARENT));
34 }
35
36 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio n);
37
38 if (m_repeatX && m_repeatY) {
39 return adoptRef(m_tileImage->newShader(SkShader::kRepeat_TileMode, SkSha der::kRepeat_TileMode, &localMatrix, preferredLocation));
40 }
41
42 return BitmapBackedPattern::createShader(preferredLocation);
43 }
44
45 SkImageInfo StaticBitmapPattern::getBitmapInfo()
46 {
47 return SkImageInfo::MakeN32Premul(m_tileImage->width(), m_tileImage->height( ));
48 }
49
50 void StaticBitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint)
51 {
52 m_tileImage->draw(&canvas, SkIntToScalar(0), SkIntToScalar(0), &paint);
53 }
54
55 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698