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

Side by Side Diff: core/fxge/win32/fx_win32_device.cpp

Issue 2534953004: Return unique_ptrs from CFX_DIBitmap::Clone(). (Closed)
Patch Set: nits 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/fxge/fx_dib.h ('k') | core/fxge/win32/fx_win32_gdipext.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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 <crtdbg.h> 7 #include <crtdbg.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "core/fxcodec/fx_codec.h" 13 #include "core/fxcodec/fx_codec.h"
14 #include "core/fxcrt/cfx_maybe_owned.h"
14 #include "core/fxcrt/fx_memory.h" 15 #include "core/fxcrt/fx_memory.h"
15 #include "core/fxcrt/fx_system.h" 16 #include "core/fxcrt/fx_system.h"
16 #include "core/fxge/cfx_fontmapper.h" 17 #include "core/fxge/cfx_fontmapper.h"
17 #include "core/fxge/cfx_gemodule.h" 18 #include "core/fxge/cfx_gemodule.h"
18 #include "core/fxge/cfx_graphstatedata.h" 19 #include "core/fxge/cfx_graphstatedata.h"
19 #include "core/fxge/cfx_pathdata.h" 20 #include "core/fxge/cfx_pathdata.h"
20 #include "core/fxge/cfx_windowsdevice.h" 21 #include "core/fxge/cfx_windowsdevice.h"
21 #include "core/fxge/dib/dib_int.h" 22 #include "core/fxge/dib/dib_int.h"
22 #include "core/fxge/fx_font.h" 23 #include "core/fxge/fx_font.h"
23 #include "core/fxge/fx_freetype.h" 24 #include "core/fxge/fx_freetype.h"
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 FX_RECT dst_rect(0, 0, width, height); 807 FX_RECT dst_rect(0, 0, width, height);
807 dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); 808 dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
808 int dst_width = dst_rect.Width(); 809 int dst_width = dst_rect.Width();
809 int dst_height = dst_rect.Height(); 810 int dst_height = dst_rect.Height();
810 ::StretchDIBits(m_hDC, left, top, dst_width, dst_height, 0, 0, dst_width, 811 ::StretchDIBits(m_hDC, left, top, dst_width, dst_height, 0, 0, dst_width,
811 dst_height, pBuffer, (BITMAPINFO*)info.c_str(), 812 dst_height, pBuffer, (BITMAPINFO*)info.c_str(),
812 DIB_RGB_COLORS, SRCCOPY); 813 DIB_RGB_COLORS, SRCCOPY);
813 } else { 814 } else {
814 CFX_DIBitmap* pBitmap = pBitmap1; 815 CFX_DIBitmap* pBitmap = pBitmap1;
815 if (pBitmap->IsCmykImage()) { 816 if (pBitmap->IsCmykImage()) {
816 pBitmap = pBitmap->CloneConvert(FXDIB_Rgb); 817 pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
817 if (!pBitmap) 818 if (!pBitmap)
818 return false; 819 return false;
819 } 820 }
820 int width = pSrcRect->Width(), height = pSrcRect->Height(); 821 int width = pSrcRect->Width(), height = pSrcRect->Height();
821 LPBYTE pBuffer = pBitmap->GetBuffer(); 822 LPBYTE pBuffer = pBitmap->GetBuffer();
822 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap); 823 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
823 ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left, 824 ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left,
824 pBitmap->GetHeight() - pSrcRect->bottom, 0, 825 pBitmap->GetHeight() - pSrcRect->bottom, 0,
825 pBitmap->GetHeight(), pBuffer, 826 pBitmap->GetHeight(), pBuffer,
826 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); 827 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
(...skipping 18 matching lines...) Expand all
845 return false; 846 return false;
846 847
847 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap); 848 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
848 if ((int64_t)abs(dest_width) * abs(dest_height) < 849 if ((int64_t)abs(dest_width) * abs(dest_height) <
849 (int64_t)pBitmap1->GetWidth() * pBitmap1->GetHeight() * 4 || 850 (int64_t)pBitmap1->GetWidth() * pBitmap1->GetHeight() * 4 ||
850 (flags & FXDIB_INTERPOL) || (flags & FXDIB_BICUBIC_INTERPOL)) { 851 (flags & FXDIB_INTERPOL) || (flags & FXDIB_BICUBIC_INTERPOL)) {
851 SetStretchBltMode(m_hDC, HALFTONE); 852 SetStretchBltMode(m_hDC, HALFTONE);
852 } else { 853 } else {
853 SetStretchBltMode(m_hDC, COLORONCOLOR); 854 SetStretchBltMode(m_hDC, COLORONCOLOR);
854 } 855 }
855 CFX_DIBitmap* pToStrechBitmap = pBitmap; 856 CFX_MaybeOwned<CFX_DIBitmap> pToStrechBitmap(pBitmap);
856 bool del = false;
857 if (m_DeviceClass == FXDC_PRINTER && 857 if (m_DeviceClass == FXDC_PRINTER &&
858 ((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() > 858 ((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() >
859 (int64_t)abs(dest_width) * abs(dest_height))) { 859 (int64_t)abs(dest_width) * abs(dest_height))) {
860 pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height); 860 pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height);
861 del = true;
862 } 861 }
863 CFX_ByteString toStrechBitmapInfo = 862 CFX_ByteString toStrechBitmapInfo =
864 CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap); 863 CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap.Get());
865 ::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0, 864 ::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0,
866 pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(), 865 pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(),
867 pToStrechBitmap->GetBuffer(), 866 pToStrechBitmap->GetBuffer(),
868 (BITMAPINFO*)toStrechBitmapInfo.c_str(), DIB_RGB_COLORS, 867 (BITMAPINFO*)toStrechBitmapInfo.c_str(), DIB_RGB_COLORS,
869 SRCCOPY); 868 SRCCOPY);
870 if (del)
871 delete pToStrechBitmap;
872 return true; 869 return true;
873 } 870 }
874 871
875 bool CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1, 872 bool CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1,
876 int dest_left, 873 int dest_left,
877 int dest_top, 874 int dest_top,
878 int dest_width, 875 int dest_width,
879 int dest_height, 876 int dest_height,
880 uint32_t bitmap_color, 877 uint32_t bitmap_color,
881 uint32_t flags) { 878 uint32_t flags) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 // static 1380 // static
1384 IFX_RenderDeviceDriver* CFX_WindowsDevice::CreateDriver(HDC hDC) { 1381 IFX_RenderDeviceDriver* CFX_WindowsDevice::CreateDriver(HDC hDC) {
1385 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY); 1382 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY);
1386 int obj_type = ::GetObjectType(hDC); 1383 int obj_type = ::GetObjectType(hDC);
1387 bool use_printer = device_type == DT_RASPRINTER || 1384 bool use_printer = device_type == DT_RASPRINTER ||
1388 device_type == DT_PLOTTER || obj_type == OBJ_ENHMETADC; 1385 device_type == DT_PLOTTER || obj_type == OBJ_ENHMETADC;
1389 if (use_printer) 1386 if (use_printer)
1390 return new CGdiPrinterDriver(hDC); 1387 return new CGdiPrinterDriver(hDC);
1391 return new CGdiDisplayDriver(hDC); 1388 return new CGdiDisplayDriver(hDC);
1392 } 1389 }
OLDNEW
« no previous file with comments | « core/fxge/fx_dib.h ('k') | core/fxge/win32/fx_win32_gdipext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698