1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef DeferredImageDecoder_h 27 #define DeferredImageDecoder_h 28 29 #include "SkBitmap.h" 30 #include "core/platform/graphics/ImageSource.h" 31 #include "core/platform/graphics/IntSize.h" 32 #include "core/platform/image-decoders/ImageDecoder.h" 33 #include "wtf/Forward.h" 34 #include "wtf/OwnPtr.h" 35 #include "wtf/Vector.h" 36 37 namespace WebCore { 38 39 class ImageFrameGenerator; 40 class SharedBuffer; 41 42 class DeferredImageDecoder { 43 public: 44 ~DeferredImageDecoder(); 45 static PassOwnPtr<DeferredImageDecoder> create(const SharedBuffer& data, ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption); 46 47 static PassOwnPtr<DeferredImageDecoder> createForTesting(PassOwnPtr<ImageDecoder>); 48 49 static bool isLazyDecoded(const SkBitmap&); 50 51 static SkBitmap createResizedLazyDecodingBitmap(const SkBitmap&, const SkISize& scaledSize, const SkIRect& scaledSubset); 52 53 static void setEnabled(bool); 54 55 String filenameExtension() const; 56 57 ImageFrame* frameBufferAtIndex(size_t index); 58 59 void setData(SharedBuffer* data, bool allDataReceived); 60 61 bool isSizeAvailable(); 62 IntSize size() const; 63 IntSize frameSizeAtIndex(size_t index) const; 64 size_t frameCount(); 65 int repetitionCount() const; 66 size_t clearCacheExceptFrame(size_t); 67 bool frameHasAlphaAtIndex(size_t index) const; 68 bool frameIsCompleteAtIndex(size_t) const; 69 float frameDurationAtIndex(size_t) const; 70 unsigned frameBytesAtIndex(size_t index) const; 71 ImageOrientation orientation() const; 72 bool hotSpot(IntPoint&) const; 73 74 private: 75 explicit DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecoder); 76 void prepareLazyDecodedFrames(); 77 SkBitmap createLazyDecodingBitmap(size_t index); 78 void activateLazyDecoding(); 79 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); 80 81 RefPtr<SharedBuffer> m_data; 82 bool m_allDataReceived; 83 OwnPtr<ImageDecoder> m_actualDecoder; 84 85 String m_filenameExtension; 86 IntSize m_size; 87 ImageOrientation m_orientation; 88 int m_repetitionCount; 89 90 Vector<OwnPtr<ImageFrame> > m_lazyDecodedFrames; 91 RefPtr<ImageFrameGenerator> m_frameGenerator; 92 93 static bool s_enabled; 94 }; 95 96 } // namespace WebCore 97 98 #endif 99