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

Side by Side Diff: core/src/fxge/win32/fx_win32_gdipext.cpp

Issue 1145843005: Revert "Remove FX_Alloc() null checks now that it can't return NULL." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 7 months 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/src/fxge/win32/fx_win32_dib.cpp ('k') | core/src/fxge/win32/fx_win32_print.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 "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ 8 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
9 #include <windows.h> 9 #include <windows.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 case CFX_GraphStateData::LineJoinRound: 759 case CFX_GraphStateData::LineJoinRound:
760 lineJoin = LineJoinRound; 760 lineJoin = LineJoinRound;
761 break; 761 break;
762 case CFX_GraphStateData::LineJoinBevel: 762 case CFX_GraphStateData::LineJoinBevel:
763 lineJoin = LineJoinBevel; 763 lineJoin = LineJoinBevel;
764 break; 764 break;
765 } 765 }
766 CallFunc(GdipSetPenLineJoin)(pPen, lineJoin); 766 CallFunc(GdipSetPenLineJoin)(pPen, lineJoin);
767 if(pGraphState->m_DashCount) { 767 if(pGraphState->m_DashCount) {
768 FX_FLOAT* pDashArray = FX_Alloc(FX_FLOAT, pGraphState->m_DashCount + pGr aphState->m_DashCount % 2); 768 FX_FLOAT* pDashArray = FX_Alloc(FX_FLOAT, pGraphState->m_DashCount + pGr aphState->m_DashCount % 2);
769 if (!pDashArray) {
770 return NULL;
771 }
769 int nCount = 0; 772 int nCount = 0;
770 FX_FLOAT on_leftover = 0, off_leftover = 0; 773 FX_FLOAT on_leftover = 0, off_leftover = 0;
771 for (int i = 0; i < pGraphState->m_DashCount; i += 2) { 774 for (int i = 0; i < pGraphState->m_DashCount; i += 2) {
772 FX_FLOAT on_phase = pGraphState->m_DashArray[i]; 775 FX_FLOAT on_phase = pGraphState->m_DashArray[i];
773 FX_FLOAT off_phase; 776 FX_FLOAT off_phase;
774 if (i == pGraphState->m_DashCount - 1) { 777 if (i == pGraphState->m_DashCount - 1) {
775 off_phase = on_phase; 778 off_phase = on_phase;
776 } else { 779 } else {
777 off_phase = pGraphState->m_DashArray[i + 1]; 780 off_phase = pGraphState->m_DashArray[i + 1];
778 } 781 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 CGdiplusExt& GdiplusExt = ((CWin32Platform*)CFX_GEModule::Get()->GetPlatform Data())->m_GdiplusExt; 863 CGdiplusExt& GdiplusExt = ((CWin32Platform*)CFX_GEModule::Get()->GetPlatform Data())->m_GdiplusExt;
861 CallFunc(GdipCreateFromHDC)(hDC, &pGraphics); 864 CallFunc(GdipCreateFromHDC)(hDC, &pGraphics);
862 CallFunc(GdipSetPageUnit)(pGraphics, UnitPixel); 865 CallFunc(GdipSetPageUnit)(pGraphics, UnitPixel);
863 CallFunc(GdipSetPixelOffsetMode)(pGraphics, PixelOffsetModeHalf); 866 CallFunc(GdipSetPixelOffsetMode)(pGraphics, PixelOffsetModeHalf);
864 GpMatrix* pMatrix = NULL; 867 GpMatrix* pMatrix = NULL;
865 if (pObject2Device) { 868 if (pObject2Device) {
866 CallFunc(GdipCreateMatrix2)(pObject2Device->a, pObject2Device->b, pObjec t2Device->c, pObject2Device->d, pObject2Device->e, pObject2Device->f, &pMatrix); 869 CallFunc(GdipCreateMatrix2)(pObject2Device->a, pObject2Device->b, pObjec t2Device->c, pObject2Device->d, pObject2Device->e, pObject2Device->f, &pMatrix);
867 CallFunc(GdipSetWorldTransform)(pGraphics, pMatrix); 870 CallFunc(GdipSetWorldTransform)(pGraphics, pMatrix);
868 } 871 }
869 PointF *points = FX_Alloc(PointF, nPoints); 872 PointF *points = FX_Alloc(PointF, nPoints);
873 if (!points) {
874 return FALSE;
875 }
870 BYTE * types = FX_Alloc(BYTE, nPoints); 876 BYTE * types = FX_Alloc(BYTE, nPoints);
877 if (!types) {
878 FX_Free(points);
879 return FALSE;
880 }
871 int nSubPathes = 0; 881 int nSubPathes = 0;
872 FX_BOOL bSubClose = FALSE; 882 FX_BOOL bSubClose = FALSE;
873 int pos_subclose = 0; 883 int pos_subclose = 0;
874 FX_BOOL bSmooth = FALSE; 884 FX_BOOL bSmooth = FALSE;
875 int startpoint = 0; 885 int startpoint = 0;
876 for(int i = 0; i < nPoints; i++) { 886 for(int i = 0; i < nPoints; i++) {
877 points[i].X = pPoints[i].m_PointX; 887 points[i].X = pPoints[i].m_PointX;
878 points[i].Y = pPoints[i].m_PointY; 888 points[i].Y = pPoints[i].m_PointY;
879 FX_FLOAT x, y; 889 FX_FLOAT x, y;
880 if (pObject2Device) { 890 if (pObject2Device) {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 dest_pixel_format = PixelFormat1bppIndexed; 1185 dest_pixel_format = PixelFormat1bppIndexed;
1176 } else if (pixel_format == PixelFormat8bppIndexed) { 1186 } else if (pixel_format == PixelFormat8bppIndexed) {
1177 info_size += 1024; 1187 info_size += 1024;
1178 bpp = 8; 1188 bpp = 8;
1179 dest_pixel_format = PixelFormat8bppIndexed; 1189 dest_pixel_format = PixelFormat8bppIndexed;
1180 } else if (pixel_format == PixelFormat32bppARGB) { 1190 } else if (pixel_format == PixelFormat32bppARGB) {
1181 bpp = 32; 1191 bpp = 32;
1182 dest_pixel_format = PixelFormat32bppARGB; 1192 dest_pixel_format = PixelFormat32bppARGB;
1183 } 1193 }
1184 LPBYTE buf = FX_Alloc(BYTE, info_size); 1194 LPBYTE buf = FX_Alloc(BYTE, info_size);
1195 if (!buf) {
1196 if (pStream) {
1197 pStream->Release();
1198 }
1199 return NULL;
1200 }
1185 BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)buf; 1201 BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)buf;
1186 pbmih->biBitCount = bpp; 1202 pbmih->biBitCount = bpp;
1187 pbmih->biCompression = BI_RGB; 1203 pbmih->biCompression = BI_RGB;
1188 pbmih->biHeight = -(int)height; 1204 pbmih->biHeight = -(int)height;
1189 pbmih->biPlanes = 1; 1205 pbmih->biPlanes = 1;
1190 pbmih->biWidth = width; 1206 pbmih->biWidth = width;
1191 Rect rect(0, 0, width, height); 1207 Rect rect(0, 0, width, height);
1192 BitmapData* pBitmapData = FX_Alloc(BitmapData, 1); 1208 BitmapData* pBitmapData = FX_Alloc(BitmapData, 1);
1209 if (!pBitmapData) {
1210 if (pStream) {
1211 pStream->Release();
1212 }
1213 return NULL;
1214 }
1193 CallFunc(GdipBitmapLockBits)(pBitmap, &rect, ImageLockModeRead, 1215 CallFunc(GdipBitmapLockBits)(pBitmap, &rect, ImageLockModeRead,
1194 dest_pixel_format, pBitmapData); 1216 dest_pixel_format, pBitmapData);
1195 if (pixel_format == PixelFormat1bppIndexed || pixel_format == PixelFormat8bp pIndexed) { 1217 if (pixel_format == PixelFormat1bppIndexed || pixel_format == PixelFormat8bp pIndexed) {
1196 DWORD* ppal = (DWORD*)(buf + sizeof(BITMAPINFOHEADER)); 1218 DWORD* ppal = (DWORD*)(buf + sizeof(BITMAPINFOHEADER));
1197 struct { 1219 struct {
1198 UINT flags; 1220 UINT flags;
1199 UINT Count; 1221 UINT Count;
1200 DWORD Entries[256]; 1222 DWORD Entries[256];
1201 } pal; 1223 } pal;
1202 int size = 0; 1224 int size = 0;
1203 CallFunc(GdipGetImagePaletteSize)(pBitmap, &size); 1225 CallFunc(GdipGetImagePaletteSize)(pBitmap, &size);
1204 CallFunc(GdipGetImagePalette)(pBitmap, (ColorPalette*)&pal, size); 1226 CallFunc(GdipGetImagePalette)(pBitmap, (ColorPalette*)&pal, size);
1205 int entries = pixel_format == PixelFormat1bppIndexed ? 2 : 256; 1227 int entries = pixel_format == PixelFormat1bppIndexed ? 2 : 256;
1206 for (int i = 0; i < entries; i ++) { 1228 for (int i = 0; i < entries; i ++) {
1207 ppal[i] = pal.Entries[i] & 0x00ffffff; 1229 ppal[i] = pal.Entries[i] & 0x00ffffff;
1208 } 1230 }
1209 } 1231 }
1210 PREVIEW3_DIBITMAP* pInfo = FX_Alloc(PREVIEW3_DIBITMAP, 1); 1232 PREVIEW3_DIBITMAP* pInfo = FX_Alloc(PREVIEW3_DIBITMAP, 1);
1233 if (!pInfo) {
1234 if (pStream) {
1235 pStream->Release();
1236 }
1237 return NULL;
1238 }
1211 pInfo->pbmi = (BITMAPINFO*)buf; 1239 pInfo->pbmi = (BITMAPINFO*)buf;
1212 pInfo->pScan0 = (LPBYTE)pBitmapData->Scan0; 1240 pInfo->pScan0 = (LPBYTE)pBitmapData->Scan0;
1213 pInfo->Stride = pBitmapData->Stride; 1241 pInfo->Stride = pBitmapData->Stride;
1214 pInfo->pBitmap = pBitmap; 1242 pInfo->pBitmap = pBitmap;
1215 pInfo->pBitmapData = pBitmapData; 1243 pInfo->pBitmapData = pBitmapData;
1216 pInfo->pStream = pStream; 1244 pInfo->pStream = pStream;
1217 return pInfo; 1245 return pInfo;
1218 } 1246 }
1219 static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) 1247 static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo)
1220 { 1248 {
(...skipping 24 matching lines...) Expand all
1245 for (int i = 0; i < height; i ++) { 1273 for (int i = 0; i < height; i ++) {
1246 FXSYS_memcpy32(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, dest_pitch); 1274 FXSYS_memcpy32(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, dest_pitch);
1247 } 1275 }
1248 } 1276 }
1249 CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(pInfo->pbmi, pData, pIn fo->pbmi->bmiHeader.biBitCount == 32); 1277 CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(pInfo->pbmi, pData, pIn fo->pbmi->bmiHeader.biBitCount == 32);
1250 FX_Free(pData); 1278 FX_Free(pData);
1251 FreeDIBitmap(pInfo); 1279 FreeDIBitmap(pInfo);
1252 return pDIBitmap; 1280 return pDIBitmap;
1253 } 1281 }
1254 #endif 1282 #endif
OLDNEW
« no previous file with comments | « core/src/fxge/win32/fx_win32_dib.cpp ('k') | core/src/fxge/win32/fx_win32_print.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698