Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(965)

Side by Side Diff: core/fpdfapi/render/cpdf_devicebuffer.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_stream.cpp ('k') | core/fpdfapi/render/cpdf_imagerenderer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 #include "core/fpdfapi/render/cpdf_devicebuffer.h" 7 #include "core/fpdfapi/render/cpdf_devicebuffer.h"
8 8
9 #include "core/fpdfapi/page/cpdf_pageobject.h" 9 #include "core/fpdfapi/page/cpdf_pageobject.h"
10 #include "core/fpdfapi/render/cpdf_rendercontext.h" 10 #include "core/fpdfapi/render/cpdf_rendercontext.h"
11 #include "core/fpdfapi/render/cpdf_renderoptions.h" 11 #include "core/fpdfapi/render/cpdf_renderoptions.h"
12 #include "core/fxge/cfx_fxgedevice.h" 12 #include "core/fxge/cfx_fxgedevice.h"
13 #include "core/fxge/cfx_renderdevice.h" 13 #include "core/fxge/cfx_renderdevice.h"
14 #include "core/fxge/fx_dib.h" 14 #include "core/fxge/fx_dib.h"
15 #include "third_party/base/ptr_util.h"
15 16
16 CPDF_DeviceBuffer::CPDF_DeviceBuffer() 17 CPDF_DeviceBuffer::CPDF_DeviceBuffer()
17 : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} 18 : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {}
18 19
19 CPDF_DeviceBuffer::~CPDF_DeviceBuffer() {} 20 CPDF_DeviceBuffer::~CPDF_DeviceBuffer() {}
20 21
21 bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, 22 bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext,
22 CFX_RenderDevice* pDevice, 23 CFX_RenderDevice* pDevice,
23 FX_RECT* pRect, 24 FX_RECT* pRect,
24 const CPDF_PageObject* pObj, 25 const CPDF_PageObject* pObj,
(...skipping 17 matching lines...) Expand all
42 m_Matrix.Scale(1.0f, (FX_FLOAT)(max_dpi) / (FX_FLOAT)dpiv); 43 m_Matrix.Scale(1.0f, (FX_FLOAT)(max_dpi) / (FX_FLOAT)dpiv);
43 } 44 }
44 #endif 45 #endif
45 CFX_Matrix ctm = m_pDevice->GetCTM(); 46 CFX_Matrix ctm = m_pDevice->GetCTM();
46 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); 47 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a);
47 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); 48 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d);
48 m_Matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0); 49 m_Matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0);
49 CFX_FloatRect rect(*pRect); 50 CFX_FloatRect rect(*pRect);
50 m_Matrix.TransformRect(rect); 51 m_Matrix.TransformRect(rect);
51 FX_RECT bitmap_rect = rect.GetOuterRect(); 52 FX_RECT bitmap_rect = rect.GetOuterRect();
52 m_pBitmap.reset(new CFX_DIBitmap); 53 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
53 m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(), FXDIB_Argb); 54 m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(), FXDIB_Argb);
54 return true; 55 return true;
55 } 56 }
56 57
57 void CPDF_DeviceBuffer::OutputToDevice() { 58 void CPDF_DeviceBuffer::OutputToDevice() {
58 if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) { 59 if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) {
59 if (m_Matrix.a == 1.0f && m_Matrix.d == 1.0f) { 60 if (m_Matrix.a == 1.0f && m_Matrix.d == 1.0f) {
60 m_pDevice->SetDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top); 61 m_pDevice->SetDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top);
61 } else { 62 } else {
62 m_pDevice->StretchDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top, 63 m_pDevice->StretchDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top,
63 m_Rect.Width(), m_Rect.Height()); 64 m_Rect.Width(), m_Rect.Height());
64 } 65 }
65 return; 66 return;
66 } 67 }
67 CFX_DIBitmap buffer; 68 CFX_DIBitmap buffer;
68 m_pDevice->CreateCompatibleBitmap(&buffer, m_pBitmap->GetWidth(), 69 m_pDevice->CreateCompatibleBitmap(&buffer, m_pBitmap->GetWidth(),
69 m_pBitmap->GetHeight()); 70 m_pBitmap->GetHeight());
70 m_pContext->GetBackground(&buffer, m_pObject, nullptr, &m_Matrix); 71 m_pContext->GetBackground(&buffer, m_pObject, nullptr, &m_Matrix);
71 buffer.CompositeBitmap(0, 0, buffer.GetWidth(), buffer.GetHeight(), 72 buffer.CompositeBitmap(0, 0, buffer.GetWidth(), buffer.GetHeight(),
72 m_pBitmap.get(), 0, 0); 73 m_pBitmap.get(), 0, 0);
73 m_pDevice->StretchDIBits(&buffer, m_Rect.left, m_Rect.top, m_Rect.Width(), 74 m_pDevice->StretchDIBits(&buffer, m_Rect.left, m_Rect.top, m_Rect.Width(),
74 m_Rect.Height()); 75 m_Rect.Height());
75 } 76 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_stream.cpp ('k') | core/fpdfapi/render/cpdf_imagerenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698