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

Side by Side Diff: core/src/fxge/skia/fx_skia_device.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 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/src/fxge/skia/fx_skia_blitter_new.cpp ('k') | core/src/fxge/win32/fx_win32_device.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 #include "core/include/fxge/fx_ge.h" 5 #include "core/include/fxge/fx_ge.h"
6 6
7 #if defined(_SKIA_SUPPORT_) 7 #if defined(_SKIA_SUPPORT_)
8 #include "core/include/fxcodec/fx_codec.h" 8 #include "core/include/fxcodec/fx_codec.h"
9 9
10 #include "SkDashPathEffect.h" 10 #include "SkDashPathEffect.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 default: 205 default:
206 join = SkPaint::kMiter_Join; 206 join = SkPaint::kMiter_Join;
207 break; 207 break;
208 } 208 }
209 FX_FIXFLOAT width = pGraphState->m_LineWidth * scale; 209 FX_FIXFLOAT width = pGraphState->m_LineWidth * scale;
210 FX_FIXFLOAT unit = fix32_to_8(fixdiv_8_8_to_32( 210 FX_FIXFLOAT unit = fix32_to_8(fixdiv_8_8_to_32(
211 FIX8_ONE, (pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2)); 211 FIX8_ONE, (pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2));
212 if (width <= unit) 212 if (width <= unit)
213 width = unit; 213 width = unit;
214 214
215 if (pGraphState->m_DashArray == NULL) { 215 if (pGraphState->m_DashArray) {
216 SkStroke stroker;
217 stroker.setCap(cap);
218 stroker.setJoin(join);
219 stroker.setMiterLimit(pGraphState->m_MiterLimit);
220 stroker.setWidth(width);
221 stroker.setDoFill(FALSE);
222 stroker.strokePath(path_data, dstPathData);
223 SkMatrix smatrix;
224 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e,
225 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0,
226 0, 1);
227 dstPathData->transform(smatrix);
228 } else {
229 int count = (pGraphState->m_DashCount + 1) / 2; 216 int count = (pGraphState->m_DashCount + 1) / 2;
230 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); 217 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar));
231 // Set dash pattern 218 // Set dash pattern
232 for (int i = 0; i < count; i++) { 219 for (int i = 0; i < count; i++) {
233 FX_FIXFLOAT on = pGraphState->m_DashArray[i * 2]; 220 FX_FIXFLOAT on = pGraphState->m_DashArray[i * 2];
234 if (on <= 0.000001f) 221 if (on <= 0.000001f)
235 on = FIX8_ONE / 10; 222 on = FIX8_ONE / 10;
236 FX_FIXFLOAT off = i * 2 + 1 == pGraphState->m_DashCount 223 FX_FIXFLOAT off = i * 2 + 1 == pGraphState->m_DashCount
237 ? on 224 ? on
238 : pGraphState->m_DashArray[i * 2 + 1]; 225 : pGraphState->m_DashArray[i * 2 + 1];
239 if (off < 0) 226 if (off < 0)
240 off = 0; 227 off = 0;
241 intervals[i * 2] = on * scale; 228 intervals[i * 2] = on * scale;
242 intervals[i * 2 + 1] = off * scale; 229 intervals[i * 2 + 1] = off * scale;
243 } 230 }
244 SkDashPathEffect* pEffect = new SkDashPathEffect( 231 SkDashPathEffect* pEffect = new SkDashPathEffect(
245 intervals, count * 2, pGraphState->m_DashPhase * scale); 232 intervals, count * 2, pGraphState->m_DashPhase * scale);
246 spaint.setPathEffect(pEffect)->unref(); 233 spaint.setPathEffect(pEffect)->unref();
247 spaint.setStrokeWidth(width); 234 spaint.setStrokeWidth(width);
248 spaint.setStrokeMiter(pGraphState->m_MiterLimit); 235 spaint.setStrokeMiter(pGraphState->m_MiterLimit);
249 spaint.setStrokeCap(cap); 236 spaint.setStrokeCap(cap);
250 spaint.setStrokeJoin(join); 237 spaint.setStrokeJoin(join);
251 spaint.getFillPath(path_data, dstPathData); 238 spaint.getFillPath(path_data, dstPathData);
252 SkMatrix smatrix; 239 SkMatrix smatrix;
253 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, 240 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e,
254 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, 241 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0,
255 0, 1); 242 0, 1);
256 dstPathData->transform(smatrix); 243 dstPathData->transform(smatrix);
257 FX_Free(intervals); 244 FX_Free(intervals);
245 } else {
246 SkStroke stroker;
247 stroker.setCap(cap);
248 stroker.setJoin(join);
249 stroker.setMiterLimit(pGraphState->m_MiterLimit);
250 stroker.setWidth(width);
251 stroker.setDoFill(FALSE);
252 stroker.strokePath(path_data, dstPathData);
253 SkMatrix smatrix;
254 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e,
255 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0,
256 0, 1);
257 dstPathData->transform(smatrix);
258 } 258 }
259 } 259 }
260 260
261 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, 261 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap,
262 int dither_bits, 262 int dither_bits,
263 FX_BOOL bRgbByteOrder, 263 FX_BOOL bRgbByteOrder,
264 CFX_DIBitmap* pOriDevice, 264 CFX_DIBitmap* pOriDevice,
265 FX_BOOL bGroupKnockout) { 265 FX_BOOL bGroupKnockout) {
266 m_pAggDriver = new CFX_AggDeviceDriver(pBitmap, dither_bits, bRgbByteOrder, 266 m_pAggDriver = new CFX_AggDeviceDriver(pBitmap, dither_bits, bRgbByteOrder,
267 pOriDevice, bGroupKnockout); 267 pOriDevice, bGroupKnockout);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 // Finally, we have got the mask that we need, intersect with current clip 325 // Finally, we have got the mask that we need, intersect with current clip
326 // region 326 // region
327 m_pAggDriver->m_pClipRgn->IntersectMaskF(clip_box.fLeft, clip_box.fTop, mask); 327 m_pAggDriver->m_pClipRgn->IntersectMaskF(clip_box.fLeft, clip_box.fTop, mask);
328 } 328 }
329 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( 329 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill(
330 const CFX_PathData* pPathData, // path info 330 const CFX_PathData* pPathData, // path info
331 const CFX_Matrix* pObject2Device, // optional transformation 331 const CFX_Matrix* pObject2Device, // optional transformation
332 int fill_mode // fill mode, WINDING or ALTERNATE 332 int fill_mode // fill mode, WINDING or ALTERNATE
333 ) { 333 ) {
334 if (m_pAggDriver->m_pClipRgn == NULL) 334 if (!m_pAggDriver->m_pClipRgn) {
335 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( 335 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn(
336 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 336 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
337 }
337 338
338 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { 339 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) {
339 CFX_FloatRect rectf; 340 CFX_FloatRect rectf;
340 if (pPathData->IsRect(pObject2Device, &rectf)) { 341 if (pPathData->IsRect(pObject2Device, &rectf)) {
341 rectf.Intersect( 342 rectf.Intersect(
342 CFX_FloatRect(0, 0, (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), 343 CFX_FloatRect(0, 0, (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH),
343 (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); 344 (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
344 FX_RECT rect = rectf.GetOutterRect(); 345 FX_RECT rect = rectf.GetOutterRect();
345 m_pAggDriver->m_pClipRgn->IntersectRect(rect); 346 m_pAggDriver->m_pClipRgn->IntersectRect(rect);
346 return TRUE; 347 return TRUE;
(...skipping 14 matching lines...) Expand all
361 SetClipMask(path_data.m_PathData, &spaint); 362 SetClipMask(path_data.m_PathData, &spaint);
362 363
363 return TRUE; 364 return TRUE;
364 } 365 }
365 366
366 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( 367 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke(
367 const CFX_PathData* pPathData, // path info 368 const CFX_PathData* pPathData, // path info
368 const CFX_Matrix* pObject2Device, // optional transformation 369 const CFX_Matrix* pObject2Device, // optional transformation
369 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes 370 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes
370 ) { 371 ) {
371 if (m_pAggDriver->m_pClipRgn == NULL) 372 if (!m_pAggDriver->m_pClipRgn) {
372 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( 373 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn(
373 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 374 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
375 }
374 376
375 // build path data 377 // build path data
376 CSkia_PathData path_data; 378 CSkia_PathData path_data;
377 path_data.BuildPath(pPathData, NULL); 379 path_data.BuildPath(pPathData, NULL);
378 path_data.m_PathData.setFillType(SkPath::kWinding_FillType); 380 path_data.m_PathData.setFillType(SkPath::kWinding_FillType);
379 381
380 SkPaint spaint; 382 SkPaint spaint;
381 spaint.setColor(0xffffffff); 383 spaint.setColor(0xffffffff);
382 spaint.setStyle(SkPaint::kStroke_Style); 384 spaint.setStyle(SkPaint::kStroke_Style);
383 spaint.setAntiAlias(TRUE); 385 spaint.setAntiAlias(TRUE);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 427
426 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( 428 FX_BOOL CFX_SkiaDeviceDriver::DrawPath(
427 const CFX_PathData* pPathData, // path info 429 const CFX_PathData* pPathData, // path info
428 const CFX_Matrix* pObject2Device, // optional transformation 430 const CFX_Matrix* pObject2Device, // optional transformation
429 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes 431 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes
430 FX_DWORD fill_color, // fill color 432 FX_DWORD fill_color, // fill color
431 FX_DWORD stroke_color, // stroke color 433 FX_DWORD stroke_color, // stroke color
432 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled 434 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled
433 int alpha_flag, 435 int alpha_flag,
434 void* pIccTransform) { 436 void* pIccTransform) {
435 if (GetBuffer() == NULL) 437 if (!GetBuffer())
436 return TRUE; 438 return TRUE;
437 FOXIT_DEBUG1("CFX_SkiaDeviceDriver::DrawPath: entering"); 439 FOXIT_DEBUG1("CFX_SkiaDeviceDriver::DrawPath: entering");
438 SkIRect rect; 440 SkIRect rect;
439 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), 441 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH),
440 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 442 GetDeviceCaps(FXDC_PIXEL_HEIGHT));
441 if ((fill_mode & 3) && fill_color) { 443 if ((fill_mode & 3) && fill_color) {
442 // We have to transform before building path data, otherwise we'll have 444 // We have to transform before building path data, otherwise we'll have
443 // flatting problem 445 // flatting problem
444 // when we enlarge a small path (flatten before transformed) 446 // when we enlarge a small path (flatten before transformed)
445 // TESTDOC: Bug #5115 - DS_S1Dimpact_lr.pdf 447 // TESTDOC: Bug #5115 - DS_S1Dimpact_lr.pdf
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 587
586 CFX_SkiaDevice::CFX_SkiaDevice() { 588 CFX_SkiaDevice::CFX_SkiaDevice() {
587 m_bOwnedBitmap = FALSE; 589 m_bOwnedBitmap = FALSE;
588 } 590 }
589 591
590 FX_BOOL CFX_SkiaDevice::Attach(CFX_DIBitmap* pBitmap, 592 FX_BOOL CFX_SkiaDevice::Attach(CFX_DIBitmap* pBitmap,
591 int dither_bits, 593 int dither_bits,
592 FX_BOOL bRgbByteOrder, 594 FX_BOOL bRgbByteOrder,
593 CFX_DIBitmap* pOriDevice, 595 CFX_DIBitmap* pOriDevice,
594 FX_BOOL bGroupKnockout) { 596 FX_BOOL bGroupKnockout) {
595 if (pBitmap == NULL) 597 if (!pBitmap)
596 return FALSE; 598 return FALSE;
597 SetBitmap(pBitmap); 599 SetBitmap(pBitmap);
598 CFX_SkiaDeviceDriver* pDriver = new CFX_SkiaDeviceDriver( 600 CFX_SkiaDeviceDriver* pDriver = new CFX_SkiaDeviceDriver(
599 pBitmap, dither_bits, bRgbByteOrder, pOriDevice, bGroupKnockout); 601 pBitmap, dither_bits, bRgbByteOrder, pOriDevice, bGroupKnockout);
600 SetDeviceDriver(pDriver); 602 SetDeviceDriver(pDriver);
601 return TRUE; 603 return TRUE;
602 } 604 }
603 605
604 FX_BOOL CFX_SkiaDevice::Create(int width, 606 FX_BOOL CFX_SkiaDevice::Create(int width,
605 int height, 607 int height,
(...skipping 11 matching lines...) Expand all
617 new CFX_SkiaDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE); 619 new CFX_SkiaDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE);
618 SetDeviceDriver(pDriver); 620 SetDeviceDriver(pDriver);
619 return TRUE; 621 return TRUE;
620 } 622 }
621 CFX_SkiaDevice::~CFX_SkiaDevice() { 623 CFX_SkiaDevice::~CFX_SkiaDevice() {
622 if (m_bOwnedBitmap && GetBitmap()) 624 if (m_bOwnedBitmap && GetBitmap())
623 delete GetBitmap(); 625 delete GetBitmap();
624 } 626 }
625 627
626 #endif 628 #endif
OLDNEW
« no previous file with comments | « core/src/fxge/skia/fx_skia_blitter_new.cpp ('k') | core/src/fxge/win32/fx_win32_device.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698