1 | /* |
2 | * Copyright (C) 2016 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. ``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 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 | #pragma once |
27 | |
28 | #include "Color.h" |
29 | #include "DecodingOptions.h" |
30 | #include "ImageBackingStore.h" |
31 | #include "ImageOrientation.h" |
32 | #include "ImageTypes.h" |
33 | #include "IntSize.h" |
34 | #include "NativeImage.h" |
35 | #include <wtf/Seconds.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | class ScalableImageDecoderFrame { |
40 | public: |
41 | ScalableImageDecoderFrame(); |
42 | ScalableImageDecoderFrame(const ScalableImageDecoderFrame& other) { operator=(other); } |
43 | |
44 | ~ScalableImageDecoderFrame(); |
45 | |
46 | ScalableImageDecoderFrame& operator=(const ScalableImageDecoderFrame& other); |
47 | |
48 | void clear(); |
49 | |
50 | bool initialize(const ImageBackingStore&); |
51 | bool initialize(const IntSize&, bool premultiplyAlpha); |
52 | |
53 | void setDecodingStatus(DecodingStatus); |
54 | DecodingStatus decodingStatus() const; |
55 | |
56 | bool isInvalid() const { return m_decodingStatus == DecodingStatus::Invalid; } |
57 | bool isPartial() const { return m_decodingStatus == DecodingStatus::Partial; } |
58 | bool isComplete() const { return m_decodingStatus == DecodingStatus::Complete; } |
59 | |
60 | IntSize size() const; |
61 | |
62 | enum class DisposalMethod { Unspecified, DoNotDispose, RestoreToBackground, RestoreToPrevious }; |
63 | void setDisposalMethod(DisposalMethod method) { m_disposalMethod = method; } |
64 | DisposalMethod disposalMethod() const { return m_disposalMethod; } |
65 | |
66 | void setOrientation(ImageOrientation orientation) { m_orientation = orientation; }; |
67 | ImageOrientation orientation() const { return m_orientation; } |
68 | |
69 | void setDuration(const Seconds& duration) { m_duration = duration; } |
70 | Seconds duration() const { return m_duration; } |
71 | |
72 | void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } |
73 | bool hasAlpha() const { return !hasMetadata() || m_hasAlpha; } |
74 | bool hasMetadata() const { return !size().isEmpty(); } |
75 | |
76 | ImageBackingStore* backingStore() const { return m_backingStore ? m_backingStore.get() : nullptr; } |
77 | bool hasBackingStore() const { return backingStore(); } |
78 | |
79 | private: |
80 | DecodingStatus m_decodingStatus { DecodingStatus::Invalid }; |
81 | |
82 | std::unique_ptr<ImageBackingStore> m_backingStore; |
83 | DisposalMethod m_disposalMethod { DisposalMethod::Unspecified }; |
84 | |
85 | ImageOrientation m_orientation { DefaultImageOrientation }; |
86 | Seconds m_duration; |
87 | bool m_hasAlpha { true }; |
88 | }; |
89 | |
90 | } |
91 | |