From f0799fe84df4d86f25d342b03525f3016d674f86 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 28 Mar 2017 09:31:32 -0700 Subject: Revert "Revert "Refcount all CFX_DIBSources (and subclasses) all the time."" This reverts commit 31b08d4cdaa17d7a03f35e087096a77036af98ec. Re-landing the patch after fixing skia build issue. Change-Id: Ie7039890088b803a6ec5ce365d70f57277459b48 Reviewed-on: https://pdfium-review.googlesource.com/3245 Commit-Queue: Tom Sepez Commit-Queue: dsinclair Reviewed-by: dsinclair --- xfa/fxgraphics/cfx_graphics.cpp | 74 +++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 36 deletions(-) (limited to 'xfa/fxgraphics/cfx_graphics.cpp') diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp index 48d8f6f80f..3cfe2d0192 100644 --- a/xfa/fxgraphics/cfx_graphics.cpp +++ b/xfa/fxgraphics/cfx_graphics.cpp @@ -198,7 +198,7 @@ void CFX_Graphics::FillPath(CFX_Path* path, RenderDeviceFillPath(path, fillMode, matrix); } -void CFX_Graphics::StretchImage(CFX_DIBSource* source, +void CFX_Graphics::StretchImage(const CFX_RetainPtr& source, const CFX_RectF& rect, CFX_Matrix* matrix) { if (!source) @@ -318,48 +318,49 @@ void CFX_Graphics::RenderDeviceFillPath(CFX_Path* path, } } -void CFX_Graphics::RenderDeviceStretchImage(CFX_DIBSource* source, - const CFX_RectF& rect, - CFX_Matrix* matrix) { +void CFX_Graphics::RenderDeviceStretchImage( + const CFX_RetainPtr& source, + const CFX_RectF& rect, + CFX_Matrix* matrix) { CFX_Matrix m1(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, m_info.CTM.e, m_info.CTM.f); if (matrix) { m1.Concat(*matrix); } - std::unique_ptr bmp1 = + CFX_RetainPtr bmp1 = source->StretchTo((int32_t)rect.Width(), (int32_t)rect.Height()); CFX_Matrix m2(rect.Width(), 0.0, 0.0, rect.Height(), rect.left, rect.top); m2.Concat(m1); int32_t left; int32_t top; - std::unique_ptr bmp2 = bmp1->FlipImage(false, true); - std::unique_ptr bmp3 = bmp2->TransformTo(&m2, left, top); + CFX_RetainPtr bmp2 = bmp1->FlipImage(false, true); + CFX_RetainPtr bmp3 = bmp2->TransformTo(&m2, left, top); CFX_RectF r = GetClipRect(); - CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); + CFX_RetainPtr bitmap = m_renderDevice->GetBitmap(); bitmap->CompositeBitmap(FXSYS_round(r.left), FXSYS_round(r.top), - FXSYS_round(r.Width()), FXSYS_round(r.Height()), - bmp3.get(), FXSYS_round(r.left - left), - FXSYS_round(r.top - top)); + FXSYS_round(r.Width()), FXSYS_round(r.Height()), bmp3, + FXSYS_round(r.left - left), FXSYS_round(r.top - top)); } void CFX_Graphics::FillPathWithPattern(CFX_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix) { CFX_Pattern* pattern = m_info.fillColor->m_info.pattern; - CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); + CFX_RetainPtr bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); - CFX_DIBitmap bmp; - bmp.Create(width, height, FXDIB_Argb); - m_renderDevice->GetDIBits(&bmp, 0, 0); + auto bmp = pdfium::MakeRetain(); + bmp->Create(width, height, FXDIB_Argb); + m_renderDevice->GetDIBits(bmp, 0, 0); FX_HatchStyle hatchStyle = m_info.fillColor->m_info.pattern->m_hatchStyle; const FX_HATCHDATA& data = hatchBitmapData[static_cast(hatchStyle)]; - CFX_DIBitmap mask; - mask.Create(data.width, data.height, FXDIB_1bppMask); - FXSYS_memcpy(mask.GetBuffer(), data.maskBits, mask.GetPitch() * data.height); + auto mask = pdfium::MakeRetain(); + mask->Create(data.width, data.height, FXDIB_1bppMask); + FXSYS_memcpy(mask->GetBuffer(), data.maskBits, + mask->GetPitch() * data.height); CFX_FloatRect rectf = path->GetPathData()->GetBoundingBox(); if (matrix) matrix->TransformRect(rectf); @@ -367,35 +368,35 @@ void CFX_Graphics::FillPathWithPattern(CFX_Path* path, FX_RECT rect(FXSYS_round(rectf.left), FXSYS_round(rectf.top), FXSYS_round(rectf.right), FXSYS_round(rectf.bottom)); CFX_FxgeDevice device; - device.Attach(&bmp, false, nullptr, false); + device.Attach(bmp, false, nullptr, false); device.FillRect(&rect, m_info.fillColor->m_info.pattern->m_backArgb); - for (int32_t j = rect.bottom; j < rect.top; j += mask.GetHeight()) { - for (int32_t i = rect.left; i < rect.right; i += mask.GetWidth()) { - device.SetBitMask(&mask, i, j, + for (int32_t j = rect.bottom; j < rect.top; j += mask->GetHeight()) { + for (int32_t i = rect.left; i < rect.right; i += mask->GetWidth()) { + device.SetBitMask(mask, i, j, m_info.fillColor->m_info.pattern->m_foreArgb); } } m_renderDevice->SaveState(); m_renderDevice->SetClip_PathFill(path->GetPathData(), matrix, fillMode); - SetDIBitsWithMatrix(&bmp, &pattern->m_matrix); + SetDIBitsWithMatrix(bmp, &pattern->m_matrix); m_renderDevice->RestoreState(false); } void CFX_Graphics::FillPathWithShading(CFX_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix) { - CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); + CFX_RetainPtr bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); float start_x = m_info.fillColor->m_shading->m_beginPoint.x; float start_y = m_info.fillColor->m_shading->m_beginPoint.y; float end_x = m_info.fillColor->m_shading->m_endPoint.x; float end_y = m_info.fillColor->m_shading->m_endPoint.y; - CFX_DIBitmap bmp; - bmp.Create(width, height, FXDIB_Argb); - m_renderDevice->GetDIBits(&bmp, 0, 0); - int32_t pitch = bmp.GetPitch(); + auto bmp = pdfium::MakeRetain(); + bmp->Create(width, height, FXDIB_Argb); + m_renderDevice->GetDIBits(bmp, 0, 0); + int32_t pitch = bmp->GetPitch(); bool result = false; switch (m_info.fillColor->m_shading->m_type) { case FX_SHADING_Axial: { @@ -403,7 +404,7 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path, float y_span = end_y - start_y; float axis_len_square = (x_span * x_span) + (y_span * y_span); for (int32_t row = 0; row < height; row++) { - uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch); + uint32_t* dib_buf = (uint32_t*)(bmp->GetBuffer() + row * pitch); for (int32_t column = 0; column < width; column++) { float x = (float)(column); float y = (float)(row); @@ -434,7 +435,7 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path, ((start_y - end_y) * (start_y - end_y)) - ((start_r - end_r) * (start_r - end_r)); for (int32_t row = 0; row < height; row++) { - uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch); + uint32_t* dib_buf = (uint32_t*)(bmp->GetBuffer() + row * pitch); for (int32_t column = 0; column < width; column++) { float x = (float)(column); float y = (float)(row); @@ -496,13 +497,14 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path, if (result) { m_renderDevice->SaveState(); m_renderDevice->SetClip_PathFill(path->GetPathData(), matrix, fillMode); - SetDIBitsWithMatrix(&bmp, matrix); + SetDIBitsWithMatrix(bmp, matrix); m_renderDevice->RestoreState(false); } } -void CFX_Graphics::SetDIBitsWithMatrix(CFX_DIBSource* source, - CFX_Matrix* matrix) { +void CFX_Graphics::SetDIBitsWithMatrix( + const CFX_RetainPtr& source, + CFX_Matrix* matrix) { if (matrix->IsIdentity()) { m_renderDevice->SetDIBits(source, 0, 0); } else { @@ -511,9 +513,9 @@ void CFX_Graphics::SetDIBitsWithMatrix(CFX_DIBSource* source, m.Concat(*matrix); int32_t left; int32_t top; - std::unique_ptr bmp1 = source->FlipImage(false, true); - std::unique_ptr bmp2 = bmp1->TransformTo(&m, left, top); - m_renderDevice->SetDIBits(bmp2.get(), left, top); + CFX_RetainPtr bmp1 = source->FlipImage(false, true); + CFX_RetainPtr bmp2 = bmp1->TransformTo(&m, left, top); + m_renderDevice->SetDIBits(bmp2, left, top); } } -- cgit v1.2.3