| 1 | /* |
| 2 | * Copyright (C) 2017-2018 Apple 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 INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "DecodingOptions.h" |
| 29 | #include "ImageOrientation.h" |
| 30 | #include "ImageTypes.h" |
| 31 | #include "IntPoint.h" |
| 32 | #include "IntSize.h" |
| 33 | #include "NativeImage.h" |
| 34 | #include <wtf/Optional.h> |
| 35 | #include <wtf/Seconds.h> |
| 36 | #include <wtf/text/WTFString.h> |
| 37 | #include <wtf/ThreadSafeRefCounted.h> |
| 38 | |
| 39 | namespace WebCore { |
| 40 | |
| 41 | class SharedBuffer; |
| 42 | |
| 43 | class ImageDecoder : public ThreadSafeRefCounted<ImageDecoder> { |
| 44 | WTF_MAKE_FAST_ALLOCATED; |
| 45 | public: |
| 46 | static RefPtr<ImageDecoder> create(SharedBuffer&, const String& mimeType, AlphaOption, GammaAndColorProfileOption); |
| 47 | virtual ~ImageDecoder() = default; |
| 48 | |
| 49 | enum class MediaType { |
| 50 | Image, |
| 51 | Video, |
| 52 | }; |
| 53 | static bool supportsMediaType(MediaType); |
| 54 | |
| 55 | virtual size_t bytesDecodedToDetermineProperties() const = 0; |
| 56 | |
| 57 | virtual EncodedDataStatus encodedDataStatus() const = 0; |
| 58 | virtual void setEncodedDataStatusChangeCallback(WTF::Function<void(EncodedDataStatus)>&&) { } |
| 59 | virtual bool isSizeAvailable() const { return encodedDataStatus() >= EncodedDataStatus::SizeAvailable; } |
| 60 | virtual IntSize size() const = 0; |
| 61 | virtual size_t frameCount() const = 0; |
| 62 | virtual RepetitionCount repetitionCount() const = 0; |
| 63 | virtual String uti() const { return emptyString(); } |
| 64 | virtual String filenameExtension() const = 0; |
| 65 | virtual Optional<IntPoint> hotSpot() const = 0; |
| 66 | |
| 67 | virtual IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const = 0; |
| 68 | virtual bool frameIsCompleteAtIndex(size_t) const = 0; |
| 69 | virtual ImageOrientation frameOrientationAtIndex(size_t) const = 0; |
| 70 | |
| 71 | virtual Seconds frameDurationAtIndex(size_t) const = 0; |
| 72 | virtual bool frameHasAlphaAtIndex(size_t) const = 0; |
| 73 | virtual bool frameAllowSubsamplingAtIndex(size_t) const = 0; |
| 74 | virtual unsigned frameBytesAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const = 0; |
| 75 | |
| 76 | virtual NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default, const DecodingOptions& = DecodingOptions(DecodingMode::Synchronous)) = 0; |
| 77 | |
| 78 | virtual void setExpectedContentSize(long long) { } |
| 79 | virtual void setData(SharedBuffer&, bool allDataReceived) = 0; |
| 80 | virtual bool isAllDataReceived() const = 0; |
| 81 | virtual void clearFrameBufferCache(size_t) = 0; |
| 82 | |
| 83 | #if USE(DIRECT2D) |
| 84 | virtual void setTargetContext(ID2D1RenderTarget*) = 0; |
| 85 | #endif |
| 86 | |
| 87 | protected: |
| 88 | ImageDecoder() = default; |
| 89 | }; |
| 90 | |
| 91 | } |
| 92 | |