Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfx_codec_memory.cpp
Go to the documentation of this file.
1
// Copyright 2018 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#
include
"core/fxcodec/cfx_codec_memory.h"
6
7
#
include
<
algorithm
>
8
9
#
include
"core/fxcrt/span_util.h"
10
#
include
"core/fxcrt/stl_util.h"
11
12
CFX_CodecMemory::CFX_CodecMemory(size_t buffer_size)
13
: buffer_(FX_Alloc(uint8_t, buffer_size)), size_(buffer_size) {}
14
15
CFX_CodecMemory::~
CFX_CodecMemory
() =
default
;
16
17
bool
CFX_CodecMemory::
Seek
(size_t pos) {
18
if
(pos > size_)
19
return
false
;
20
21
pos_ = pos;
22
return
true
;
23
}
24
25
size_t
CFX_CodecMemory::
ReadBlock
(pdfium::span<uint8_t> buffer) {
26
if
(buffer.empty() ||
IsEOF
(
)
)
27
return
0;
28
29
size_t bytes_to_read =
std
::min(buffer.size(), size_ - pos_);
30
fxcrt
::Copy(GetBufferSpan().subspan(pos_, bytes_to_read), buffer);
31
pos_ += bytes_to_read;
32
return
bytes_to_read;
33
}
34
35
bool
CFX_CodecMemory::
TryResize
(size_t new_buffer_size) {
36
uint8_t* pOldBuf = buffer_.release();
37
uint8_t* pNewBuf = FX_TryRealloc(uint8_t, pOldBuf, new_buffer_size);
38
if
(new_buffer_size && !pNewBuf) {
39
buffer_.reset(pOldBuf);
40
return
false
;
41
}
42
buffer_.reset(pNewBuf);
43
size_ = new_buffer_size;
44
return
true
;
45
}
46
47
void
CFX_CodecMemory::
Consume
(size_t consumed) {
48
fxcrt
::spanmove(GetBufferSpan(), GetBufferSpan().subspan(consumed));
49
}
CFX_CodecMemory::TryResize
bool TryResize(size_t new_buffer_size)
Definition
cfx_codec_memory.cpp:35
CFX_CodecMemory::IsEOF
bool IsEOF() const
Definition
cfx_codec_memory.h:30
CFX_CodecMemory::~CFX_CodecMemory
~CFX_CodecMemory() override
CFX_CodecMemory::ReadBlock
size_t ReadBlock(pdfium::span< uint8_t > buffer)
Definition
cfx_codec_memory.cpp:25
CFX_CodecMemory::Seek
bool Seek(size_t pos)
Definition
cfx_codec_memory.cpp:17
CFX_CodecMemory::Consume
void Consume(size_t consumed)
Definition
cfx_codec_memory.cpp:47
fxcrt
Definition
stl_util.h:17
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcodec
cfx_codec_memory.cpp
Generated on
for Qt by
1.18.0