OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_SRC_FXCRT_EXTENSION_H_ | 7 #ifndef CORE_SRC_FXCRT_EXTENSION_H_ |
8 #define CORE_SRC_FXCRT_EXTENSION_H_ | 8 #define CORE_SRC_FXCRT_EXTENSION_H_ |
9 | 9 |
10 #include "core/include/fxcrt/fx_basic.h" | 10 #include "core/include/fxcrt/fx_basic.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); | 97 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); |
98 } | 98 } |
99 ~CFX_MemoryStream() override { | 99 ~CFX_MemoryStream() override { |
100 if (m_dwFlags & FX_MEMSTREAM_TakeOver) { | 100 if (m_dwFlags & FX_MEMSTREAM_TakeOver) { |
101 for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { | 101 for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { |
102 FX_Free((uint8_t*)m_Blocks[i]); | 102 FX_Free((uint8_t*)m_Blocks[i]); |
103 } | 103 } |
104 } | 104 } |
105 m_Blocks.RemoveAll(); | 105 m_Blocks.RemoveAll(); |
106 } | 106 } |
107 virtual IFX_FileStream* Retain() override { | 107 |
| 108 // IFX_MemoryStream: |
| 109 IFX_FileStream* Retain() override { |
108 m_dwCount++; | 110 m_dwCount++; |
109 return this; | 111 return this; |
110 } | 112 } |
111 virtual void Release() override { | 113 void Release() override { |
112 FX_DWORD nCount = --m_dwCount; | 114 FX_DWORD nCount = --m_dwCount; |
113 if (nCount) { | 115 if (nCount) { |
114 return; | 116 return; |
115 } | 117 } |
116 delete this; | 118 delete this; |
117 } | 119 } |
118 virtual FX_FILESIZE GetSize() override { return (FX_FILESIZE)m_nCurSize; } | 120 FX_FILESIZE GetSize() override { return (FX_FILESIZE)m_nCurSize; } |
119 virtual FX_BOOL IsEOF() override { return m_nCurPos >= (size_t)GetSize(); } | 121 FX_BOOL IsEOF() override { return m_nCurPos >= (size_t)GetSize(); } |
120 virtual FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_nCurPos; } | 122 FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_nCurPos; } |
121 virtual FX_BOOL ReadBlock(void* buffer, | 123 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
122 FX_FILESIZE offset, | |
123 size_t size) override { | |
124 if (!buffer || !size) { | 124 if (!buffer || !size) { |
125 return FALSE; | 125 return FALSE; |
126 } | 126 } |
127 | 127 |
128 FX_SAFE_SIZE_T newPos = size; | 128 FX_SAFE_SIZE_T newPos = size; |
129 newPos += offset; | 129 newPos += offset; |
130 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || | 130 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || |
131 newPos.ValueOrDie() > m_nCurSize) { | 131 newPos.ValueOrDie() > m_nCurSize) { |
132 return FALSE; | 132 return FALSE; |
133 } | 133 } |
(...skipping 12 matching lines...) Expand all Loading... |
146 } | 146 } |
147 FXSYS_memcpy( | 147 FXSYS_memcpy( |
148 buffer, (uint8_t*)m_Blocks[(int)nStartBlock] + (size_t)offset, nRead); | 148 buffer, (uint8_t*)m_Blocks[(int)nStartBlock] + (size_t)offset, nRead); |
149 buffer = ((uint8_t*)buffer) + nRead; | 149 buffer = ((uint8_t*)buffer) + nRead; |
150 size -= nRead; | 150 size -= nRead; |
151 nStartBlock++; | 151 nStartBlock++; |
152 offset = 0; | 152 offset = 0; |
153 } | 153 } |
154 return TRUE; | 154 return TRUE; |
155 } | 155 } |
156 virtual size_t ReadBlock(void* buffer, size_t size) override { | 156 size_t ReadBlock(void* buffer, size_t size) override { |
157 if (m_nCurPos >= m_nCurSize) { | 157 if (m_nCurPos >= m_nCurSize) { |
158 return 0; | 158 return 0; |
159 } | 159 } |
160 size_t nRead = FX_MIN(size, m_nCurSize - m_nCurPos); | 160 size_t nRead = FX_MIN(size, m_nCurSize - m_nCurPos); |
161 if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) { | 161 if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) { |
162 return 0; | 162 return 0; |
163 } | 163 } |
164 return nRead; | 164 return nRead; |
165 } | 165 } |
166 virtual FX_BOOL WriteBlock(const void* buffer, | 166 FX_BOOL WriteBlock(const void* buffer, |
167 FX_FILESIZE offset, | 167 FX_FILESIZE offset, |
168 size_t size) override { | 168 size_t size) override { |
169 if (!buffer || !size) { | 169 if (!buffer || !size) { |
170 return FALSE; | 170 return FALSE; |
171 } | 171 } |
172 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { | 172 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { |
173 FX_SAFE_SIZE_T newPos = size; | 173 FX_SAFE_SIZE_T newPos = size; |
174 newPos += offset; | 174 newPos += offset; |
175 if (!newPos.IsValid()) | 175 if (!newPos.IsValid()) |
176 return FALSE; | 176 return FALSE; |
177 | 177 |
178 m_nCurPos = newPos.ValueOrDie(); | 178 m_nCurPos = newPos.ValueOrDie(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 FXSYS_memcpy((uint8_t*)m_Blocks[(int)nStartBlock] + (size_t)offset, | 217 FXSYS_memcpy((uint8_t*)m_Blocks[(int)nStartBlock] + (size_t)offset, |
218 buffer, nWrite); | 218 buffer, nWrite); |
219 buffer = ((uint8_t*)buffer) + nWrite; | 219 buffer = ((uint8_t*)buffer) + nWrite; |
220 size -= nWrite; | 220 size -= nWrite; |
221 nStartBlock++; | 221 nStartBlock++; |
222 offset = 0; | 222 offset = 0; |
223 } | 223 } |
224 return TRUE; | 224 return TRUE; |
225 } | 225 } |
226 virtual FX_BOOL Flush() override { return TRUE; } | 226 FX_BOOL Flush() override { return TRUE; } |
227 virtual FX_BOOL IsConsecutive() const override { | 227 FX_BOOL IsConsecutive() const override { |
228 return m_dwFlags & FX_MEMSTREAM_Consecutive; | 228 return m_dwFlags & FX_MEMSTREAM_Consecutive; |
229 } | 229 } |
230 virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) override { | 230 void EstimateSize(size_t nInitSize, size_t nGrowSize) override { |
231 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { | 231 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { |
232 if (m_Blocks.GetSize() < 1) { | 232 if (m_Blocks.GetSize() < 1) { |
233 uint8_t* pBlock = FX_Alloc(uint8_t, FX_MAX(nInitSize, 4096)); | 233 uint8_t* pBlock = FX_Alloc(uint8_t, FX_MAX(nInitSize, 4096)); |
234 m_Blocks.Add(pBlock); | 234 m_Blocks.Add(pBlock); |
235 } | 235 } |
236 m_nGrowSize = FX_MAX(nGrowSize, 4096); | 236 m_nGrowSize = FX_MAX(nGrowSize, 4096); |
237 } else if (m_Blocks.GetSize() < 1) { | 237 } else if (m_Blocks.GetSize() < 1) { |
238 m_nGrowSize = FX_MAX(nGrowSize, 4096); | 238 m_nGrowSize = FX_MAX(nGrowSize, 4096); |
239 } | 239 } |
240 } | 240 } |
241 virtual uint8_t* GetBuffer() const override { | 241 uint8_t* GetBuffer() const override { |
242 return m_Blocks.GetSize() ? (uint8_t*)m_Blocks[0] : NULL; | 242 return m_Blocks.GetSize() ? (uint8_t*)m_Blocks[0] : NULL; |
243 } | 243 } |
244 virtual void AttachBuffer(uint8_t* pBuffer, | 244 void AttachBuffer(uint8_t* pBuffer, |
245 size_t nSize, | 245 size_t nSize, |
246 FX_BOOL bTakeOver = FALSE) override { | 246 FX_BOOL bTakeOver = FALSE) override { |
247 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { | 247 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { |
248 return; | 248 return; |
249 } | 249 } |
250 m_Blocks.RemoveAll(); | 250 m_Blocks.RemoveAll(); |
251 m_Blocks.Add(pBuffer); | 251 m_Blocks.Add(pBuffer); |
252 m_nTotalSize = m_nCurSize = nSize; | 252 m_nTotalSize = m_nCurSize = nSize; |
253 m_nCurPos = 0; | 253 m_nCurPos = 0; |
254 m_dwFlags = | 254 m_dwFlags = |
255 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); | 255 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); |
256 } | 256 } |
257 virtual void DetachBuffer() override { | 257 void DetachBuffer() override { |
258 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { | 258 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { |
259 return; | 259 return; |
260 } | 260 } |
261 m_Blocks.RemoveAll(); | 261 m_Blocks.RemoveAll(); |
262 m_nTotalSize = m_nCurSize = m_nCurPos = 0; | 262 m_nTotalSize = m_nCurSize = m_nCurPos = 0; |
263 m_dwFlags = FX_MEMSTREAM_TakeOver; | 263 m_dwFlags = FX_MEMSTREAM_TakeOver; |
264 } | 264 } |
265 | 265 |
266 protected: | 266 protected: |
267 CFX_PtrArray m_Blocks; | 267 CFX_PtrArray m_Blocks; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; | 309 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; |
310 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; | 310 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; |
311 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 311 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
312 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); | 312 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); |
313 #endif | 313 #endif |
314 #ifdef __cplusplus | 314 #ifdef __cplusplus |
315 } | 315 } |
316 #endif | 316 #endif |
317 | 317 |
318 #endif // CORE_SRC_FXCRT_EXTENSION_H_ | 318 #endif // CORE_SRC_FXCRT_EXTENSION_H_ |
OLD | NEW |