| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Computer, Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 4 * Copyright (C) 2013 Google, Inc. All rights reserved. | 4 * Copyright (C) 2013 Google, Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "sky/engine/config.h" | 28 #include "sky/engine/config.h" |
| 29 #include "sky/engine/platform/graphics/Pattern.h" | 29 #include "sky/engine/platform/graphics/Pattern.h" |
| 30 | 30 |
| 31 #include "sky/engine/platform/graphics/skia/SkiaUtils.h" | 31 #include "sky/engine/platform/graphics/skia/SkiaUtils.h" |
| 32 #include "third_party/skia/include/core/SkCanvas.h" | 32 #include "third_party/skia/include/core/SkCanvas.h" |
| 33 #include "v8/include/v8.h" | |
| 34 | 33 |
| 35 namespace blink { | 34 namespace blink { |
| 36 | 35 |
| 37 PassRefPtr<Pattern> Pattern::createBitmapPattern(PassRefPtr<Image> tileImage, Re
peatMode repeatMode) | 36 PassRefPtr<Pattern> Pattern::createBitmapPattern(PassRefPtr<Image> tileImage, Re
peatMode repeatMode) |
| 38 { | 37 { |
| 39 return adoptRef(new Pattern(tileImage, repeatMode)); | 38 return adoptRef(new Pattern(tileImage, repeatMode)); |
| 40 } | 39 } |
| 41 | 40 |
| 42 Pattern::Pattern(PassRefPtr<Image> image, RepeatMode repeatMode) | 41 Pattern::Pattern(PassRefPtr<Image> image, RepeatMode repeatMode) |
| 43 : m_repeatMode(repeatMode) | 42 : m_repeatMode(repeatMode) |
| 44 , m_externalMemoryAllocated(0) | 43 , m_externalMemoryAllocated(0) |
| 45 { | 44 { |
| 46 if (image) { | 45 if (image) { |
| 47 m_tileImage = image->nativeImageForCurrentFrame(); | 46 m_tileImage = image->nativeImageForCurrentFrame(); |
| 48 } | 47 } |
| 49 } | 48 } |
| 50 | 49 |
| 51 Pattern::~Pattern() | 50 Pattern::~Pattern() |
| 52 { | 51 { |
| 53 if (m_externalMemoryAllocated) | |
| 54 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnalMemoryAllocated); | |
| 55 } | 52 } |
| 56 | 53 |
| 57 SkShader* Pattern::shader() | 54 SkShader* Pattern::shader() |
| 58 { | 55 { |
| 59 if (m_pattern) | 56 if (m_pattern) |
| 60 return m_pattern.get(); | 57 return m_pattern.get(); |
| 61 | 58 |
| 62 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); | 59 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); |
| 63 | 60 |
| 64 // If we don't have a bitmap, return a transparent shader. | 61 // If we don't have a bitmap, return a transparent shader. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 94 SkBitmap bm2; | 91 SkBitmap bm2; |
| 95 bm2.allocPixels(info); | 92 bm2.allocPixels(info); |
| 96 bm2.eraseARGB(0x00, 0x00, 0x00, 0x00); | 93 bm2.eraseARGB(0x00, 0x00, 0x00, 0x00); |
| 97 SkCanvas canvas(bm2); | 94 SkCanvas canvas(bm2); |
| 98 canvas.drawBitmap(m_tileImage->bitmap(), 0, 0); | 95 canvas.drawBitmap(m_tileImage->bitmap(), 0, 0); |
| 99 bm2.setImmutable(); | 96 bm2.setImmutable(); |
| 100 m_pattern = adoptRef(SkShader::CreateBitmapShader(bm2, tileModeX, tileMo
deY, &localMatrix)); | 97 m_pattern = adoptRef(SkShader::CreateBitmapShader(bm2, tileModeX, tileMo
deY, &localMatrix)); |
| 101 | 98 |
| 102 // Clamp to int, since that's what the adjust function takes. | 99 // Clamp to int, since that's what the adjust function takes. |
| 103 m_externalMemoryAllocated = static_cast<int>(std::min(static_cast<size_t
>(INT_MAX), bm2.getSafeSize())); | 100 m_externalMemoryAllocated = static_cast<int>(std::min(static_cast<size_t
>(INT_MAX), bm2.getSafeSize())); |
| 104 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_exter
nalMemoryAllocated); | |
| 105 } | 101 } |
| 106 return m_pattern.get(); | 102 return m_pattern.get(); |
| 107 } | 103 } |
| 108 | 104 |
| 109 void Pattern::setPatternSpaceTransform(const AffineTransform& patternSpaceTransf
ormation) | 105 void Pattern::setPatternSpaceTransform(const AffineTransform& patternSpaceTransf
ormation) |
| 110 { | 106 { |
| 111 if (patternSpaceTransformation == m_patternSpaceTransformation) | 107 if (patternSpaceTransformation == m_patternSpaceTransformation) |
| 112 return; | 108 return; |
| 113 | 109 |
| 114 m_patternSpaceTransformation = patternSpaceTransformation; | 110 m_patternSpaceTransformation = patternSpaceTransformation; |
| 115 m_pattern.clear(); | 111 m_pattern.clear(); |
| 116 } | 112 } |
| 117 | 113 |
| 118 } // namespace blink | 114 } // namespace blink |
| OLD | NEW |