summaryrefslogtreecommitdiff
path: root/core/fxge
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-07 09:21:17 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-07 09:21:18 -0800
commit833619b4441915c7c55085d44b3221eaef0d9800 (patch)
tree68bf76e83078223ba03f490c2c13f484e40154d4 /core/fxge
parent8f875507a986d10335e40a5f7c1679aff9770d0a (diff)
downloadpdfium-833619b4441915c7c55085d44b3221eaef0d9800.tar.xz
Refcount all the IFX_ stream classes all the time.
We can remove a lot of "bOwnsStream" logic in the process. Always pass these by const reference, in case the called method wants to hang on to the stream (one exception is where we stick a raw pointer into a void* slot in a context from another layer). Review-Url: https://codereview.chromium.org/2451493002
Diffstat (limited to 'core/fxge')
-rw-r--r--core/fxge/android/cfpf_skiafilefont.h6
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.cpp20
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.h2
-rw-r--r--core/fxge/fx_font.h2
-rw-r--r--core/fxge/ge/cfx_font.cpp18
5 files changed, 30 insertions, 18 deletions
diff --git a/core/fxge/android/cfpf_skiafilefont.h b/core/fxge/android/cfpf_skiafilefont.h
index b6657bf978..2c9fc90ad2 100644
--- a/core/fxge/android/cfpf_skiafilefont.h
+++ b/core/fxge/android/cfpf_skiafilefont.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_
#define CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxge/android/cfpf_skiafontdescriptor.h"
class IFX_SeekableReadStream;
@@ -15,11 +16,12 @@ class IFX_SeekableReadStream;
class CFPF_SkiaFileFont : public CFPF_SkiaFontDescriptor {
public:
- CFPF_SkiaFileFont() : m_pFile(nullptr) {}
+ CFPF_SkiaFileFont() {}
// CFPF_SkiaFontDescriptor
int32_t GetType() const override { return FPF_SKIAFONTTYPE_File; }
- IFX_SeekableReadStream* m_pFile;
+
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFile;
};
#endif // CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index 6463e8b531..e3511be67a 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -28,14 +28,17 @@ static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream,
unsigned long offset,
unsigned char* buffer,
unsigned long count) {
+ if (count == 0)
+ return 0;
+
IFX_SeekableReadStream* pFileRead =
- (IFX_SeekableReadStream*)stream->descriptor.pointer;
+ static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer);
if (!pFileRead)
return 0;
- if (count > 0) {
- if (!pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count))
- return 0;
- }
+
+ if (!pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count))
+ return 0;
+
return count;
}
@@ -358,8 +361,9 @@ CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname,
return nullptr;
}
-FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_SeekableReadStream* pFileRead,
- int32_t iFaceIndex) {
+FXFT_Face CFPF_SkiaFontMgr::GetFontFace(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
+ int32_t iFaceIndex) {
if (!pFileRead)
return nullptr;
if (pFileRead->GetSize() == 0)
@@ -369,7 +373,7 @@ FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_SeekableReadStream* pFileRead,
FXFT_StreamRec streamRec;
FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec));
streamRec.size = pFileRead->GetSize();
- streamRec.descriptor.pointer = pFileRead;
+ streamRec.descriptor.pointer = static_cast<void*>(pFileRead.Get());
streamRec.read = FPF_SkiaStream_Read;
streamRec.close = FPF_SkiaStream_Close;
FXFT_Open_Args args;
diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h
index 7d89c6edb8..4d0ea0e0d2 100644
--- a/core/fxge/android/cfpf_skiafontmgr.h
+++ b/core/fxge/android/cfpf_skiafontmgr.h
@@ -31,7 +31,7 @@ class CFPF_SkiaFontMgr {
uint32_t dwMatch = 0);
bool InitFTLibrary();
- FXFT_Face GetFontFace(IFX_SeekableReadStream* pFileRead,
+ FXFT_Face GetFontFace(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
int32_t iFaceIndex = 0);
FXFT_Face GetFontFace(const CFX_ByteStringC& bsFile, int32_t iFaceIndex = 0);
FXFT_Face GetFontFace(const uint8_t* pBuffer,
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index 6bb4bdea34..96396af15e 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -111,7 +111,7 @@ class CFX_Font {
CFX_SubstFont* GetSubstFont() const { return m_pSubstFont.get(); }
#ifdef PDF_ENABLE_XFA
- bool LoadFile(IFX_SeekableReadStream* pFile,
+ bool LoadFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
int nFaceIndex = 0,
int* pFaceCount = nullptr);
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index b85709040b..7be300ff66 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -47,21 +47,27 @@ unsigned long FTStreamRead(FXFT_Stream stream,
IFX_SeekableReadStream* pFile =
static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer);
- return pFile->ReadBlock(buffer, offset, count) ? count : 0;
+ if (!pFile)
+ return 0;
+
+ if (!pFile->ReadBlock(buffer, offset, count))
+ return 0;
+
+ return count;
}
void FTStreamClose(FXFT_Stream stream) {}
bool LoadFileImp(FXFT_Library library,
FXFT_Face* Face,
- IFX_SeekableReadStream* pFile,
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
int32_t faceIndex,
std::unique_ptr<FXFT_StreamRec>* stream) {
- std::unique_ptr<FXFT_StreamRec> stream1(new FXFT_StreamRec());
+ auto stream1 = pdfium::MakeUnique<FXFT_StreamRec>();
stream1->base = nullptr;
stream1->size = static_cast<unsigned long>(pFile->GetSize());
stream1->pos = 0;
- stream1->descriptor.pointer = pFile;
+ stream1->descriptor.pointer = static_cast<void*>(pFile.Get());
stream1->close = FTStreamClose;
stream1->read = FTStreamRead;
FXFT_Open_Args args;
@@ -338,15 +344,15 @@ void CFX_Font::LoadSubst(const CFX_ByteString& face_name,
}
#ifdef PDF_ENABLE_XFA
-bool CFX_Font::LoadFile(IFX_SeekableReadStream* pFile,
+bool CFX_Font::LoadFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
int nFaceIndex,
int* pFaceCount) {
m_bEmbedded = false;
CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
pFontMgr->InitFTLibrary();
- FXFT_Library library = pFontMgr->GetFTLibrary();
+ FXFT_Library library = pFontMgr->GetFTLibrary();
std::unique_ptr<FXFT_StreamRec> stream;
if (!LoadFileImp(library, &m_Face, pFile, nFaceIndex, &stream))
return false;