1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_IMAGE_DECODER_EXTERNAL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_IMAGE_DECODER_EXTERNAL_H_
#include <memory>
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/loader/fetch/bytes_consumer.h"
namespace blink {
class ExceptionState;
class ScriptState;
class ImageBitmapOptions;
class ImageDecoder;
class ImageDecoderInit;
class ReadableStreamBytesConsumer;
class ScriptPromiseResolver;
class SegmentReader;
class MODULES_EXPORT ImageDecoderExternal final : public ScriptWrappable,
public BytesConsumer::Client {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(ImageDecoderExternal);
public:
static ImageDecoderExternal* Create(ScriptState*,
const ImageDecoderInit*,
ExceptionState&);
ImageDecoderExternal(ScriptState*, const ImageDecoderInit*, ExceptionState&);
~ImageDecoderExternal() override;
// image_decoder.idl implementation.
ScriptPromise decode(uint32_t frame_index, bool complete_frames_only);
uint32_t frameCount() const;
String type() const;
uint32_t repetitionCount() const;
bool complete() const;
// BytesConsumer::Client implementation.
void OnStateChange() override;
String DebugName() const override;
// GarbageCollected override.
void Trace(Visitor*) override;
private:
void MaybeSatisfyPendingDecodes();
void MaybeCreateImageDecoder(scoped_refptr<SegmentReader> sr);
void UpdateFrameAndRepetitionCount();
Member<ScriptState> script_state_;
// Used when a ReadableStream is provided.
Member<ReadableStreamBytesConsumer> consumer_;
scoped_refptr<SharedBuffer> stream_buffer_;
// Construction parameters.
Member<const ImageDecoderInit> init_data_;
Member<const ImageBitmapOptions> options_;
bool data_complete_ = false;
std::unique_ptr<ImageDecoder> decoder_;
String mime_type_;
uint32_t frame_count_ = 0u;
uint32_t repetition_count_ = 0u;
// Pending decode() requests.
struct DecodeRequest : public GarbageCollected<DecodeRequest> {
DecodeRequest(ScriptPromiseResolver* resolver,
uint32_t frame_index,
bool complete_frames_only);
void Trace(Visitor*);
Member<ScriptPromiseResolver> resolver;
uint32_t frame_index;
bool complete_frames_only;
bool complete = false;
};
HeapVector<Member<DecodeRequest>> pending_decodes_;
// When decode() of incomplete frames has been requested, we need to track the
// generation id for each SkBitmap that we've handed out. So that we can defer
// resolution of promises until a new bitmap is generated.
HashMap<uint32_t,
uint32_t,
DefaultHash<uint32_t>::Hash,
WTF::UnsignedWithZeroKeyHashTraits<uint32_t>>
incomplete_frames_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_IMAGE_DECODER_EXTERNAL_H_
|