| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "NativeImageSkia.h" |
| 31 | 32 |
| 32 #include "base/gfx/image_operations.h" | 33 #include "SkiaUtils.h" |
| 33 | 34 |
| 34 #include "NativeImageSkia.h" | 35 #include "skia/ext/image_operations.h" |
| 35 #include "SkiaUtils.h" | |
| 36 | 36 |
| 37 NativeImageSkia::NativeImageSkia() | 37 NativeImageSkia::NativeImageSkia() |
| 38 : SkBitmap(), | 38 : SkBitmap(), |
| 39 m_isDataComplete(false), | 39 m_isDataComplete(false), |
| 40 m_resizedImage(), | 40 m_resizedImage(), |
| 41 m_lastRequestSize(0, 0), | 41 m_lastRequestSize(0, 0), |
| 42 m_resizeRequests(0) { | 42 m_resizeRequests(0) { |
| 43 } | 43 } |
| 44 | 44 |
| 45 int NativeImageSkia::decodedSize() const { | 45 int NativeImageSkia::decodedSize() const { |
| 46 return getSize() + m_resizedImage.getSize(); | 46 return getSize() + m_resizedImage.getSize(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool NativeImageSkia::hasResizedBitmap(int w, int h) const { | 49 bool NativeImageSkia::hasResizedBitmap(int w, int h) const { |
| 50 if (m_lastRequestSize.width() == w && m_lastRequestSize.height() == h) { | 50 if (m_lastRequestSize.width() == w && m_lastRequestSize.height() == h) { |
| 51 m_resizeRequests++; | 51 m_resizeRequests++; |
| 52 } else { | 52 } else { |
| 53 m_lastRequestSize = WebCore::IntSize(w, h); | 53 m_lastRequestSize = WebCore::IntSize(w, h); |
| 54 m_resizeRequests = 0; | 54 m_resizeRequests = 0; |
| 55 } | 55 } |
| 56 | 56 |
| 57 return m_resizedImage.width() == w && m_resizedImage.height() == h; | 57 return m_resizedImage.width() == w && m_resizedImage.height() == h; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // FIXME(brettw) don't cache when image is in-progress. | 60 // FIXME(brettw) don't cache when image is in-progress. |
| 61 | 61 |
| 62 SkBitmap NativeImageSkia::resizedBitmap(int w, int h) const { | 62 SkBitmap NativeImageSkia::resizedBitmap(int w, int h) const { |
| 63 if (m_resizedImage.width() != w || m_resizedImage.height() != h) { | 63 if (m_resizedImage.width() != w || m_resizedImage.height() != h) { |
| 64 m_resizedImage = gfx::ImageOperations::Resize(*this, | 64 m_resizedImage = skia::ImageOperations::Resize(*this, |
| 65 gfx::ImageOperations::RESIZE_LANCZOS3, gfx::Size(w, h)); | 65 skia::ImageOperations::RESIZE_LANCZOS3, gfx::Size(w, h)); |
| 66 } | 66 } |
| 67 return m_resizedImage; | 67 return m_resizedImage; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // static | 70 // static |
| 71 bool NativeImageSkia::shouldCacheResampling(int dest_width, | 71 bool NativeImageSkia::shouldCacheResampling(int dest_width, |
| 72 int dest_height, | 72 int dest_height, |
| 73 int dest_subset_width, | 73 int dest_subset_width, |
| 74 int dest_subset_height) const { | 74 int dest_subset_height) const { |
| 75 // We can not cache incomplete frames. This might be a good optimization in | 75 // We can not cache incomplete frames. This might be a good optimization in |
| (...skipping 22 matching lines...) Expand all Loading... |
| 98 m_lastRequestSize = WebCore::IntSize(dest_width, dest_height); | 98 m_lastRequestSize = WebCore::IntSize(dest_width, dest_height); |
| 99 m_resizeRequests = 0; | 99 m_resizeRequests = 0; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Otherwise, use the heuristic that if more than 1/4 of the image is | 102 // Otherwise, use the heuristic that if more than 1/4 of the image is |
| 103 // requested, it's worth caching. | 103 // requested, it's worth caching. |
| 104 int dest_size = dest_width * dest_height; | 104 int dest_size = dest_width * dest_height; |
| 105 int dest_subset_size = dest_subset_width * dest_subset_height; | 105 int dest_subset_size = dest_subset_width * dest_subset_height; |
| 106 return dest_size / 4 < dest_subset_size; | 106 return dest_size / 4 < dest_subset_size; |
| 107 } | 107 } |
| OLD | NEW |