Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
Justin Novosad
2014/07/29 14:56:53
Short header
Rémi Piotaix
2014/07/29 17:18:23
Done.
| |
| 2 // | |
| 3 // The Chromium Authors can be found at | |
| 4 // http://src.chromium.org/svn/trunk/src/AUTHORS | |
| 5 // | |
| 6 // Redistribution and use in source and binary forms, with or without | |
| 7 // modification, are permitted provided that the following conditions are | |
| 8 // met: | |
| 9 // | |
| 10 // * Redistributions of source code must retain the above copyright | |
| 11 // notice, this list of conditions and the following disclaimer. | |
| 12 // * Redistributions in binary form must reproduce the above | |
| 13 // copyright notice, this list of conditions and the following disclaimer | |
| 14 // in the documentation and/or other materials provided with the | |
| 15 // distribution. | |
| 16 // * Neither the name of Google Inc. nor the names of its | |
| 17 // contributors may be used to endorse or promote products derived from | |
| 18 // this software without specific prior written permission. | |
| 19 // | |
| 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 31 | |
| 32 #include "config.h" | |
| 33 #include "platform/graphics/StaticBitmapPattern.h" | |
| 34 | |
|
Justin Novosad
2014/07/29 14:56:53
No need for 2 blank lines.
Rémi Piotaix
2014/07/29 17:18:23
Done.
| |
| 35 | |
| 36 #include "SkCanvas.h" | |
|
Justin Novosad
2014/07/29 14:56:53
we now prefer third_party/skia/include/core/...
Rémi Piotaix
2014/07/29 17:18:23
Done.
| |
| 37 #include "SkColorShader.h" | |
| 38 #include "platform/graphics/skia/SkiaUtils.h" | |
| 39 #include <v8.h> | |
| 40 | |
| 41 namespace WebCore { | |
| 42 | |
| 43 StaticBitmapPattern::StaticBitmapPattern(PassRefPtr<SkImage> image, bool repeatX , bool repeatY) | |
| 44 : Pattern(repeatX, repeatY) | |
| 45 { | |
| 46 if (image) { | |
|
Justin Novosad
2014/07/29 14:56:53
Is this conditional necessary?
Rémi Piotaix
2014/07/29 17:18:23
Done.
| |
| 47 m_tileImage = image; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 PassRefPtr<SkShader> StaticBitmapPattern::createShader() | |
| 52 { | |
| 53 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio n); | |
| 54 | |
| 55 RefPtr<SkShader> shader; | |
| 56 | |
| 57 // If we don't have a bitmap, return a transparent shader. | |
| 58 if (!m_tileImage) { | |
| 59 shader = adoptRef(new SkColorShader(SK_ColorTRANSPARENT)); | |
|
Justin Novosad
2014/07/29 14:56:53
why not return null?
Rémi Piotaix
2014/07/29 17:18:23
Done.
Rémi Piotaix
2014/07/30 18:59:13
Reverted, was breaking some tests (and also breaks
| |
| 60 } else if (m_repeatX && m_repeatY) { | |
| 61 shader = adoptRef(m_tileImage->newShader(SkShader::kRepeat_TileMode, SkS hader::kRepeat_TileMode, &localMatrix)); | |
| 62 } else { | |
| 63 // Skia does not have a "draw the tile only once" option. Clamp_TileMode | |
| 64 // repeats the last line of the image after drawing one tile. To avoid | |
| 65 // filling the space with arbitrary pixels, this workaround forces the | |
| 66 // image to have a line of transparent pixels on the "repeated" edge(s), | |
| 67 // thus causing extra space to be transparent filled. | |
| 68 SkShader::TileMode tileModeX = m_repeatX ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; | |
| 69 SkShader::TileMode tileModeY = m_repeatY ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; | |
| 70 int expandW = m_repeatX ? 0 : 1; | |
| 71 int expandH = m_repeatY ? 0 : 1; | |
| 72 | |
| 73 // Create a transparent bitmap 1 pixel wider and/or taller than the | |
| 74 // original, then copy the orignal into it. | |
| 75 // FIXME: Is there a better way to pad (not scale) an image in skia? | |
| 76 SkImageInfo info = m_tileImage->info(); | |
| 77 info.fWidth = m_tileImage->width() + expandW; | |
| 78 info.fHeight = m_tileImage->height() + expandH; | |
| 79 // we explicitly require non-opaquness, since we are going to add a tran sparent strip. | |
| 80 info.fAlphaType = kPremul_SkAlphaType; | |
| 81 | |
| 82 SkBitmap bm2; | |
| 83 bm2.allocPixels(info); | |
| 84 bm2.eraseARGB(0x00, 0x00, 0x00, 0x00); | |
|
Justin Novosad
2014/07/29 14:56:53
could clear just borders
Rémi Piotaix
2014/07/30 18:59:12
Done.
| |
| 85 SkCanvas canvas(bm2); | |
| 86 m_tileImage->draw(&canvas, SkIntToScalar(0), SkIntToScalar(0), 0); | |
|
Justin Novosad
2014/07/29 14:56:53
use Src xfermode
Rémi Piotaix
2014/07/30 18:59:12
Done.
| |
| 87 | |
| 88 bm2.setImmutable(); | |
| 89 shader = adoptRef(SkShader::CreateBitmapShader(bm2, tileModeX, tileModeY , &localMatrix)); | |
| 90 | |
| 91 // Clamp to int, since that's what the adjust function takes. | |
| 92 m_externalMemoryAllocated = static_cast<int> (std::min(static_cast<size_ t> (INT_MAX), bm2.getSafeSize())); | |
| 93 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_exter nalMemoryAllocated); | |
|
Justin Novosad
2014/07/29 14:56:53
delta?
Rémi Piotaix
2014/07/30 18:59:12
Done.
| |
| 94 } | |
| 95 return shader; | |
| 96 } | |
| 97 | |
| 98 } // namespace | |
| OLD | NEW |