Pass CFX_Matrix by const-ref where possible in core/
Change-Id: I1785bae33343ae7ea8c42ddf859c374f4457a2de
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79311
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_rendercontext.cpp b/core/fpdfapi/render/cpdf_rendercontext.cpp
index 8f92880..2367c96 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.cpp
+++ b/core/fpdfapi/render/cpdf_rendercontext.cpp
@@ -42,11 +42,8 @@
}
void CPDF_RenderContext::AppendLayer(CPDF_PageObjectHolder* pObjectHolder,
- const CFX_Matrix* pObject2Device) {
- m_Layers.emplace_back();
- m_Layers.back().m_pObjectHolder = pObjectHolder;
- if (pObject2Device)
- m_Layers.back().m_Matrix = *pObject2Device;
+ const CFX_Matrix& mtObject2Device) {
+ m_Layers.emplace_back(pObjectHolder, mtObject2Device);
}
void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice,
@@ -82,7 +79,9 @@
}
}
-CPDF_RenderContext::Layer::Layer() = default;
+CPDF_RenderContext::Layer::Layer(CPDF_PageObjectHolder* pHolder,
+ const CFX_Matrix& matrix)
+ : m_pObjectHolder(pHolder), m_Matrix(matrix) {}
CPDF_RenderContext::Layer::Layer(const Layer& that) = default;
diff --git a/core/fpdfapi/render/cpdf_rendercontext.h b/core/fpdfapi/render/cpdf_rendercontext.h
index d9efbc4..ec99c58 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.h
+++ b/core/fpdfapi/render/cpdf_rendercontext.h
@@ -27,12 +27,12 @@
public:
class Layer {
public:
- Layer();
+ Layer(CPDF_PageObjectHolder* pHolder, const CFX_Matrix& matrix);
Layer(const Layer& that);
~Layer();
- UnownedPtr<CPDF_PageObjectHolder> m_pObjectHolder;
- CFX_Matrix m_Matrix;
+ UnownedPtr<CPDF_PageObjectHolder> const m_pObjectHolder;
+ const CFX_Matrix m_Matrix;
};
CPDF_RenderContext(CPDF_Document* pDoc,
@@ -41,7 +41,7 @@
~CPDF_RenderContext();
void AppendLayer(CPDF_PageObjectHolder* pObjectHolder,
- const CFX_Matrix* pObject2Device);
+ const CFX_Matrix& mtObject2Device);
void Render(CFX_RenderDevice* pDevice,
const CPDF_RenderOptions* pOptions,
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 8641ed6..7173baa 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -700,7 +700,7 @@
CFX_Matrix smask_matrix =
*pPageObj->m_GeneralState.GetSMaskMatrix() * mtObj2Device;
RetainPtr<CFX_DIBBase> pSMaskSource =
- LoadSMask(pSMaskDict, &rect, &smask_matrix);
+ LoadSMask(pSMaskDict, &rect, smask_matrix);
if (pSMaskSource)
bitmap->MultiplyAlpha(pSMaskSource);
}
@@ -870,7 +870,7 @@
float font_size = textobj->m_TextState.GetFontSize();
if (bPattern) {
DrawTextPathWithPattern(textobj, mtObj2Device, pFont.Get(), font_size,
- &text_matrix, is_fill, is_stroke);
+ text_matrix, is_fill, is_stroke);
return true;
}
if (is_clip || is_stroke) {
@@ -1017,7 +1017,7 @@
RetainPtr<CPDF_Type3Cache> pCache =
CPDF_DocRenderData::FromDocument(pDoc)->GetCachedType3(pType3Font);
- const CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix);
+ const CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, matrix);
if (!pBitmap)
continue;
@@ -1075,7 +1075,7 @@
const CFX_Matrix& mtObj2Device,
CPDF_Font* pFont,
float font_size,
- const CFX_Matrix* pTextMatrix,
+ const CFX_Matrix& mtTextMatrix,
bool fill,
bool stroke) {
if (!stroke) {
@@ -1123,7 +1123,7 @@
path.set_filltype(fill ? CFX_FillRenderOptions::FillType::kWinding
: CFX_FillRenderOptions::FillType::kNoFill);
path.path().Append(pPath, &matrix);
- path.set_matrix(*pTextMatrix);
+ path.set_matrix(mtTextMatrix);
path.CalcBoundingBox();
ProcessPath(&path, mtObj2Device);
}
@@ -1371,7 +1371,7 @@
RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
- const CFX_Matrix* pMatrix) {
+ const CFX_Matrix& mtMatrix) {
if (!pSMaskDict)
return nullptr;
@@ -1385,7 +1385,7 @@
if (pFuncObj && (pFuncObj->IsDictionary() || pFuncObj->IsStream()))
pFunc = CPDF_Function::Load(pFuncObj);
- CFX_Matrix matrix = *pMatrix;
+ CFX_Matrix matrix = mtMatrix;
matrix.Translate(-pClipRect->left, -pClipRect->top);
CPDF_Form form(m_pContext->GetDocument(), m_pContext->GetPageResources(),
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 4d94e7a..7b38765 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -163,7 +163,7 @@
const CFX_Matrix& mtObj2Device,
CPDF_Font* pFont,
float font_size,
- const CFX_Matrix* pTextMatrix,
+ const CFX_Matrix& mtTextMatrix,
bool fill,
bool stroke);
bool ProcessForm(const CPDF_FormObject* pFormObj,
@@ -175,7 +175,7 @@
int* top);
RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
- const CFX_Matrix* pMatrix);
+ const CFX_Matrix& mtMatrix);
// Optionally write the colorspace family value into |pCSFamily|.
FX_ARGB GetBackColor(const CPDF_Dictionary* pSMaskDict,
const CPDF_Dictionary* pGroupDict,
diff --git a/core/fpdfapi/render/cpdf_rendertiling.cpp b/core/fpdfapi/render/cpdf_rendertiling.cpp
index c00e75e..17575ef 100644
--- a/core/fpdfapi/render/cpdf_rendertiling.cpp
+++ b/core/fpdfapi/render/cpdf_rendertiling.cpp
@@ -55,7 +55,7 @@
options.GetOptions().bForceHalftone = true;
CPDF_RenderContext context(pDoc, nullptr, pCache);
- context.AppendLayer(pPatternForm, &mtPattern2Bitmap);
+ context.AppendLayer(pPatternForm, mtPattern2Bitmap);
context.Render(&bitmap_device, &options, nullptr);
#if defined(_SKIA_SUPPORT_PATHS_)
bitmap_device.Flush(true);
diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp
index 0d1b0ed..6e7911c 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -86,11 +86,11 @@
CPDF_Type3Cache::~CPDF_Type3Cache() = default;
const CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(uint32_t charcode,
- const CFX_Matrix* pMatrix) {
+ const CFX_Matrix& mtMatrix) {
CPDF_UniqueKeyGen keygen;
keygen.Generate(
- 4, FXSYS_roundf(pMatrix->a * 10000), FXSYS_roundf(pMatrix->b * 10000),
- FXSYS_roundf(pMatrix->c * 10000), FXSYS_roundf(pMatrix->d * 10000));
+ 4, FXSYS_roundf(mtMatrix.a * 10000), FXSYS_roundf(mtMatrix.b * 10000),
+ FXSYS_roundf(mtMatrix.c * 10000), FXSYS_roundf(mtMatrix.d * 10000));
ByteString FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);
CPDF_Type3GlyphMap* pSizeCache;
auto it = m_SizeMap.find(FaceGlyphsKey);
@@ -106,7 +106,7 @@
return pExisting;
std::unique_ptr<CFX_GlyphBitmap> pNewBitmap =
- RenderGlyph(pSizeCache, charcode, pMatrix);
+ RenderGlyph(pSizeCache, charcode, mtMatrix);
CFX_GlyphBitmap* pGlyphBitmap = pNewBitmap.get();
pSizeCache->SetBitmap(charcode, std::move(pNewBitmap));
return pGlyphBitmap;
@@ -115,12 +115,12 @@
std::unique_ptr<CFX_GlyphBitmap> CPDF_Type3Cache::RenderGlyph(
CPDF_Type3GlyphMap* pSize,
uint32_t charcode,
- const CFX_Matrix* pMatrix) {
+ const CFX_Matrix& mtMatrix) {
const CPDF_Type3Char* pChar = m_pFont->LoadChar(charcode);
if (!pChar || !pChar->GetBitmap())
return nullptr;
- CFX_Matrix text_matrix(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0);
+ CFX_Matrix text_matrix(mtMatrix.a, mtMatrix.b, mtMatrix.c, mtMatrix.d, 0, 0);
CFX_Matrix image_matrix = pChar->matrix() * text_matrix;
RetainPtr<CFX_DIBitmap> pBitmap = pChar->GetBitmap();
diff --git a/core/fpdfapi/render/cpdf_type3cache.h b/core/fpdfapi/render/cpdf_type3cache.h
index 7096a5d..d7dbbb2 100644
--- a/core/fpdfapi/render/cpdf_type3cache.h
+++ b/core/fpdfapi/render/cpdf_type3cache.h
@@ -25,7 +25,7 @@
CONSTRUCT_VIA_MAKE_RETAIN;
const CFX_GlyphBitmap* LoadGlyph(uint32_t charcode,
- const CFX_Matrix* pMatrix);
+ const CFX_Matrix& mtMatrix);
private:
explicit CPDF_Type3Cache(CPDF_Type3Font* pFont);
@@ -33,7 +33,7 @@
std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(CPDF_Type3GlyphMap* pSize,
uint32_t charcode,
- const CFX_Matrix* pMatrix);
+ const CFX_Matrix& mtMatrix);
RetainPtr<CPDF_Type3Font> const m_pFont;
std::map<ByteString, std::unique_ptr<CPDF_Type3GlyphMap>> m_SizeMap;
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index ae39fde..d19241b 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -42,7 +42,7 @@
CPDF_Form* AnnotGetMatrix(const CPDF_Page* pPage,
CPDF_Annot* pAnnot,
CPDF_Annot::AppearanceMode mode,
- const CFX_Matrix* pUser2Device,
+ const CFX_Matrix& mtUser2Device,
CFX_Matrix* matrix) {
CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode);
if (!pForm)
@@ -52,7 +52,7 @@
CFX_FloatRect form_bbox =
form_matrix.TransformRect(pForm->GetDict()->GetRectFor("BBox"));
matrix->MatchRect(pAnnot->GetRect(), form_bbox);
- matrix->Concat(*pUser2Device);
+ matrix->Concat(mtUser2Device);
return pForm;
}
@@ -401,21 +401,21 @@
GenerateAPIfNeeded();
CFX_Matrix matrix;
- CPDF_Form* pForm = AnnotGetMatrix(pPage, this, mode, &mtUser2Device, &matrix);
+ CPDF_Form* pForm = AnnotGetMatrix(pPage, this, mode, mtUser2Device, &matrix);
if (!pForm)
return false;
CPDF_RenderContext context(
pPage->GetDocument(), pPage->m_pPageResources.Get(),
static_cast<CPDF_PageRenderCache*>(pPage->GetRenderCache()));
- context.AppendLayer(pForm, &matrix);
+ context.AppendLayer(pForm, matrix);
context.Render(pDevice, pOptions, nullptr);
return true;
}
bool CPDF_Annot::DrawInContext(const CPDF_Page* pPage,
CPDF_RenderContext* pContext,
- const CFX_Matrix* pUser2Device,
+ const CFX_Matrix& mtUser2Device,
AppearanceMode mode) {
if (!ShouldDrawAnnotation())
return false;
@@ -428,11 +428,11 @@
GenerateAPIfNeeded();
CFX_Matrix matrix;
- CPDF_Form* pForm = AnnotGetMatrix(pPage, this, mode, pUser2Device, &matrix);
+ CPDF_Form* pForm = AnnotGetMatrix(pPage, this, mode, mtUser2Device, &matrix);
if (!pForm)
return false;
- pContext->AppendLayer(pForm, &matrix);
+ pContext->AppendLayer(pForm, matrix);
return true;
}
diff --git a/core/fpdfdoc/cpdf_annot.h b/core/fpdfdoc/cpdf_annot.h
index 65a1ba9..fa50ac8 100644
--- a/core/fpdfdoc/cpdf_annot.h
+++ b/core/fpdfdoc/cpdf_annot.h
@@ -93,7 +93,7 @@
const CPDF_RenderOptions* pOptions);
bool DrawInContext(const CPDF_Page* pPage,
CPDF_RenderContext* pContext,
- const CFX_Matrix* pUser2Device,
+ const CFX_Matrix& mtUser2Device,
AppearanceMode mode);
void ClearCachedAP();
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 50d39bf..6814377 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -225,7 +225,7 @@
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
bool bPrinting,
- const CFX_Matrix* pMatrix,
+ const CFX_Matrix& mtMatrix,
bool bWidgetPass,
CPDF_RenderOptions* pOptions,
FX_RECT* clip_rect) {
@@ -254,7 +254,7 @@
}
}
- CFX_Matrix matrix = *pMatrix;
+ CFX_Matrix matrix = mtMatrix;
if (clip_rect) {
FX_RECT annot_rect =
matrix.TransformRect(pAnnot->GetRect()).GetOuterRect();
@@ -263,7 +263,7 @@
continue;
}
if (pContext) {
- pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal);
+ pAnnot->DrawInContext(pPage, pContext, matrix, CPDF_Annot::Normal);
} else if (!pAnnot->DrawAppearance(pPage, pDevice, matrix,
CPDF_Annot::Normal, pOptions)) {
pAnnot->DrawBorder(pDevice, &matrix, pOptions);
@@ -275,16 +275,16 @@
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
bool bPrinting,
- const CFX_Matrix* pUser2Device,
+ const CFX_Matrix& mtUser2Device,
uint32_t dwAnnotFlags,
CPDF_RenderOptions* pOptions,
FX_RECT* pClipRect) {
if (dwAnnotFlags & pdfium::annotation_flags::kInvisible) {
- DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, false,
+ DisplayPass(pPage, pDevice, pContext, bPrinting, mtUser2Device, false,
pOptions, pClipRect);
}
if (dwAnnotFlags & pdfium::annotation_flags::kHidden) {
- DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, true,
+ DisplayPass(pPage, pDevice, pContext, bPrinting, mtUser2Device, true,
pOptions, pClipRect);
}
}
@@ -293,12 +293,12 @@
CFX_RenderDevice* device,
CPDF_RenderContext* pContext,
bool bPrinting,
- const CFX_Matrix* pMatrix,
+ const CFX_Matrix& mtMatrix,
bool bShowWidget,
CPDF_RenderOptions* pOptions) {
uint32_t dwAnnotFlags = bShowWidget ? pdfium::annotation_flags::kInvisible |
pdfium::annotation_flags::kHidden
: pdfium::annotation_flags::kInvisible;
- DisplayAnnots(pPage, device, pContext, bPrinting, pMatrix, dwAnnotFlags,
+ DisplayAnnots(pPage, device, pContext, bPrinting, mtMatrix, dwAnnotFlags,
pOptions, nullptr);
}
diff --git a/core/fpdfdoc/cpdf_annotlist.h b/core/fpdfdoc/cpdf_annotlist.h
index 583ffce..581b9a8 100644
--- a/core/fpdfdoc/cpdf_annotlist.h
+++ b/core/fpdfdoc/cpdf_annotlist.h
@@ -31,7 +31,7 @@
CFX_RenderDevice* device,
CPDF_RenderContext* pContext,
bool bPrinting,
- const CFX_Matrix* pMatrix,
+ const CFX_Matrix& mtMatrix,
bool bShowWidget,
CPDF_RenderOptions* pOptions);
@@ -39,7 +39,7 @@
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
bool bPrinting,
- const CFX_Matrix* pUser2Device,
+ const CFX_Matrix& mtUser2Device,
uint32_t dwAnnotFlags,
CPDF_RenderOptions* pOptions,
FX_RECT* pClipRect);
@@ -55,7 +55,7 @@
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
bool bPrinting,
- const CFX_Matrix* pMatrix,
+ const CFX_Matrix& mtMatrix,
bool bWidget,
CPDF_RenderOptions* pOptions,
FX_RECT* clip_rect);
diff --git a/fpdfsdk/cpdfsdk_renderpage.cpp b/fpdfsdk/cpdfsdk_renderpage.cpp
index 42fd11e..dcca929 100644
--- a/fpdfsdk/cpdfsdk_renderpage.cpp
+++ b/fpdfsdk/cpdfsdk_renderpage.cpp
@@ -62,7 +62,7 @@
pPage->GetDocument(), pPage->m_pPageResources.Get(),
static_cast<CPDF_PageRenderCache*>(pPage->GetRenderCache()));
- pContext->m_pContext->AppendLayer(pPage, &matrix);
+ pContext->m_pContext->AppendLayer(pPage, matrix);
if (flags & FPDF_ANNOT) {
auto pOwnedList = std::make_unique<CPDF_AnnotList>(pPage);
@@ -71,7 +71,7 @@
bool bPrinting =
pContext->m_pDevice->GetDeviceType() != DeviceType::kDisplay;
pList->DisplayAnnots(pPage, pContext->m_pDevice.get(),
- pContext->m_pContext.get(), bPrinting, &matrix, false,
+ pContext->m_pContext.get(), bPrinting, matrix, false,
nullptr);
}