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 "../../include/fxcrt/fx_basic.h" | 10 #include "../../include/fxcrt/fx_basic.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; | 23 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; |
24 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; | 24 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; |
25 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; | 25 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; |
26 virtual size_t WritePos(const void* pBuffer, | 26 virtual size_t WritePos(const void* pBuffer, |
27 size_t szBuffer, | 27 size_t szBuffer, |
28 FX_FILESIZE pos) = 0; | 28 FX_FILESIZE pos) = 0; |
29 virtual FX_BOOL Flush() = 0; | 29 virtual FX_BOOL Flush() = 0; |
30 virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; | 30 virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; |
31 }; | 31 }; |
32 IFXCRT_FileAccess* FXCRT_FileAccess_Create(); | 32 IFXCRT_FileAccess* FXCRT_FileAccess_Create(); |
| 33 |
33 class CFX_CRTFileStream final : public IFX_FileStream { | 34 class CFX_CRTFileStream final : public IFX_FileStream { |
34 public: | 35 public: |
35 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {} | 36 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {} |
36 ~CFX_CRTFileStream() { | 37 ~CFX_CRTFileStream() override { |
37 if (m_pFile) { | 38 if (m_pFile) { |
38 m_pFile->Release(); | 39 m_pFile->Release(); |
39 } | 40 } |
40 } | 41 } |
41 virtual IFX_FileStream* Retain() override { | 42 virtual IFX_FileStream* Retain() override { |
42 m_dwCount++; | 43 m_dwCount++; |
43 return this; | 44 return this; |
44 } | 45 } |
45 virtual void Release() override { | 46 virtual void Release() override { |
46 FX_DWORD nCount = --m_dwCount; | 47 FX_DWORD nCount = --m_dwCount; |
(...skipping 16 matching lines...) Expand all Loading... |
63 FX_FILESIZE offset, | 64 FX_FILESIZE offset, |
64 size_t size) override { | 65 size_t size) override { |
65 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); | 66 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); |
66 } | 67 } |
67 virtual FX_BOOL Flush() override { return m_pFile->Flush(); } | 68 virtual FX_BOOL Flush() override { return m_pFile->Flush(); } |
68 | 69 |
69 protected: | 70 protected: |
70 IFXCRT_FileAccess* m_pFile; | 71 IFXCRT_FileAccess* m_pFile; |
71 FX_DWORD m_dwCount; | 72 FX_DWORD m_dwCount; |
72 }; | 73 }; |
| 74 |
73 #define FX_MEMSTREAM_BlockSize (64 * 1024) | 75 #define FX_MEMSTREAM_BlockSize (64 * 1024) |
74 #define FX_MEMSTREAM_Consecutive 0x01 | 76 #define FX_MEMSTREAM_Consecutive 0x01 |
75 #define FX_MEMSTREAM_TakeOver 0x02 | 77 #define FX_MEMSTREAM_TakeOver 0x02 |
76 class CFX_MemoryStream final : public IFX_MemoryStream { | 78 class CFX_MemoryStream final : public IFX_MemoryStream { |
77 public: | 79 public: |
78 CFX_MemoryStream(FX_BOOL bConsecutive) | 80 CFX_MemoryStream(FX_BOOL bConsecutive) |
79 : m_dwCount(1), | 81 : m_dwCount(1), |
80 m_nTotalSize(0), | 82 m_nTotalSize(0), |
81 m_nCurSize(0), | 83 m_nCurSize(0), |
82 m_nCurPos(0), | 84 m_nCurPos(0), |
83 m_nGrowSize(FX_MEMSTREAM_BlockSize) { | 85 m_nGrowSize(FX_MEMSTREAM_BlockSize) { |
84 m_dwFlags = | 86 m_dwFlags = |
85 FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); | 87 FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); |
86 } | 88 } |
87 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver) | 89 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver) |
88 : m_dwCount(1), | 90 : m_dwCount(1), |
89 m_nTotalSize(nSize), | 91 m_nTotalSize(nSize), |
90 m_nCurSize(nSize), | 92 m_nCurSize(nSize), |
91 m_nCurPos(0), | 93 m_nCurPos(0), |
92 m_nGrowSize(FX_MEMSTREAM_BlockSize) { | 94 m_nGrowSize(FX_MEMSTREAM_BlockSize) { |
93 m_Blocks.Add(pBuffer); | 95 m_Blocks.Add(pBuffer); |
94 m_dwFlags = | 96 m_dwFlags = |
95 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); | 97 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); |
96 } | 98 } |
97 ~CFX_MemoryStream() { | 99 ~CFX_MemoryStream() override { |
98 if (m_dwFlags & FX_MEMSTREAM_TakeOver) { | 100 if (m_dwFlags & FX_MEMSTREAM_TakeOver) { |
99 for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { | 101 for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { |
100 FX_Free((uint8_t*)m_Blocks[i]); | 102 FX_Free((uint8_t*)m_Blocks[i]); |
101 } | 103 } |
102 } | 104 } |
103 m_Blocks.RemoveAll(); | 105 m_Blocks.RemoveAll(); |
104 } | 106 } |
105 virtual IFX_FileStream* Retain() override { | 107 virtual IFX_FileStream* Retain() override { |
106 m_dwCount++; | 108 m_dwCount++; |
107 return this; | 109 return this; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; | 282 size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; |
281 m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); | 283 m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); |
282 while (size--) { | 284 while (size--) { |
283 uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); | 285 uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); |
284 m_Blocks.SetAt(iCount++, pBlock); | 286 m_Blocks.SetAt(iCount++, pBlock); |
285 m_nTotalSize += m_nGrowSize; | 287 m_nTotalSize += m_nGrowSize; |
286 } | 288 } |
287 return TRUE; | 289 return TRUE; |
288 } | 290 } |
289 }; | 291 }; |
| 292 |
290 #ifdef __cplusplus | 293 #ifdef __cplusplus |
291 extern "C" { | 294 extern "C" { |
292 #endif | 295 #endif |
293 #define MT_N 848 | 296 #define MT_N 848 |
294 #define MT_M 456 | 297 #define MT_M 456 |
295 #define MT_Matrix_A 0x9908b0df | 298 #define MT_Matrix_A 0x9908b0df |
296 #define MT_Upper_Mask 0x80000000 | 299 #define MT_Upper_Mask 0x80000000 |
297 #define MT_Lower_Mask 0x7fffffff | 300 #define MT_Lower_Mask 0x7fffffff |
298 typedef struct _FX_MTRANDOMCONTEXT { | 301 typedef struct _FX_MTRANDOMCONTEXT { |
299 _FX_MTRANDOMCONTEXT() { | 302 _FX_MTRANDOMCONTEXT() { |
300 mti = MT_N + 1; | 303 mti = MT_N + 1; |
301 bHaveSeed = FALSE; | 304 bHaveSeed = FALSE; |
302 } | 305 } |
303 FX_DWORD mti; | 306 FX_DWORD mti; |
304 FX_BOOL bHaveSeed; | 307 FX_BOOL bHaveSeed; |
305 FX_DWORD mt[MT_N]; | 308 FX_DWORD mt[MT_N]; |
306 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; | 309 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; |
307 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; | 310 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; |
308 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 311 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
309 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); | 312 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); |
310 #endif | 313 #endif |
311 #ifdef __cplusplus | 314 #ifdef __cplusplus |
312 } | 315 } |
313 #endif | 316 #endif |
314 | 317 |
315 #endif // CORE_SRC_FXCRT_EXTENSION_H_ | 318 #endif // CORE_SRC_FXCRT_EXTENSION_H_ |
OLD | NEW |