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

Side by Side Diff: core/fxge/agg/fx_agg_driver.cpp

Issue 2163103002: Use smart pointers for graphics device classes (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: vector change Created 4 years, 5 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
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 "core/fxge/agg/fx_agg_driver.h" 7 #include "core/fxge/agg/fx_agg_driver.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 stroke.line_cap(cap); 413 stroke.line_cap(cap);
414 stroke.miter_limit(pGraphState->m_MiterLimit); 414 stroke.miter_limit(pGraphState->m_MiterLimit);
415 stroke.width(width); 415 stroke.width(width);
416 rasterizer.add_path_transformed(stroke, pObject2Device); 416 rasterizer.add_path_transformed(stroke, pObject2Device);
417 } 417 }
418 } 418 }
419 419
420 CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap, 420 CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap,
421 FX_BOOL bRgbByteOrder, 421 FX_BOOL bRgbByteOrder,
422 CFX_DIBitmap* pOriDevice, 422 CFX_DIBitmap* pOriDevice,
423 FX_BOOL bGroupKnockout) { 423 FX_BOOL bGroupKnockout)
424 m_pBitmap = pBitmap; 424 : m_pBitmap(pBitmap),
425 m_pClipRgn = nullptr; 425 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
426 m_pPlatformBitmap = nullptr; 426 m_pPlatformGraphics(nullptr),
427 m_pPlatformGraphics = nullptr; 427 #endif
428 m_pDwRenderTartget = nullptr; 428 m_FillFlags(0),
429 m_bRgbByteOrder = bRgbByteOrder; 429 m_bRgbByteOrder(bRgbByteOrder),
430 m_pOriDevice = pOriDevice; 430 m_pOriDevice(pOriDevice),
431 m_bGroupKnockout = bGroupKnockout; 431 m_bGroupKnockout(bGroupKnockout) {
432 m_FillFlags = 0;
433 InitPlatform(); 432 InitPlatform();
434 } 433 }
435 434
436 CFX_AggDeviceDriver::~CFX_AggDeviceDriver() { 435 CFX_AggDeviceDriver::~CFX_AggDeviceDriver() {
437 delete m_pClipRgn;
438 for (int i = 0; i < m_StateStack.GetSize(); i++)
439 delete m_StateStack[i];
440 DestroyPlatform(); 436 DestroyPlatform();
441 } 437 }
442 438
443 uint8_t* CFX_AggDeviceDriver::GetBuffer() const { 439 uint8_t* CFX_AggDeviceDriver::GetBuffer() const {
444 return m_pBitmap->GetBuffer(); 440 return m_pBitmap->GetBuffer();
445 } 441 }
446 442
447 const CFX_DIBitmap* CFX_AggDeviceDriver::GetBitmap() const { 443 const CFX_DIBitmap* CFX_AggDeviceDriver::GetBitmap() const {
448 return m_pBitmap; 444 return m_pBitmap;
449 } 445 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 if (m_pBitmap->IsCmykImage()) { 488 if (m_pBitmap->IsCmykImage()) {
493 flags |= FXRC_CMYK_OUTPUT; 489 flags |= FXRC_CMYK_OUTPUT;
494 } 490 }
495 return flags; 491 return flags;
496 } 492 }
497 } 493 }
498 return 0; 494 return 0;
499 } 495 }
500 496
501 void CFX_AggDeviceDriver::SaveState() { 497 void CFX_AggDeviceDriver::SaveState() {
502 CFX_ClipRgn* pClip = nullptr; 498 std::unique_ptr<CFX_ClipRgn> pClip;
503 if (m_pClipRgn) { 499 if (m_pClipRgn)
504 pClip = new CFX_ClipRgn(*m_pClipRgn); 500 pClip.reset(new CFX_ClipRgn(*m_pClipRgn));
505 } 501 m_StateStack.push_back(std::move(pClip));
506 m_StateStack.Add(pClip);
507 } 502 }
508 503
509 void CFX_AggDeviceDriver::RestoreState(bool bKeepSaved) { 504 void CFX_AggDeviceDriver::RestoreState(bool bKeepSaved) {
510 delete m_pClipRgn; 505 m_pClipRgn.reset();
511 m_pClipRgn = nullptr;
512 506
513 int size = m_StateStack.GetSize(); 507 if (m_StateStack.empty())
514 if (!size)
515 return; 508 return;
516 509
517 CFX_ClipRgn* pSavedClip = m_StateStack[size - 1];
518 if (bKeepSaved) { 510 if (bKeepSaved) {
519 if (pSavedClip) { 511 if (m_StateStack.back())
520 m_pClipRgn = new CFX_ClipRgn(*pSavedClip); 512 m_pClipRgn.reset(new CFX_ClipRgn(*m_StateStack.back()));
521 }
522 } else { 513 } else {
523 m_StateStack.RemoveAt(size - 1); 514 m_pClipRgn = std::move(m_StateStack.back());
524 m_pClipRgn = pSavedClip; 515 m_StateStack.pop_back();
525 } 516 }
526 } 517 }
527 518
528 void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { 519 void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) {
529 FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(), 520 FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(),
530 rasterizer.max_x() + 1, rasterizer.max_y() + 1); 521 rasterizer.max_x() + 1, rasterizer.max_y() + 1);
531 path_rect.Intersect(m_pClipRgn->GetBox()); 522 path_rect.Intersect(m_pClipRgn->GetBox());
532 CFX_DIBitmapRef mask; 523 CFX_DIBitmapRef mask;
533 CFX_DIBitmap* pThisLayer = mask.New(); 524 CFX_DIBitmap* pThisLayer = mask.New();
534 if (!pThisLayer) { 525 if (!pThisLayer) {
(...skipping 13 matching lines...) Expand all
548 agg::render_scanlines(rasterizer, scanline, final_render, 539 agg::render_scanlines(rasterizer, scanline, final_render,
549 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); 540 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0);
550 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); 541 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask);
551 } 542 }
552 543
553 FX_BOOL CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData, 544 FX_BOOL CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
554 const CFX_Matrix* pObject2Device, 545 const CFX_Matrix* pObject2Device,
555 int fill_mode) { 546 int fill_mode) {
556 m_FillFlags = fill_mode; 547 m_FillFlags = fill_mode;
557 if (!m_pClipRgn) { 548 if (!m_pClipRgn) {
558 m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), 549 m_pClipRgn.reset(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH),
559 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 550 GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
560 } 551 }
561 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { 552 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) {
562 CFX_FloatRect rectf; 553 CFX_FloatRect rectf;
563 if (pPathData->IsRect(pObject2Device, &rectf)) { 554 if (pPathData->IsRect(pObject2Device, &rectf)) {
564 rectf.Intersect( 555 rectf.Intersect(
565 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), 556 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH),
566 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); 557 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
567 FX_RECT rect = rectf.GetOutterRect(); 558 FX_RECT rect = rectf.GetOutterRect();
568 m_pClipRgn->IntersectRect(rect); 559 m_pClipRgn->IntersectRect(rect);
569 return TRUE; 560 return TRUE;
(...skipping 11 matching lines...) Expand all
581 : agg::fill_even_odd); 572 : agg::fill_even_odd);
582 SetClipMask(rasterizer); 573 SetClipMask(rasterizer);
583 return TRUE; 574 return TRUE;
584 } 575 }
585 576
586 FX_BOOL CFX_AggDeviceDriver::SetClip_PathStroke( 577 FX_BOOL CFX_AggDeviceDriver::SetClip_PathStroke(
587 const CFX_PathData* pPathData, 578 const CFX_PathData* pPathData,
588 const CFX_Matrix* pObject2Device, 579 const CFX_Matrix* pObject2Device,
589 const CFX_GraphStateData* pGraphState) { 580 const CFX_GraphStateData* pGraphState) {
590 if (!m_pClipRgn) { 581 if (!m_pClipRgn) {
591 m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), 582 m_pClipRgn.reset(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH),
592 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 583 GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
593 } 584 }
594 CAgg_PathData path_data; 585 CAgg_PathData path_data;
595 path_data.BuildPath(pPathData, nullptr); 586 path_data.BuildPath(pPathData, nullptr);
596 agg::rasterizer_scanline_aa rasterizer; 587 agg::rasterizer_scanline_aa rasterizer;
597 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), 588 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
598 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); 589 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
599 RasterizeStroke(rasterizer, path_data.m_PathData, pObject2Device, 590 RasterizeStroke(rasterizer, path_data.m_PathData, pObject2Device,
600 pGraphState); 591 pGraphState);
601 rasterizer.filling_rule(agg::fill_non_zero); 592 rasterizer.filling_rule(agg::fill_non_zero);
602 SetClipMask(rasterizer); 593 SetClipMask(rasterizer);
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 1428
1438 FX_BOOL CFX_AggDeviceDriver::RenderRasterizer( 1429 FX_BOOL CFX_AggDeviceDriver::RenderRasterizer(
1439 agg::rasterizer_scanline_aa& rasterizer, 1430 agg::rasterizer_scanline_aa& rasterizer,
1440 uint32_t color, 1431 uint32_t color,
1441 FX_BOOL bFullCover, 1432 FX_BOOL bFullCover,
1442 FX_BOOL bGroupKnockout, 1433 FX_BOOL bGroupKnockout,
1443 int alpha_flag, 1434 int alpha_flag,
1444 void* pIccTransform) { 1435 void* pIccTransform) {
1445 CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr; 1436 CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr;
1446 CFX_Renderer render; 1437 CFX_Renderer render;
1447 if (!render.Init(m_pBitmap, pt, m_pClipRgn, color, bFullCover, 1438 if (!render.Init(m_pBitmap, pt, m_pClipRgn.get(), color, bFullCover,
1448 m_bRgbByteOrder, alpha_flag, pIccTransform)) { 1439 m_bRgbByteOrder, alpha_flag, pIccTransform)) {
1449 return FALSE; 1440 return FALSE;
1450 } 1441 }
1451 agg::scanline_u8 scanline; 1442 agg::scanline_u8 scanline;
1452 agg::render_scanlines(rasterizer, scanline, render, 1443 agg::render_scanlines(rasterizer, scanline, render,
1453 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); 1444 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0);
1454 return TRUE; 1445 return TRUE;
1455 } 1446 }
1456 1447
1457 FX_BOOL CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData, 1448 FX_BOOL CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 FX_BOOL CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, 1643 FX_BOOL CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
1653 uint32_t argb, 1644 uint32_t argb,
1654 const FX_RECT* pSrcRect, 1645 const FX_RECT* pSrcRect,
1655 int left, 1646 int left,
1656 int top, 1647 int top,
1657 int blend_type) { 1648 int blend_type) {
1658 if (!m_pBitmap->GetBuffer()) 1649 if (!m_pBitmap->GetBuffer())
1659 return TRUE; 1650 return TRUE;
1660 1651
1661 if (pBitmap->IsAlphaMask()) { 1652 if (pBitmap->IsAlphaMask()) {
1662 return m_pBitmap->CompositeMask(left, top, pSrcRect->Width(), 1653 return m_pBitmap->CompositeMask(
1663 pSrcRect->Height(), pBitmap, argb, 1654 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb,
1664 pSrcRect->left, pSrcRect->top, blend_type, 1655 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(),
1665 m_pClipRgn, m_bRgbByteOrder, 0, nullptr); 1656 m_bRgbByteOrder, 0, nullptr);
1666 } 1657 }
1667 return m_pBitmap->CompositeBitmap( 1658 return m_pBitmap->CompositeBitmap(
1668 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, 1659 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left,
1669 pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder, nullptr); 1660 pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr);
1670 } 1661 }
1671 1662
1672 FX_BOOL CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, 1663 FX_BOOL CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
1673 uint32_t argb, 1664 uint32_t argb,
1674 int dest_left, 1665 int dest_left,
1675 int dest_top, 1666 int dest_top,
1676 int dest_width, 1667 int dest_width,
1677 int dest_height, 1668 int dest_height,
1678 const FX_RECT* pClipRect, 1669 const FX_RECT* pClipRect,
1679 uint32_t flags, 1670 uint32_t flags,
1680 int blend_type) { 1671 int blend_type) {
1681 if (!m_pBitmap->GetBuffer()) 1672 if (!m_pBitmap->GetBuffer())
1682 return TRUE; 1673 return TRUE;
1683 1674
1684 if (dest_width == pSource->GetWidth() && 1675 if (dest_width == pSource->GetWidth() &&
1685 dest_height == pSource->GetHeight()) { 1676 dest_height == pSource->GetHeight()) {
1686 FX_RECT rect(0, 0, dest_width, dest_height); 1677 FX_RECT rect(0, 0, dest_width, dest_height);
1687 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type); 1678 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type);
1688 } 1679 }
1689 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, 1680 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width,
1690 dest_top + dest_height); 1681 dest_top + dest_height);
1691 dest_rect.Normalize(); 1682 dest_rect.Normalize();
1692 FX_RECT dest_clip = dest_rect; 1683 FX_RECT dest_clip = dest_rect;
1693 dest_clip.Intersect(*pClipRect); 1684 dest_clip.Intersect(*pClipRect);
1694 CFX_BitmapComposer composer; 1685 CFX_BitmapComposer composer;
1695 composer.Compose(m_pBitmap, m_pClipRgn, 255, argb, dest_clip, FALSE, FALSE, 1686 composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, FALSE,
1696 FALSE, m_bRgbByteOrder, 0, nullptr, blend_type); 1687 FALSE, FALSE, m_bRgbByteOrder, 0, nullptr, blend_type);
1697 dest_clip.Offset(-dest_rect.left, -dest_rect.top); 1688 dest_clip.Offset(-dest_rect.left, -dest_rect.top);
1698 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, 1689 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height,
1699 dest_clip, flags); 1690 dest_clip, flags);
1700 if (stretcher.Start()) 1691 if (stretcher.Start())
1701 stretcher.Continue(nullptr); 1692 stretcher.Continue(nullptr);
1702 return TRUE; 1693 return TRUE;
1703 } 1694 }
1704 1695
1705 FX_BOOL CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, 1696 FX_BOOL CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
1706 int bitmap_alpha, 1697 int bitmap_alpha,
1707 uint32_t argb, 1698 uint32_t argb,
1708 const CFX_Matrix* pMatrix, 1699 const CFX_Matrix* pMatrix,
1709 uint32_t render_flags, 1700 uint32_t render_flags,
1710 void*& handle, 1701 void*& handle,
1711 int blend_type) { 1702 int blend_type) {
1712 if (!m_pBitmap->GetBuffer()) 1703 if (!m_pBitmap->GetBuffer())
1713 return TRUE; 1704 return TRUE;
1714 1705
1715 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; 1706 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer;
1716 pRenderer->Start(m_pBitmap, m_pClipRgn, pSource, bitmap_alpha, argb, pMatrix, 1707 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb,
1717 render_flags, m_bRgbByteOrder, 0, nullptr); 1708 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr);
1718 handle = pRenderer; 1709 handle = pRenderer;
1719 return TRUE; 1710 return TRUE;
1720 } 1711 }
1721 1712
1722 FX_BOOL CFX_AggDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { 1713 FX_BOOL CFX_AggDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) {
1723 if (!m_pBitmap->GetBuffer()) { 1714 if (!m_pBitmap->GetBuffer()) {
1724 return TRUE; 1715 return TRUE;
1725 } 1716 }
1726 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause); 1717 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause);
1727 } 1718 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 SetDeviceDriver(pDriver); 1759 SetDeviceDriver(pDriver);
1769 return true; 1760 return true;
1770 } 1761 }
1771 1762
1772 CFX_FxgeDevice::~CFX_FxgeDevice() { 1763 CFX_FxgeDevice::~CFX_FxgeDevice() {
1773 if (m_bOwnedBitmap) { 1764 if (m_bOwnedBitmap) {
1774 delete GetBitmap(); 1765 delete GetBitmap();
1775 } 1766 }
1776 } 1767 }
1777 #endif 1768 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698