| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 class SharedBuffer; | 46 class SharedBuffer; |
| 47 | 47 |
| 48 class ImageDecoderFactory { | 48 class ImageDecoderFactory { |
| 49 public: | 49 public: |
| 50 virtual ~ImageDecoderFactory() { } | 50 virtual ~ImageDecoderFactory() { } |
| 51 virtual PassOwnPtr<ImageDecoder> create() = 0; | 51 virtual PassOwnPtr<ImageDecoder> create() = 0; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 class ImageFrameGenerator : public ThreadSafeRefCounted<ImageFrameGenerator> { | 54 class ImageFrameGenerator : public ThreadSafeRefCounted<ImageFrameGenerator> { |
| 55 public: | 55 public: |
| 56 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, PassR
efPtr<SharedBuffer> data, bool allDataReceived) | 56 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, PassR
efPtr<SharedBuffer> data, bool allDataReceived, bool isMultiFrame = false) |
| 57 { | 57 { |
| 58 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived)
); | 58 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived,
isMultiFrame)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool
allDataReceived); | 61 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool
allDataReceived, bool isMultiFrame); |
| 62 ~ImageFrameGenerator(); | 62 ~ImageFrameGenerator(); |
| 63 | 63 |
| 64 const ScaledImageFragment* decodeAndScale(const SkISize& scaledSize); | 64 const ScaledImageFragment* decodeAndScale(const SkISize& scaledSize, size_t
index = 0); |
| 65 | 65 |
| 66 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); | 66 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); |
| 67 | 67 |
| 68 // Creates a new SharedBuffer containing the data received so far. | 68 // Creates a new SharedBuffer containing the data received so far. |
| 69 void copyData(RefPtr<SharedBuffer>*, bool* allDataReceived); | 69 void copyData(RefPtr<SharedBuffer>*, bool* allDataReceived); |
| 70 | 70 |
| 71 SkISize getFullSize() const { return m_fullSize; } | 71 SkISize getFullSize() const { return m_fullSize; } |
| 72 | 72 |
| 73 bool isMultiFrame() const { return m_isMultiFrame; } |
| 74 |
| 73 void setImageDecoderFactoryForTesting(PassOwnPtr<ImageDecoderFactory> factor
y) { m_imageDecoderFactory = factory; } | 75 void setImageDecoderFactoryForTesting(PassOwnPtr<ImageDecoderFactory> factor
y) { m_imageDecoderFactory = factory; } |
| 74 | 76 |
| 77 // FIXME: Return alpha state for each frame. |
| 75 bool hasAlpha(); | 78 bool hasAlpha(); |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 // These methods are called while m_decodeMutex is locked. | 81 // These methods are called while m_decodeMutex is locked. |
| 79 const ScaledImageFragment* tryToLockCompleteCache(const SkISize& scaledSize)
; | 82 const ScaledImageFragment* tryToLockCompleteCache(const SkISize& scaledSize,
size_t index); |
| 80 const ScaledImageFragment* tryToScale(const ScaledImageFragment* fullSizeIma
ge, const SkISize& scaledSize); | 83 const ScaledImageFragment* tryToScale(const ScaledImageFragment* fullSizeIma
ge, const SkISize& scaledSize, size_t index); |
| 81 const ScaledImageFragment* tryToResumeDecodeAndScale(const SkISize& scaledSi
ze); | 84 const ScaledImageFragment* tryToResumeDecodeAndScale(const SkISize& scaledSi
ze, size_t index); |
| 82 const ScaledImageFragment* tryToDecodeAndScale(const SkISize& scaledSize); | 85 const ScaledImageFragment* tryToDecodeAndScale(const SkISize& scaledSize, si
ze_t index); |
| 83 | 86 |
| 84 // Use the given decoder to decode. If a decoder is not given then try to cr
eate one. | 87 // Use the given decoder to decode. If a decoder is not given then try to cr
eate one. |
| 85 PassOwnPtr<ScaledImageFragment> decode(ImageDecoder**); | 88 PassOwnPtr<ScaledImageFragment> decode(size_t index, ImageDecoder**); |
| 86 | 89 |
| 87 // Return the next generation ID of a new image object. This is used | 90 // Return the next generation ID of a new image object. This is used |
| 88 // to identify images of the same frame from different stages of | 91 // to identify images of the same frame from different stages of |
| 89 // progressive decode. | 92 // progressive decode. |
| 90 size_t nextGenerationId() { return m_decodeCount++; } | 93 size_t nextGenerationId() { return m_decodeCount++; } |
| 91 | 94 |
| 92 SkISize m_fullSize; | 95 SkISize m_fullSize; |
| 93 ThreadSafeDataTransport m_data; | 96 ThreadSafeDataTransport m_data; |
| 97 bool m_isMultiFrame; |
| 94 bool m_decodeFailedAndEmpty; | 98 bool m_decodeFailedAndEmpty; |
| 95 bool m_hasAlpha; | 99 bool m_hasAlpha; |
| 96 size_t m_decodeCount; | 100 size_t m_decodeCount; |
| 97 DiscardablePixelRefAllocator m_allocator; | 101 DiscardablePixelRefAllocator m_allocator; |
| 98 | 102 |
| 99 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; | 103 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; |
| 100 | 104 |
| 101 // Prevents multiple decode operations on the same data. | 105 // Prevents multiple decode operations on the same data. |
| 102 Mutex m_decodeMutex; | 106 Mutex m_decodeMutex; |
| 103 | 107 |
| 104 // Protect concurrent access to m_hasAlpha. | 108 // Protect concurrent access to m_hasAlpha. |
| 105 Mutex m_alphaMutex; | 109 Mutex m_alphaMutex; |
| 106 }; | 110 }; |
| 107 | 111 |
| 108 } // namespace WebCore | 112 } // namespace WebCore |
| 109 | 113 |
| 110 #endif | 114 #endif |
| OLD | NEW |