summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/cpdf_renderstatus.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/render/cpdf_renderstatus.cpp')
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp167
1 files changed, 82 insertions, 85 deletions
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 5320422b41..17576fc1f3 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -97,7 +97,7 @@ uint32_t CountOutputs(
return total;
}
-void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawAxialShading(CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -183,7 +183,7 @@ void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
}
-void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawRadialShading(CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -316,7 +316,7 @@ void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
}
-void DrawFuncShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawFuncShading(CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -391,7 +391,7 @@ bool GetScanlineIntersect(int y,
return true;
}
-void DrawGouraud(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawGouraud(CFX_DIBitmap* pBitmap,
int alpha,
CPDF_MeshVertex triangle[3]) {
float min_y = triangle[0].position.y;
@@ -473,7 +473,7 @@ void DrawGouraud(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
void DrawFreeGouraudShading(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -514,7 +514,7 @@ void DrawFreeGouraudShading(
}
void DrawLatticeGouraudShading(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -808,7 +808,7 @@ struct CPDF_PatchDrawer {
void DrawCoonPatchMeshes(
ShadingType type,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -892,20 +892,21 @@ void DrawCoonPatchMeshes(
}
}
-CFX_RetainPtr<CFX_DIBitmap> DrawPatternBitmap(CPDF_Document* pDoc,
- CPDF_PageRenderCache* pCache,
- CPDF_TilingPattern* pPattern,
- const CFX_Matrix* pObject2Device,
- int width,
- int height,
- int flags) {
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+std::unique_ptr<CFX_DIBitmap> DrawPatternBitmap(
+ CPDF_Document* pDoc,
+ CPDF_PageRenderCache* pCache,
+ CPDF_TilingPattern* pPattern,
+ const CFX_Matrix* pObject2Device,
+ int width,
+ int height,
+ int flags) {
+ std::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap);
if (!pBitmap->Create(width, height,
pPattern->colored() ? FXDIB_Argb : FXDIB_8bppMask)) {
return nullptr;
}
CFX_FxgeDevice bitmap_device;
- bitmap_device.Attach(pBitmap, false, nullptr, false);
+ bitmap_device.Attach(pBitmap.get(), false, nullptr, false);
pBitmap->Clear(0);
CFX_FloatRect cell_bbox = pPattern->bbox();
pPattern->pattern_to_form()->TransformRect(cell_bbox);
@@ -1530,41 +1531,38 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
}
FX_RECT rect = pPageObj->GetBBox(pObj2Device);
rect.Intersect(m_pDevice->GetClipBox());
- if (rect.IsEmpty())
+ if (rect.IsEmpty()) {
return true;
-
+ }
CFX_Matrix deviceCTM = m_pDevice->GetCTM();
float scaleX = FXSYS_fabs(deviceCTM.a);
float scaleY = FXSYS_fabs(deviceCTM.d);
int width = FXSYS_round((float)rect.Width() * scaleX);
int height = FXSYS_round((float)rect.Height() * scaleY);
CFX_FxgeDevice bitmap_device;
- CFX_RetainPtr<CFX_DIBitmap> oriDevice;
+ std::unique_ptr<CFX_DIBitmap> oriDevice;
if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
- oriDevice = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!m_pDevice->CreateCompatibleBitmap(oriDevice, width, height))
+ oriDevice = pdfium::MakeUnique<CFX_DIBitmap>();
+ if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height))
return true;
- m_pDevice->GetDIBits(oriDevice, rect.left, rect.top);
+ m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top);
}
- if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice))
+ if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get()))
return true;
-
- CFX_RetainPtr<CFX_DIBitmap> bitmap = bitmap_device.GetBitmap();
+ CFX_DIBitmap* bitmap = bitmap_device.GetBitmap();
bitmap->Clear(0);
-
CFX_Matrix new_matrix = *pObj2Device;
new_matrix.Translate(-rect.left, -rect.top);
new_matrix.Scale(scaleX, scaleY);
-
- CFX_RetainPtr<CFX_DIBitmap> pTextMask;
+ std::unique_ptr<CFX_DIBitmap> pTextMask;
if (bTextClip) {
- pTextMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ pTextMask = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pTextMask->Create(width, height, FXDIB_8bppMask))
return true;
pTextMask->Clear(0);
CFX_FxgeDevice text_device;
- text_device.Attach(pTextMask, false, nullptr, false);
+ text_device.Attach(pTextMask.get(), false, nullptr, false);
for (uint32_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); i++) {
CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i);
if (!textobj)
@@ -1591,14 +1589,14 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
if (pSMaskDict) {
CFX_Matrix smask_matrix = *pPageObj->m_GeneralState.GetSMaskMatrix();
smask_matrix.Concat(*pObj2Device);
- CFX_RetainPtr<CFX_DIBSource> pSMaskSource =
+ std::unique_ptr<CFX_DIBSource> pSMaskSource =
LoadSMask(pSMaskDict, &rect, &smask_matrix);
if (pSMaskSource)
- bitmap->MultiplyAlpha(pSMaskSource);
+ bitmap->MultiplyAlpha(pSMaskSource.get());
}
if (pTextMask) {
- bitmap->MultiplyAlpha(pTextMask);
- pTextMask.Reset();
+ bitmap->MultiplyAlpha(pTextMask.get());
+ pTextMask.reset();
}
int32_t blitAlpha = 255;
if (Transparency & PDFTRANS_GROUP && group_alpha != 1.0f) {
@@ -1620,7 +1618,7 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
return true;
}
-CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
+std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
const CPDF_PageObject* pObj,
const FX_RECT& rect,
int& left,
@@ -1635,11 +1633,11 @@ CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
float scaleY = FXSYS_fabs(deviceCTM.d);
int width = FXSYS_round(bbox.Width() * scaleX);
int height = FXSYS_round(bbox.Height() * scaleY);
- auto pBackdrop = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pBackdrop = pdfium::MakeUnique<CFX_DIBitmap>();
if (bBackAlphaRequired && !m_bDropObjects)
pBackdrop->Create(width, height, FXDIB_Argb);
else
- m_pDevice->CreateCompatibleBitmap(pBackdrop, width, height);
+ m_pDevice->CreateCompatibleBitmap(pBackdrop.get(), width, height);
if (!pBackdrop->GetBuffer())
return nullptr;
@@ -1651,16 +1649,16 @@ CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS);
if (!bNeedDraw) {
- m_pDevice->GetDIBits(pBackdrop, left, top);
+ m_pDevice->GetDIBits(pBackdrop.get(), left, top);
return pBackdrop;
}
+
CFX_Matrix FinalMatrix = m_DeviceMatrix;
FinalMatrix.Translate(-left, -top);
FinalMatrix.Scale(scaleX, scaleY);
pBackdrop->Clear(pBackdrop->HasAlpha() ? 0 : 0xffffffff);
-
CFX_FxgeDevice device;
- device.Attach(pBackdrop, false, nullptr, false);
+ device.Attach(pBackdrop.get(), false, nullptr, false);
m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix);
return pBackdrop;
}
@@ -1850,7 +1848,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!glyph.m_pGlyph)
continue;
- m_pDevice->SetBitMask(glyph.m_pGlyph->m_pBitmap,
+ m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap,
glyph.m_Origin.x + glyph.m_pGlyph->m_Left,
glyph.m_Origin.y - glyph.m_pGlyph->m_Top,
fill_argb);
@@ -1912,7 +1910,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
CFX_Point origin(FXSYS_round(matrix.e), FXSYS_round(matrix.f));
if (glyphs.empty()) {
- m_pDevice->SetBitMask(pBitmap->m_pBitmap, origin.x + pBitmap->m_Left,
+ m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin.x + pBitmap->m_Left,
origin.y - pBitmap->m_Top, fill_argb);
} else {
glyphs[iChar].m_pGlyph = pBitmap;
@@ -1922,7 +1920,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
CFX_Matrix image_matrix = pType3Char->m_ImageMatrix;
image_matrix.Concat(matrix);
CPDF_ImageRenderer renderer;
- if (renderer.Start(this, pType3Char->m_pBitmap, fill_argb, 255,
+ if (renderer.Start(this, pType3Char->m_pBitmap.get(), fill_argb, 255,
&image_matrix, 0, false, FXDIB_BLEND_NORMAL)) {
renderer.Continue(nullptr);
}
@@ -1936,12 +1934,12 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
return true;
FX_RECT rect = FXGE_GetGlyphsBBox(glyphs, 0, sa, sd);
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pBitmap->Create(static_cast<int>(rect.Width() * sa),
- static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
+ CFX_DIBitmap bitmap;
+ if (!bitmap.Create(static_cast<int>(rect.Width() * sa),
+ static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
return true;
}
- pBitmap->Clear(0);
+ bitmap.Clear(0);
for (const FXTEXT_GLYPHPOS& glyph : glyphs) {
if (!glyph.m_pGlyph)
continue;
@@ -1960,13 +1958,13 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!top.IsValid())
continue;
- pBitmap->CompositeMask(left.ValueOrDie(), top.ValueOrDie(),
- glyph.m_pGlyph->m_pBitmap->GetWidth(),
- glyph.m_pGlyph->m_pBitmap->GetHeight(),
- glyph.m_pGlyph->m_pBitmap, fill_argb, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr);
+ bitmap.CompositeMask(left.ValueOrDie(), top.ValueOrDie(),
+ glyph.m_pGlyph->m_Bitmap.GetWidth(),
+ glyph.m_pGlyph->m_Bitmap.GetHeight(),
+ &glyph.m_pGlyph->m_Bitmap, fill_argb, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr);
}
- m_pDevice->SetBitMask(pBitmap, rect.left, rect.top, fill_argb);
+ m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb);
return true;
}
@@ -2069,7 +2067,7 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150);
CFX_Matrix FinalMatrix = *pMatrix;
FinalMatrix.Concat(*buffer.GetMatrix());
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = buffer.GetBitmap();
+ CFX_DIBitmap* pBitmap = buffer.GetBitmap();
if (!pBitmap->GetBuffer())
return;
@@ -2287,9 +2285,9 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
}
float left_offset = cell_bbox.left - mtPattern2Device.e;
float top_offset = cell_bbox.bottom - mtPattern2Device.f;
- CFX_RetainPtr<CFX_DIBitmap> pPatternBitmap;
+ std::unique_ptr<CFX_DIBitmap> pPatternBitmap;
if (width * height < 16) {
- CFX_RetainPtr<CFX_DIBitmap> pEnlargedBitmap =
+ std::unique_ptr<CFX_DIBitmap> pEnlargedBitmap =
DrawPatternBitmap(m_pContext->GetDocument(), m_pContext->GetPageCache(),
pPattern, pObj2Device, 8, 8, m_Options.m_Flags);
pPatternBitmap = pEnlargedBitmap->StretchTo(width, height);
@@ -2309,11 +2307,11 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
FX_ARGB fill_argb = GetFillArgb(pPageObj);
int clip_width = clip_box.right - clip_box.left;
int clip_height = clip_box.bottom - clip_box.top;
- auto pScreen = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pScreen->Create(clip_width, clip_height, FXDIB_Argb))
+ CFX_DIBitmap screen;
+ if (!screen.Create(clip_width, clip_height, FXDIB_Argb)) {
return;
-
- pScreen->Clear(0);
+ }
+ screen.Clear(0);
uint32_t* src_buf = (uint32_t*)pPatternBitmap->GetBuffer();
for (int col = min_col; col <= max_col; col++) {
for (int row = min_row; row <= max_row; row++) {
@@ -2344,7 +2342,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
continue;
}
uint32_t* dest_buf =
- (uint32_t*)(pScreen->GetBuffer() + pScreen->GetPitch() * start_y +
+ (uint32_t*)(screen.GetBuffer() + screen.GetPitch() * start_y +
start_x * 4);
if (pPattern->colored())
*dest_buf = *src_buf;
@@ -2352,16 +2350,16 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
*dest_buf = (*(uint8_t*)src_buf << 24) | (fill_argb & 0xffffff);
} else {
if (pPattern->colored()) {
- pScreen->CompositeBitmap(start_x, start_y, width, height,
- pPatternBitmap, 0, 0);
+ screen.CompositeBitmap(start_x, start_y, width, height,
+ pPatternBitmap.get(), 0, 0);
} else {
- pScreen->CompositeMask(start_x, start_y, width, height,
- pPatternBitmap, fill_argb, 0, 0);
+ screen.CompositeMask(start_x, start_y, width, height,
+ pPatternBitmap.get(), fill_argb, 0, 0);
}
}
}
}
- CompositeDIBitmap(pScreen, clip_box.left, clip_box.top, 0, 255,
+ CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255,
FXDIB_BLEND_NORMAL, false);
m_pDevice->RestoreState(false);
}
@@ -2408,17 +2406,16 @@ bool CPDF_RenderStatus::ProcessImage(CPDF_ImageObject* pImageObj,
return render.GetResult();
}
-void CPDF_RenderStatus::CompositeDIBitmap(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
- int left,
- int top,
- FX_ARGB mask_argb,
- int bitmap_alpha,
- int blend_mode,
- int Transparency) {
- if (!pDIBitmap)
+void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
+ int left,
+ int top,
+ FX_ARGB mask_argb,
+ int bitmap_alpha,
+ int blend_mode,
+ int Transparency) {
+ if (!pDIBitmap) {
return;
-
+ }
if (blend_mode == FXDIB_BLEND_NORMAL) {
if (!pDIBitmap->IsAlphaMask()) {
if (bitmap_alpha < 255) {
@@ -2466,10 +2463,10 @@ void CPDF_RenderStatus::CompositeDIBitmap(
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
rect.Intersect(m_pDevice->GetClipBox());
- CFX_RetainPtr<CFX_DIBitmap> pClone;
+ CFX_MaybeOwned<CFX_DIBitmap> pClone;
if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
pClone = m_pDevice->GetBackDrop()->Clone(&rect);
- CFX_RetainPtr<CFX_DIBitmap> pForeBitmap = m_pDevice->GetBitmap();
+ CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
pForeBitmap, rect.left, rect.top);
left = left >= 0 ? 0 : left;
@@ -2484,7 +2481,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(
pClone = pDIBitmap;
}
if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone, rect.left, rect.top);
+ m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top);
} else {
if (pDIBitmap->IsAlphaMask())
return;
@@ -2497,7 +2494,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(
int back_left, back_top;
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
- CFX_RetainPtr<CFX_DIBitmap> pBackdrop =
+ std::unique_ptr<CFX_DIBitmap> pBackdrop =
GetBackdrop(m_pCurObj, rect, back_left, back_top,
blend_mode > FXDIB_BLEND_NORMAL && bIsolated);
if (!pBackdrop)
@@ -2513,17 +2510,17 @@ void CPDF_RenderStatus::CompositeDIBitmap(
pDIBitmap, mask_argb, 0, 0, blend_mode);
}
- auto pBackdrop1 = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pBackdrop1 = pdfium::MakeUnique<CFX_DIBitmap>();
pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(),
FXDIB_Rgb32);
pBackdrop1->Clear((uint32_t)-1);
pBackdrop1->CompositeBitmap(0, 0, pBackdrop->GetWidth(),
- pBackdrop->GetHeight(), pBackdrop, 0, 0);
+ pBackdrop->GetHeight(), pBackdrop.get(), 0, 0);
pBackdrop = std::move(pBackdrop1);
- m_pDevice->SetDIBits(pBackdrop, back_left, back_top);
+ m_pDevice->SetDIBits(pBackdrop.get(), back_left, back_top);
}
-CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
+std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
const CFX_Matrix* pMatrix) {
@@ -2616,7 +2613,7 @@ CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
nullptr, 0, color_space_family, bLuminosity);
status.RenderObjectList(&form, &matrix);
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pMask->Create(width, height, FXDIB_8bppMask))
return nullptr;