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

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

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