OLD | NEW |
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 |
11 #include "core/fxcodec/fx_codec.h" | 11 #include "core/fxcodec/fx_codec.h" |
12 #include "core/fxcrt/fx_memory.h" | 12 #include "core/fxcrt/fx_memory.h" |
13 #include "core/fxge/cfx_fxgedevice.h" | 13 #include "core/fxge/cfx_fxgedevice.h" |
14 #include "core/fxge/cfx_gemodule.h" | 14 #include "core/fxge/cfx_gemodule.h" |
15 #include "core/fxge/cfx_graphstatedata.h" | 15 #include "core/fxge/cfx_graphstatedata.h" |
16 #include "core/fxge/cfx_pathdata.h" | 16 #include "core/fxge/cfx_pathdata.h" |
17 #include "core/fxge/cfx_renderdevice.h" | 17 #include "core/fxge/cfx_renderdevice.h" |
18 #include "core/fxge/dib/dib_int.h" | 18 #include "core/fxge/dib/dib_int.h" |
19 #include "core/fxge/ge/cfx_cliprgn.h" | 19 #include "core/fxge/ge/cfx_cliprgn.h" |
20 #include "core/fxge/ge/fx_text_int.h" | 20 #include "core/fxge/ge/fx_text_int.h" |
21 #include "core/fxge/ifx_renderdevicedriver.h" | 21 #include "core/fxge/ifx_renderdevicedriver.h" |
22 #include "third_party/agg23/agg_conv_dash.h" | 22 #include "third_party/agg23/agg_conv_dash.h" |
23 #include "third_party/agg23/agg_conv_stroke.h" | 23 #include "third_party/agg23/agg_conv_stroke.h" |
24 #include "third_party/agg23/agg_curves.h" | 24 #include "third_party/agg23/agg_curves.h" |
25 #include "third_party/agg23/agg_path_storage.h" | 25 #include "third_party/agg23/agg_path_storage.h" |
26 #include "third_party/agg23/agg_pixfmt_gray.h" | 26 #include "third_party/agg23/agg_pixfmt_gray.h" |
27 #include "third_party/agg23/agg_rasterizer_scanline_aa.h" | 27 #include "third_party/agg23/agg_rasterizer_scanline_aa.h" |
28 #include "third_party/agg23/agg_renderer_scanline.h" | 28 #include "third_party/agg23/agg_renderer_scanline.h" |
29 #include "third_party/agg23/agg_scanline_u.h" | 29 #include "third_party/agg23/agg_scanline_u.h" |
| 30 #include "third_party/base/ptr_util.h" |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 void HardClip(FX_FLOAT& x, FX_FLOAT& y) { | 34 void HardClip(FX_FLOAT& x, FX_FLOAT& y) { |
34 x = std::max(std::min(x, 50000.0f), -50000.0f); | 35 x = std::max(std::min(x, 50000.0f), -50000.0f); |
35 y = std::max(std::min(y, 50000.0f), -50000.0f); | 36 y = std::max(std::min(y, 50000.0f), -50000.0f); |
36 } | 37 } |
37 | 38 |
38 void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) { | 39 void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) { |
39 if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight()) | 40 if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight()) |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 492 } |
492 return flags; | 493 return flags; |
493 } | 494 } |
494 } | 495 } |
495 return 0; | 496 return 0; |
496 } | 497 } |
497 | 498 |
498 void CFX_AggDeviceDriver::SaveState() { | 499 void CFX_AggDeviceDriver::SaveState() { |
499 std::unique_ptr<CFX_ClipRgn> pClip; | 500 std::unique_ptr<CFX_ClipRgn> pClip; |
500 if (m_pClipRgn) | 501 if (m_pClipRgn) |
501 pClip = WrapUnique(new CFX_ClipRgn(*m_pClipRgn)); | 502 pClip = pdfium::MakeUnique<CFX_ClipRgn>(*m_pClipRgn); |
502 m_StateStack.push_back(std::move(pClip)); | 503 m_StateStack.push_back(std::move(pClip)); |
503 } | 504 } |
504 | 505 |
505 void CFX_AggDeviceDriver::RestoreState(bool bKeepSaved) { | 506 void CFX_AggDeviceDriver::RestoreState(bool bKeepSaved) { |
506 m_pClipRgn.reset(); | 507 m_pClipRgn.reset(); |
507 | 508 |
508 if (m_StateStack.empty()) | 509 if (m_StateStack.empty()) |
509 return; | 510 return; |
510 | 511 |
511 if (bKeepSaved) { | 512 if (bKeepSaved) { |
512 if (m_StateStack.back()) | 513 if (m_StateStack.back()) |
513 m_pClipRgn = WrapUnique(new CFX_ClipRgn(*m_StateStack.back())); | 514 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(*m_StateStack.back()); |
514 } else { | 515 } else { |
515 m_pClipRgn = std::move(m_StateStack.back()); | 516 m_pClipRgn = std::move(m_StateStack.back()); |
516 m_StateStack.pop_back(); | 517 m_StateStack.pop_back(); |
517 } | 518 } |
518 } | 519 } |
519 | 520 |
520 void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { | 521 void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { |
521 FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(), | 522 FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(), |
522 rasterizer.max_x() + 1, rasterizer.max_y() + 1); | 523 rasterizer.max_x() + 1, rasterizer.max_y() + 1); |
523 path_rect.Intersect(m_pClipRgn->GetBox()); | 524 path_rect.Intersect(m_pClipRgn->GetBox()); |
(...skipping 13 matching lines...) Expand all Loading... |
537 agg::render_scanlines(rasterizer, scanline, final_render, | 538 agg::render_scanlines(rasterizer, scanline, final_render, |
538 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); | 539 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); |
539 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); | 540 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); |
540 } | 541 } |
541 | 542 |
542 FX_BOOL CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData, | 543 FX_BOOL CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData, |
543 const CFX_Matrix* pObject2Device, | 544 const CFX_Matrix* pObject2Device, |
544 int fill_mode) { | 545 int fill_mode) { |
545 m_FillFlags = fill_mode; | 546 m_FillFlags = fill_mode; |
546 if (!m_pClipRgn) { | 547 if (!m_pClipRgn) { |
547 m_pClipRgn = WrapUnique(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), | 548 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( |
548 GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 549 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
549 } | 550 } |
550 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 551 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
551 CFX_FloatRect rectf; | 552 CFX_FloatRect rectf; |
552 if (pPathData->IsRect(pObject2Device, &rectf)) { | 553 if (pPathData->IsRect(pObject2Device, &rectf)) { |
553 rectf.Intersect( | 554 rectf.Intersect( |
554 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 555 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
555 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 556 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
556 FX_RECT rect = rectf.GetOuterRect(); | 557 FX_RECT rect = rectf.GetOuterRect(); |
557 m_pClipRgn->IntersectRect(rect); | 558 m_pClipRgn->IntersectRect(rect); |
558 return TRUE; | 559 return TRUE; |
(...skipping 11 matching lines...) Expand all Loading... |
570 : agg::fill_even_odd); | 571 : agg::fill_even_odd); |
571 SetClipMask(rasterizer); | 572 SetClipMask(rasterizer); |
572 return TRUE; | 573 return TRUE; |
573 } | 574 } |
574 | 575 |
575 FX_BOOL CFX_AggDeviceDriver::SetClip_PathStroke( | 576 FX_BOOL CFX_AggDeviceDriver::SetClip_PathStroke( |
576 const CFX_PathData* pPathData, | 577 const CFX_PathData* pPathData, |
577 const CFX_Matrix* pObject2Device, | 578 const CFX_Matrix* pObject2Device, |
578 const CFX_GraphStateData* pGraphState) { | 579 const CFX_GraphStateData* pGraphState) { |
579 if (!m_pClipRgn) { | 580 if (!m_pClipRgn) { |
580 m_pClipRgn = WrapUnique(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), | 581 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( |
581 GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 582 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
582 } | 583 } |
583 CAgg_PathData path_data; | 584 CAgg_PathData path_data; |
584 path_data.BuildPath(pPathData, nullptr); | 585 path_data.BuildPath(pPathData, nullptr); |
585 agg::rasterizer_scanline_aa rasterizer; | 586 agg::rasterizer_scanline_aa rasterizer; |
586 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), | 587 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), |
587 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 588 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
588 RasterizeStroke(rasterizer, path_data.m_PathData, pObject2Device, | 589 RasterizeStroke(rasterizer, path_data.m_PathData, pObject2Device, |
589 pGraphState); | 590 pGraphState); |
590 rasterizer.filling_rule(agg::fill_non_zero); | 591 rasterizer.filling_rule(agg::fill_non_zero); |
591 SetClipMask(rasterizer); | 592 SetClipMask(rasterizer); |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 } | 1729 } |
1729 | 1730 |
1730 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, | 1731 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, |
1731 bool bRgbByteOrder, | 1732 bool bRgbByteOrder, |
1732 CFX_DIBitmap* pOriDevice, | 1733 CFX_DIBitmap* pOriDevice, |
1733 bool bGroupKnockout) { | 1734 bool bGroupKnockout) { |
1734 if (!pBitmap) | 1735 if (!pBitmap) |
1735 return false; | 1736 return false; |
1736 | 1737 |
1737 SetBitmap(pBitmap); | 1738 SetBitmap(pBitmap); |
1738 SetDeviceDriver(WrapUnique(new CFX_AggDeviceDriver( | 1739 SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>( |
1739 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout))); | 1740 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout)); |
1740 return true; | 1741 return true; |
1741 } | 1742 } |
1742 | 1743 |
1743 bool CFX_FxgeDevice::Create(int width, | 1744 bool CFX_FxgeDevice::Create(int width, |
1744 int height, | 1745 int height, |
1745 FXDIB_Format format, | 1746 FXDIB_Format format, |
1746 CFX_DIBitmap* pOriDevice) { | 1747 CFX_DIBitmap* pOriDevice) { |
1747 m_bOwnedBitmap = true; | 1748 m_bOwnedBitmap = true; |
1748 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 1749 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
1749 if (!pBitmap->Create(width, height, format)) { | 1750 if (!pBitmap->Create(width, height, format)) { |
1750 delete pBitmap; | 1751 delete pBitmap; |
1751 return false; | 1752 return false; |
1752 } | 1753 } |
1753 SetBitmap(pBitmap); | 1754 SetBitmap(pBitmap); |
1754 SetDeviceDriver( | 1755 SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>(pBitmap, FALSE, |
1755 WrapUnique(new CFX_AggDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE))); | 1756 pOriDevice, FALSE)); |
1756 return true; | 1757 return true; |
1757 } | 1758 } |
1758 | 1759 |
1759 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1760 CFX_FxgeDevice::~CFX_FxgeDevice() { |
1760 if (m_bOwnedBitmap) { | 1761 if (m_bOwnedBitmap) { |
1761 delete GetBitmap(); | 1762 delete GetBitmap(); |
1762 } | 1763 } |
1763 } | 1764 } |
1764 #endif | 1765 #endif |
OLD | NEW |