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

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

Issue 1143663008: Merge to XFA: Remove FX_Alloc() null checks now that it can't return NULL. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Rebased. 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 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 case CFX_GraphStateData::LineJoinRound: 762 case CFX_GraphStateData::LineJoinRound:
763 lineJoin = LineJoinRound; 763 lineJoin = LineJoinRound;
764 break; 764 break;
765 case CFX_GraphStateData::LineJoinBevel: 765 case CFX_GraphStateData::LineJoinBevel:
766 lineJoin = LineJoinBevel; 766 lineJoin = LineJoinBevel;
767 break; 767 break;
768 } 768 }
769 CallFunc(GdipSetPenLineJoin)(pPen, lineJoin); 769 CallFunc(GdipSetPenLineJoin)(pPen, lineJoin);
770 if(pGraphState->m_DashCount) { 770 if(pGraphState->m_DashCount) {
771 FX_FLOAT* pDashArray = FX_Alloc(FX_FLOAT, pGraphState->m_DashCount + pGr aphState->m_DashCount % 2); 771 FX_FLOAT* pDashArray = FX_Alloc(FX_FLOAT, pGraphState->m_DashCount + pGr aphState->m_DashCount % 2);
772 if (!pDashArray) {
773 return NULL;
774 }
775 int nCount = 0; 772 int nCount = 0;
776 FX_FLOAT on_leftover = 0, off_leftover = 0; 773 FX_FLOAT on_leftover = 0, off_leftover = 0;
777 for (int i = 0; i < pGraphState->m_DashCount; i += 2) { 774 for (int i = 0; i < pGraphState->m_DashCount; i += 2) {
778 FX_FLOAT on_phase = pGraphState->m_DashArray[i]; 775 FX_FLOAT on_phase = pGraphState->m_DashArray[i];
779 FX_FLOAT off_phase; 776 FX_FLOAT off_phase;
780 if (i == pGraphState->m_DashCount - 1) { 777 if (i == pGraphState->m_DashCount - 1) {
781 off_phase = on_phase; 778 off_phase = on_phase;
782 } else { 779 } else {
783 off_phase = pGraphState->m_DashArray[i + 1]; 780 off_phase = pGraphState->m_DashArray[i + 1];
784 } 781 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 CGdiplusExt& GdiplusExt = ((CWin32Platform*)CFX_GEModule::Get()->GetPlatform Data())->m_GdiplusExt; 863 CGdiplusExt& GdiplusExt = ((CWin32Platform*)CFX_GEModule::Get()->GetPlatform Data())->m_GdiplusExt;
867 CallFunc(GdipCreateFromHDC)(hDC, &pGraphics); 864 CallFunc(GdipCreateFromHDC)(hDC, &pGraphics);
868 CallFunc(GdipSetPageUnit)(pGraphics, UnitPixel); 865 CallFunc(GdipSetPageUnit)(pGraphics, UnitPixel);
869 CallFunc(GdipSetPixelOffsetMode)(pGraphics, PixelOffsetModeHalf); 866 CallFunc(GdipSetPixelOffsetMode)(pGraphics, PixelOffsetModeHalf);
870 GpMatrix* pMatrix = NULL; 867 GpMatrix* pMatrix = NULL;
871 if (pObject2Device) { 868 if (pObject2Device) {
872 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);
873 CallFunc(GdipSetWorldTransform)(pGraphics, pMatrix); 870 CallFunc(GdipSetWorldTransform)(pGraphics, pMatrix);
874 } 871 }
875 PointF *points = FX_Alloc(PointF, nPoints); 872 PointF *points = FX_Alloc(PointF, nPoints);
876 if (!points) {
877 return FALSE;
878 }
879 BYTE * types = FX_Alloc(BYTE, nPoints); 873 BYTE * types = FX_Alloc(BYTE, nPoints);
880 if (!types) {
881 FX_Free(points);
882 return FALSE;
883 }
884 int nSubPathes = 0; 874 int nSubPathes = 0;
885 FX_BOOL bSubClose = FALSE; 875 FX_BOOL bSubClose = FALSE;
886 int pos_subclose = 0; 876 int pos_subclose = 0;
887 FX_BOOL bSmooth = FALSE; 877 FX_BOOL bSmooth = FALSE;
888 int startpoint = 0; 878 int startpoint = 0;
889 for(int i = 0; i < nPoints; i++) { 879 for(int i = 0; i < nPoints; i++) {
890 points[i].X = pPoints[i].m_PointX; 880 points[i].X = pPoints[i].m_PointX;
891 points[i].Y = pPoints[i].m_PointY; 881 points[i].Y = pPoints[i].m_PointY;
892 FX_FLOAT x, y; 882 FX_FLOAT x, y;
893 if (pObject2Device) { 883 if (pObject2Device) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 dest_pixel_format = PixelFormat1bppIndexed; 1181 dest_pixel_format = PixelFormat1bppIndexed;
1192 } else if (pixel_format == PixelFormat8bppIndexed) { 1182 } else if (pixel_format == PixelFormat8bppIndexed) {
1193 info_size += 1024; 1183 info_size += 1024;
1194 bpp = 8; 1184 bpp = 8;
1195 dest_pixel_format = PixelFormat8bppIndexed; 1185 dest_pixel_format = PixelFormat8bppIndexed;
1196 } else if (pixel_format == PixelFormat32bppARGB) { 1186 } else if (pixel_format == PixelFormat32bppARGB) {
1197 bpp = 32; 1187 bpp = 32;
1198 dest_pixel_format = PixelFormat32bppARGB; 1188 dest_pixel_format = PixelFormat32bppARGB;
1199 } 1189 }
1200 LPBYTE buf = FX_Alloc(BYTE, info_size); 1190 LPBYTE buf = FX_Alloc(BYTE, info_size);
1201 if (!buf) {
1202 if (pStream) {
1203 pStream->Release();
1204 }
1205 return NULL;
1206 }
1207 BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)buf; 1191 BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)buf;
1208 pbmih->biBitCount = bpp; 1192 pbmih->biBitCount = bpp;
1209 pbmih->biCompression = BI_RGB; 1193 pbmih->biCompression = BI_RGB;
1210 pbmih->biHeight = -(int)height; 1194 pbmih->biHeight = -(int)height;
1211 pbmih->biPlanes = 1; 1195 pbmih->biPlanes = 1;
1212 pbmih->biWidth = width; 1196 pbmih->biWidth = width;
1213 Rect rect(0, 0, width, height); 1197 Rect rect(0, 0, width, height);
1214 BitmapData* pBitmapData = FX_Alloc(BitmapData, 1); 1198 BitmapData* pBitmapData = FX_Alloc(BitmapData, 1);
1215 if (!pBitmapData) {
1216 if (pStream) {
1217 pStream->Release();
1218 }
1219 return NULL;
1220 }
1221 CallFunc(GdipBitmapLockBits)(pBitmap, &rect, ImageLockModeRead, 1199 CallFunc(GdipBitmapLockBits)(pBitmap, &rect, ImageLockModeRead,
1222 dest_pixel_format, pBitmapData); 1200 dest_pixel_format, pBitmapData);
1223 if (pixel_format == PixelFormat1bppIndexed || pixel_format == PixelFormat8bp pIndexed) { 1201 if (pixel_format == PixelFormat1bppIndexed || pixel_format == PixelFormat8bp pIndexed) {
1224 DWORD* ppal = (DWORD*)(buf + sizeof(BITMAPINFOHEADER)); 1202 DWORD* ppal = (DWORD*)(buf + sizeof(BITMAPINFOHEADER));
1225 struct { 1203 struct {
1226 UINT flags; 1204 UINT flags;
1227 UINT Count; 1205 UINT Count;
1228 DWORD Entries[256]; 1206 DWORD Entries[256];
1229 } pal; 1207 } pal;
1230 int size = 0; 1208 int size = 0;
1231 CallFunc(GdipGetImagePaletteSize)(pBitmap, &size); 1209 CallFunc(GdipGetImagePaletteSize)(pBitmap, &size);
1232 CallFunc(GdipGetImagePalette)(pBitmap, (ColorPalette*)&pal, size); 1210 CallFunc(GdipGetImagePalette)(pBitmap, (ColorPalette*)&pal, size);
1233 int entries = pixel_format == PixelFormat1bppIndexed ? 2 : 256; 1211 int entries = pixel_format == PixelFormat1bppIndexed ? 2 : 256;
1234 for (int i = 0; i < entries; i ++) { 1212 for (int i = 0; i < entries; i ++) {
1235 ppal[i] = pal.Entries[i] & 0x00ffffff; 1213 ppal[i] = pal.Entries[i] & 0x00ffffff;
1236 } 1214 }
1237 } 1215 }
1238 PREVIEW3_DIBITMAP* pInfo = FX_Alloc(PREVIEW3_DIBITMAP, 1); 1216 PREVIEW3_DIBITMAP* pInfo = FX_Alloc(PREVIEW3_DIBITMAP, 1);
1239 if (!pInfo) {
1240 if (pStream) {
1241 pStream->Release();
1242 }
1243 return NULL;
1244 }
1245 pInfo->pbmi = (BITMAPINFO*)buf; 1217 pInfo->pbmi = (BITMAPINFO*)buf;
1246 pInfo->pScan0 = (LPBYTE)pBitmapData->Scan0; 1218 pInfo->pScan0 = (LPBYTE)pBitmapData->Scan0;
1247 pInfo->Stride = pBitmapData->Stride; 1219 pInfo->Stride = pBitmapData->Stride;
1248 pInfo->pBitmap = pBitmap; 1220 pInfo->pBitmap = pBitmap;
1249 pInfo->pBitmapData = pBitmapData; 1221 pInfo->pBitmapData = pBitmapData;
1250 pInfo->pStream = pStream; 1222 pInfo->pStream = pStream;
1251 return pInfo; 1223 return pInfo;
1252 } 1224 }
1253 static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) 1225 static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo)
1254 { 1226 {
(...skipping 24 matching lines...) Expand all
1279 for (int i = 0; i < height; i ++) { 1251 for (int i = 0; i < height; i ++) {
1280 FXSYS_memcpy32(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, dest_pitch); 1252 FXSYS_memcpy32(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, dest_pitch);
1281 } 1253 }
1282 } 1254 }
1283 CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(pInfo->pbmi, pData, pIn fo->pbmi->bmiHeader.biBitCount == 32); 1255 CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(pInfo->pbmi, pData, pIn fo->pbmi->bmiHeader.biBitCount == 32);
1284 FX_Free(pData); 1256 FX_Free(pData);
1285 FreeDIBitmap(pInfo); 1257 FreeDIBitmap(pInfo);
1286 return pDIBitmap; 1258 return pDIBitmap;
1287 } 1259 }
1288 #endif 1260 #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