| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk> | 3 * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk> |
| 4 * Copyright (C) 2008, Google Inc. All rights reserved. | 4 * Copyright (C) 2008, 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 ImageSource::~ImageSource() | 42 ImageSource::~ImageSource() |
| 43 { | 43 { |
| 44 } | 44 } |
| 45 | 45 |
| 46 size_t ImageSource::clearCacheExceptFrame(size_t clearExceptFrame) | 46 size_t ImageSource::clearCacheExceptFrame(size_t clearExceptFrame) |
| 47 { | 47 { |
| 48 return m_decoder ? m_decoder->clearCacheExceptFrame(clearExceptFrame) : 0; | 48 return m_decoder ? m_decoder->clearCacheExceptFrame(clearExceptFrame) : 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool ImageSource::initialized() const | |
| 52 { | |
| 53 return m_decoder; | |
| 54 } | |
| 55 | |
| 56 void ImageSource::resetDecoder() | |
| 57 { | |
| 58 m_decoder.clear(); | |
| 59 } | |
| 60 | |
| 61 void ImageSource::setData(SharedBuffer& data, bool allDataReceived) | 51 void ImageSource::setData(SharedBuffer& data, bool allDataReceived) |
| 62 { | 52 { |
| 63 // Create a decoder by sniffing the encoded data. If insufficient data bytes
are available to | 53 // Create a decoder by sniffing the encoded data. If insufficient data bytes
are available to |
| 64 // determine the encoded image type, no decoder is created. | 54 // determine the encoded image type, no decoder is created. |
| 65 if (!m_decoder) | 55 if (!m_decoder) |
| 66 m_decoder = DeferredImageDecoder::create(data, m_alphaOption, m_gammaAnd
ColorProfileOption); | 56 m_decoder = DeferredImageDecoder::create(data, m_alphaOption, m_gammaAnd
ColorProfileOption); |
| 67 | 57 |
| 68 if (m_decoder) | 58 if (m_decoder) |
| 69 m_decoder->setData(data, allDataReceived); | 59 m_decoder->setData(data, allDataReceived); |
| 70 } | 60 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 88 { | 78 { |
| 89 return frameSizeAtIndex(0, shouldRespectOrientation); | 79 return frameSizeAtIndex(0, shouldRespectOrientation); |
| 90 } | 80 } |
| 91 | 81 |
| 92 IntSize ImageSource::frameSizeAtIndex(size_t index, RespectImageOrientationEnum
shouldRespectOrientation) const | 82 IntSize ImageSource::frameSizeAtIndex(size_t index, RespectImageOrientationEnum
shouldRespectOrientation) const |
| 93 { | 83 { |
| 94 if (!m_decoder) | 84 if (!m_decoder) |
| 95 return IntSize(); | 85 return IntSize(); |
| 96 | 86 |
| 97 IntSize size = m_decoder->frameSizeAtIndex(index); | 87 IntSize size = m_decoder->frameSizeAtIndex(index); |
| 98 if ((shouldRespectOrientation == RespectImageOrientation) && m_decoder->orie
ntation().usesWidthAsHeight()) | 88 if ((shouldRespectOrientation == RespectImageOrientation) && m_decoder->orie
ntationAtIndex(index).usesWidthAsHeight()) |
| 99 return IntSize(size.height(), size.width()); | 89 return IntSize(size.height(), size.width()); |
| 100 | 90 |
| 101 return size; | 91 return size; |
| 102 } | 92 } |
| 103 | 93 |
| 104 bool ImageSource::getHotSpot(IntPoint& hotSpot) const | 94 bool ImageSource::getHotSpot(IntPoint& hotSpot) const |
| 105 { | 95 { |
| 106 return m_decoder ? m_decoder->hotSpot(hotSpot) : false; | 96 return m_decoder ? m_decoder->hotSpot(hotSpot) : false; |
| 107 } | 97 } |
| 108 | 98 |
| 109 int ImageSource::repetitionCount() | 99 int ImageSource::repetitionCount() |
| 110 { | 100 { |
| 111 return m_decoder ? m_decoder->repetitionCount() : cAnimationNone; | 101 return m_decoder ? m_decoder->repetitionCount() : cAnimationNone; |
| 112 } | 102 } |
| 113 | 103 |
| 114 size_t ImageSource::frameCount() const | 104 size_t ImageSource::frameCount() const |
| 115 { | 105 { |
| 116 return m_decoder ? m_decoder->frameCount() : 0; | 106 int count = m_decoder ? m_decoder->frameCount() : 0; |
| 107 return count; |
| 117 } | 108 } |
| 118 | 109 |
| 119 PassRefPtr<NativeImageSkia> ImageSource::createFrameAtIndex(size_t index) | 110 PassRefPtr<NativeImageSkia> ImageSource::createFrameAtIndex(size_t index) |
| 120 { | 111 { |
| 121 if (!m_decoder) | 112 if (!m_decoder) |
| 122 return nullptr; | 113 return nullptr; |
| 123 | 114 return m_decoder->createFrameAtIndex(index); |
| 124 ImageFrame* buffer = m_decoder->frameBufferAtIndex(index); | |
| 125 if (!buffer || buffer->status() == ImageFrame::FrameEmpty) | |
| 126 return nullptr; | |
| 127 | |
| 128 // Zero-height images can cause problems for some ports. If we have an | |
| 129 // empty image dimension, just bail. | |
| 130 if (size().isEmpty()) | |
| 131 return nullptr; | |
| 132 | |
| 133 // Return the buffer contents as a native image. For some ports, the data | |
| 134 // is already in a native container, and this just increments its refcount. | |
| 135 return buffer->asNewNativeImage(); | |
| 136 } | 115 } |
| 137 | 116 |
| 138 float ImageSource::frameDurationAtIndex(size_t index) const | 117 float ImageSource::frameDurationAtIndex(size_t index) const |
| 139 { | 118 { |
| 140 if (!m_decoder) | 119 if (!m_decoder) |
| 141 return 0; | 120 return 0; |
| 142 | 121 |
| 143 // Many annoying ads specify a 0 duration to make an image flash as quickly
as possible. | 122 // Many annoying ads specify a 0 duration to make an image flash as quickly
as possible. |
| 144 // We follow Firefox's behavior and use a duration of 100 ms for any frames
that specify | 123 // We follow Firefox's behavior and use a duration of 100 ms for any frames
that specify |
| 145 // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.o
rg/b/36082> | 124 // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.o
rg/b/36082> |
| 146 // for more information. | 125 // for more information. |
| 147 const float duration = m_decoder->frameDurationAtIndex(index) / 1000.0f; | 126 const float duration = m_decoder->frameDurationAtIndex(index) / 1000.0f; |
| 148 if (duration < 0.011f) | 127 if (duration < 0.011f) |
| 149 return 0.100f; | 128 return 0.100f; |
| 150 return duration; | 129 return duration; |
| 151 } | 130 } |
| 152 | 131 |
| 153 ImageOrientation ImageSource::orientationAtIndex(size_t) const | 132 ImageOrientation ImageSource::orientationAtIndex(size_t index) const |
| 154 { | 133 { |
| 155 return m_decoder ? m_decoder->orientation() : DefaultImageOrientation; | 134 return m_decoder ? m_decoder->orientationAtIndex(index) : DefaultImageOrient
ation; |
| 156 } | 135 } |
| 157 | 136 |
| 158 bool ImageSource::frameHasAlphaAtIndex(size_t index) const | 137 bool ImageSource::frameHasAlphaAtIndex(size_t index) const |
| 159 { | 138 { |
| 160 return !m_decoder || m_decoder->frameHasAlphaAtIndex(index); | 139 return !m_decoder || m_decoder->frameHasAlphaAtIndex(index); |
| 161 } | 140 } |
| 162 | 141 |
| 163 bool ImageSource::frameIsCompleteAtIndex(size_t index) const | 142 bool ImageSource::frameIsCompleteAtIndex(size_t index) const |
| 164 { | 143 { |
| 165 return m_decoder && m_decoder->frameIsCompleteAtIndex(index); | 144 return m_decoder && m_decoder->frameIsCompleteAtIndex(index); |
| 166 } | 145 } |
| 167 | 146 |
| 168 unsigned ImageSource::frameBytesAtIndex(size_t index) const | 147 unsigned ImageSource::frameBytesAtIndex(size_t index) const |
| 169 { | 148 { |
| 170 return m_decoder ? m_decoder->frameBytesAtIndex(index) : 0; | 149 return m_decoder ? m_decoder->frameBytesAtIndex(index) : 0; |
| 171 } | 150 } |
| 172 | 151 |
| 173 } // namespace blink | 152 } // namespace blink |
| OLD | NEW |