7#include "core/fxge/agg/fx_agg_driver.h"
15#include "build/build_config.h"
16#include "core/fxcrt/fx_2d_size.h"
17#include "core/fxcrt/fx_safe_types.h"
18#include "core/fxcrt/unowned_ptr_exclusion.h"
19#include "core/fxge/cfx_cliprgn.h"
20#include "core/fxge/cfx_defaultrenderdevice.h"
21#include "core/fxge/cfx_graphstatedata.h"
22#include "core/fxge/cfx_path.h"
23#include "core/fxge/dib/cfx_dibitmap.h"
24#include "core/fxge/dib/cfx_imagerenderer.h"
25#include "core/fxge/dib/cfx_imagestretcher.h"
26#include "third_party/base/check.h"
27#include "third_party/base/check_op.h"
28#include "third_party/base/containers/span.h"
29#include "third_party/base/notreached.h"
33#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
36#include "third_party/agg23/agg_clip_liang_barsky.h"
37#include "third_party/agg23/agg_conv_dash.h"
38#include "third_party/agg23/agg_conv_stroke.h"
39#include "third_party/agg23/agg_curves.h"
40#include "third_party/agg23/agg_path_storage.h"
41#include "third_party/agg23/agg_pixfmt_gray.h"
42#include "third_party/agg23/agg_rasterizer_scanline_aa.h"
43#include "third_party/agg23/agg_renderer_scanline.h"
44#include "third_party/agg23/agg_scanline_u.h"
46#pragma GCC diagnostic pop
52const float kMaxPos = 32000.0f;
54CFX_PointF HardClip(
const CFX_PointF& pos) {
55 return CFX_PointF(
std::clamp(pos.x, -kMaxPos, kMaxPos),
56 std::clamp(pos.y, -kMaxPos, kMaxPos));
59void RgbByteOrderCompositeRect(
const RetainPtr<CFX_DIBitmap>& pBitmap,
70 rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
75 int Bpp = pBitmap->GetBPP() / 8;
77 pdfium::span<uint8_t> pBuffer = pBitmap->GetWritableBuffer();
78 if (src_alpha == 255) {
79 for (
int row = rect
.top; row < rect
.bottom; row++) {
81 pBuffer.subspan(row * pBitmap->GetPitch() + rect.left * Bpp).data();
83 std::fill_n(
reinterpret_cast<uint32_t*>(dest_scan), width, dib_argb);
85 for (
int col = 0; col < width; col++) {
94 bool bAlpha = pBitmap->IsAlphaFormat();
95 for (
int row = rect
.top; row < rect
.bottom; row++) {
97 pBuffer.subspan(row * pBitmap->GetPitch() + rect.left * Bpp).data();
99 for (
int col = 0; col < width; col++) {
100 uint8_t back_alpha = dest_scan[3];
101 if (back_alpha == 0) {
107 back_alpha + src_alpha - back_alpha * src_alpha / 255;
108 dest_scan[3] = dest_alpha;
109 int alpha_ratio = src_alpha * 255 / dest_alpha;
119 for (
int col = 0; col < width; col++) {
132void RgbByteOrderTransferBitmap(
RetainPtr<CFX_DIBitmap> pBitmap,
140 if (!pBitmap->GetOverlapRect(dest_left, dest_top, width, height,
141 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(),
142 src_left, src_top,
nullptr)) {
146 const int Bpp = pBitmap->GetBPP() / 8;
148 const FXDIB_Format src_format = pSrcBitmap->GetFormat();
149 const int dest_pitch = pBitmap->GetPitch();
151 const size_t dest_x_offset = Fx2DSizeOrDie(dest_left, Bpp);
152 const size_t dest_y_offset = Fx2DSizeOrDie(dest_top, dest_pitch);
154 pdfium::span<uint8_t> dest_span = pBitmap->GetWritableBuffer()
155 .subspan(dest_y_offset)
156 .subspan(dest_x_offset);
157 if (dest_format == src_format) {
158 const size_t src_x_offset = Fx2DSizeOrDie(src_left, Bpp);
159 for (
int row = 0; row < height; row++) {
160 uint8_t* dest_scan = dest_span.data();
161 const uint8_t* src_scan =
162 pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data();
164 for (
int col = 0; col < width; col++) {
166 *
reinterpret_cast<
const uint32_t*>(src_scan));
171 for (
int col = 0; col < width; col++) {
172 *dest_scan++ = src_scan[2];
173 *dest_scan++ = src_scan[1];
174 *dest_scan++ = src_scan[0];
178 dest_span = dest_span.subspan(dest_pitch);
185 const size_t src_x_offset = Fx2DSizeOrDie(src_left, 4);
186 for (
int row = 0; row < height; row++) {
187 uint8_t* dest_scan = dest_span.data();
188 const uint8_t* src_scan =
189 pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data();
190 for (
int col = 0; col < width; col++) {
191 *dest_scan++ = src_scan[2];
192 *dest_scan++ = src_scan[1];
193 *dest_scan++ = src_scan[0];
196 if (row < height - 1) {
200 dest_span = dest_span.subspan(dest_pitch);
206 DCHECK(dest_format == FXDIB_Format::kArgb ||
207 dest_format == FXDIB_Format::kRgb32);
209 const size_t src_x_offset = Fx2DSizeOrDie(src_left, 3);
210 for (
int row = 0; row < height; row++) {
211 uint8_t* dest_scan = dest_span.data();
212 const uint8_t* src_scan =
213 pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data();
214 for (
int col = 0; col < width; col++) {
220 dest_span = dest_span.subspan(dest_pitch);
227 const size_t src_x_offset = Fx2DSizeOrDie(src_left, 4);
228 for (
int row = 0; row < height; row++) {
229 uint8_t* dest_scan = dest_span.data();
230 const uint8_t* src_scan =
231 pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data();
232 for (
int col = 0; col < width; col++) {
238 dest_span = dest_span.subspan(dest_pitch);
242void RasterizeStroke(
agg::rasterizer_scanline_aa* rasterizer,
243 agg::path_storage* path_data,
251 cap =
agg::round_cap;
254 cap =
agg::square_cap;
260 agg::line_join_e join;
263 join =
agg::round_join;
266 join =
agg::bevel_join;
269 join =
agg::miter_join_revert;
274 if (pObject2Device) {
278 width =
std::max(width, unit);
279 if (!pGraphState->m_DashArray.empty()) {
280 using DashConverter = agg::conv_dash<agg::path_storage>;
281 DashConverter dash(*path_data);
282 for (size_t i = 0; i < (pGraphState->m_DashArray.size() + 1) / 2; i++) {
283 float on = pGraphState->m_DashArray[i * 2];
286 float off = i * 2 + 1 == pGraphState->m_DashArray.size()
288 : pGraphState->m_DashArray[i * 2 + 1];
289 off =
std::max(off, 0.0f);
290 dash.add_dash(on * scale, off * scale);
293 using DashStroke = agg::conv_stroke<DashConverter>;
294 DashStroke stroke(dash);
295 stroke.line_join(join);
296 stroke.line_cap(cap);
299 rasterizer->add_path_transformed(stroke, pObject2Device);
302 agg::conv_stroke<agg::path_storage> stroke(*path_data);
303 stroke.line_join(join);
304 stroke.line_cap(cap);
307 rasterizer->add_path_transformed(stroke, pObject2Device);
310agg::filling_rule_e GetAlternateOrWindingFillType(
314 :
agg::fill_even_odd;
325 return FX_RECT(0, 0, device->GetWidth(), device->GetHeight());
330 CFX_Renderer(
const RetainPtr<CFX_DIBitmap>& pDevice,
331 const RetainPtr<CFX_DIBitmap>& pBackdropDevice,
338 void prepare(
unsigned) {}
340 template <
class Scanline>
341 void render(
const Scanline& sl);
344 using CompositeSpanFunc =
void (CFX_Renderer::*)(uint8_t*,
353 void CompositeSpan(uint8_t* dest_scan,
354 const uint8_t* backdrop_scan,
359 const uint8_t* cover_scan,
362 const uint8_t* clip_scan);
364 void CompositeSpan1bpp(uint8_t* dest_scan,
368 const uint8_t* cover_scan,
371 const uint8_t* clip_scan);
373 void CompositeSpanGray(uint8_t* dest_scan,
377 const uint8_t* cover_scan,
380 const uint8_t* clip_scan);
382 void CompositeSpanARGB(uint8_t* dest_scan,
386 const uint8_t* cover_scan,
389 const uint8_t* clip_scan);
391 void CompositeSpanRGB(uint8_t* dest_scan,
395 const uint8_t* cover_scan,
398 const uint8_t* clip_scan);
400 void CompositeSpan1bppHelper(uint8_t* dest_scan,
403 const uint8_t* cover_scan,
404 const uint8_t* clip_scan,
407 static CompositeSpanFunc GetCompositeSpanFunc(
409 if (device->GetBPP() == 1)
410 return &CFX_Renderer::CompositeSpan1bpp;
411 if (device->GetBPP() == 8)
412 return &CFX_Renderer::CompositeSpanGray;
413 if (device->GetFormat() == FXDIB_Format::kArgb)
414 return &CFX_Renderer::CompositeSpanARGB;
415 return &CFX_Renderer::CompositeSpanRGB;
418 inline int GetSrcAlpha(
const uint8_t* clip_scan,
int col)
const {
419 return clip_scan ? m_Alpha * clip_scan[col] / 255 : m_Alpha;
422 inline int GetSourceAlpha(
const uint8_t* cover_scan,
423 const uint8_t* clip_scan,
425 return clip_scan ? m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255
426 : m_Alpha * cover_scan[col] / 255;
429 inline int GetColStart(
int span_left,
int clip_left)
const {
430 return span_left < clip_left ? clip_left - span_left : 0;
433 inline int GetColEnd(
int span_left,
int span_len,
int clip_right)
const {
434 return span_left + span_len < clip_right ? span_len
435 : clip_right - span_left;
443 const uint32_t m_Color;
444 const bool m_bFullCover;
445 const bool m_bRgbByteOrder;
447 RetainPtr<CFX_DIBitmap>
const m_pBackdropDevice;
448 RetainPtr<CFX_DIBitmap>
const m_pClipMask;
451 const CompositeSpanFunc m_CompositeSpanFunc;
454void CFX_Renderer::CompositeSpan(uint8_t* dest_scan,
455 const uint8_t* backdrop_scan,
460 const uint8_t* cover_scan,
463 const uint8_t* clip_scan) {
464 int col_start = GetColStart(span_left, clip_left);
465 int col_end = GetColEnd(span_left, span_len, clip_right);
467 dest_scan += col_start * Bpp;
468 backdrop_scan += col_start * Bpp;
470 dest_scan += col_start / 8;
471 backdrop_scan += col_start / 8;
473 if (m_bRgbByteOrder) {
474 if (Bpp == 4 && bDestAlpha) {
475 for (
int col = col_start; col < col_end; col++) {
476 int src_alpha = GetSrcAlpha(clip_scan, col);
478 backdrop_scan[3] + src_alpha - backdrop_scan[3] * src_alpha / 255;
479 dest_scan[3] = dest_alpha;
480 int alpha_ratio = src_alpha * 255 / dest_alpha;
505 if (Bpp == 3 || Bpp == 4) {
506 for (
int col = col_start; col < col_end; col++) {
507 int src_alpha = GetSrcAlpha(clip_scan, col);
511 backdrop_scan += Bpp - 2;
517 dest_scan += Bpp - 2;
522 if (Bpp == 4 && bDestAlpha) {
523 for (
int col = col_start; col < col_end; col++) {
524 int src_alpha = GetSrcAlpha(clip_scan, col);
525 int src_alpha_covered = src_alpha * cover_scan[col] / 255;
526 if (src_alpha_covered == 0) {
530 if (cover_scan[col] == 255) {
531 dest_scan[3] = src_alpha_covered;
532 *dest_scan++ = m_Blue;
533 *dest_scan++ = m_Green;
538 if (dest_scan[3] == 0) {
539 dest_scan[3] = src_alpha_covered;
540 *dest_scan++ = m_Blue;
541 *dest_scan++ = m_Green;
546 uint8_t cover = cover_scan[col];
557 if (Bpp == 3 || Bpp == 4) {
558 for (
int col = col_start; col < col_end; col++) {
559 int src_alpha = GetSrcAlpha(clip_scan, col);
564 dest_scan += Bpp - 2;
565 backdrop_scan += Bpp - 2;
571 backdrop_scan += Bpp - 2;
577 dest_scan += Bpp - 2;
582 for (
int col = col_start; col < col_end; col++) {
583 int src_alpha = GetSrcAlpha(clip_scan, col);
594 CompositeSpan1bppHelper(dest_scan, col_start, col_end, cover_scan, clip_scan,
598void CFX_Renderer::CompositeSpan1bpp(uint8_t* dest_scan,
602 const uint8_t* cover_scan,
605 const uint8_t* clip_scan) {
606 DCHECK(!m_bRgbByteOrder);
607 int col_start = GetColStart(span_left, clip_left);
608 int col_end = GetColEnd(span_left, span_len, clip_right);
609 dest_scan += col_start / 8;
610 CompositeSpan1bppHelper(dest_scan, col_start, col_end, cover_scan, clip_scan,
614void CFX_Renderer::CompositeSpanGray(uint8_t* dest_scan,
618 const uint8_t* cover_scan,
621 const uint8_t* clip_scan) {
622 DCHECK(!m_bRgbByteOrder);
623 int col_start = GetColStart(span_left, clip_left);
624 int col_end = GetColEnd(span_left, span_len, clip_right);
625 dest_scan += col_start;
626 for (
int col = col_start; col < col_end; col++) {
627 int src_alpha = GetSourceAlpha(cover_scan, clip_scan, col);
629 if (src_alpha == 255)
638void CFX_Renderer::CompositeSpanARGB(uint8_t* dest_scan,
642 const uint8_t* cover_scan,
645 const uint8_t* clip_scan) {
646 int col_start = GetColStart(span_left, clip_left);
647 int col_end = GetColEnd(span_left, span_len, clip_right);
648 dest_scan += col_start * Bpp;
649 if (m_bRgbByteOrder) {
650 for (
int col = col_start; col < col_end; col++) {
651 int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
652 : GetSourceAlpha(cover_scan, clip_scan, col);
654 if (src_alpha == 255) {
655 *(
reinterpret_cast<uint32_t*>(dest_scan)) = m_Color;
658 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
659 dest_scan[3] = dest_alpha;
660 int alpha_ratio = src_alpha * 255 / dest_alpha;
674 for (
int col = col_start; col < col_end; col++) {
675 int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
676 : GetSourceAlpha(cover_scan, clip_scan, col);
678 if (src_alpha == 255) {
679 *(
reinterpret_cast<uint32_t*>(dest_scan)) = m_Color;
681 if (dest_scan[3] == 0) {
682 dest_scan[3] = src_alpha;
683 *dest_scan++ = m_Blue;
684 *dest_scan++ = m_Green;
690 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
691 dest_scan[3] = dest_alpha;
692 int alpha_ratio = src_alpha * 255 / dest_alpha;
706void CFX_Renderer::CompositeSpanRGB(uint8_t* dest_scan,
710 const uint8_t* cover_scan,
713 const uint8_t* clip_scan) {
714 int col_start = GetColStart(span_left, clip_left);
715 int col_end = GetColEnd(span_left, span_len, clip_right);
716 dest_scan += col_start * Bpp;
717 if (m_bRgbByteOrder) {
718 for (
int col = col_start; col < col_end; col++) {
719 int src_alpha = GetSourceAlpha(cover_scan, clip_scan, col);
721 if (src_alpha == 255) {
723 *(uint32_t*)dest_scan = m_Color;
724 }
else if (Bpp == 3) {
725 *dest_scan++ = m_Red;
726 *dest_scan++ = m_Green;
727 *dest_scan++ = m_Blue;
736 dest_scan += Bpp - 2;
744 for (
int col = col_start; col < col_end; col++) {
745 int src_alpha = m_bFullCover ? GetSrcAlpha(clip_scan, col)
746 : GetSourceAlpha(cover_scan, clip_scan, col);
748 if (src_alpha == 255) {
750 *(uint32_t*)dest_scan = m_Color;
751 }
else if (Bpp == 3) {
752 *dest_scan++ = m_Blue;
753 *dest_scan++ = m_Green;
754 *dest_scan++ = m_Red;
763 dest_scan += Bpp - 2;
771CFX_Renderer::CFX_Renderer(
const RetainPtr<CFX_DIBitmap>& pDevice,
772 const RetainPtr<CFX_DIBitmap>& pBackdropDevice,
779 m_bFullCover(bFullCover),
780 m_bRgbByteOrder(bRgbByteOrder),
781 m_ClipBox(GetClipBoxFromRegion(pDevice, pClipRgn)),
782 m_pBackdropDevice(pBackdropDevice),
783 m_pClipMask(GetClipMaskFromRegion(pClipRgn)),
785 m_pClipRgn(pClipRgn),
786 m_CompositeSpanFunc(GetCompositeSpanFunc(m_pDevice)) {
787 if (m_pDevice->GetBPP() == 8) {
788 DCHECK(!m_bRgbByteOrder);
789 if (m_pDevice->IsMaskFormat())
796 std::tie(m_Alpha, m_Red, m_Green, m_Blue) = ArgbDecode(color);
799template <
class Scanline>
800void CFX_Renderer::render(
const Scanline& sl) {
806 m_pDevice->GetWritableBuffer().subspan(m_pDevice->GetPitch() * y).data();
807 const uint8_t* backdrop_scan =
nullptr;
808 if (m_pBackdropDevice) {
809 backdrop_scan = m_pBackdropDevice->GetBuffer()
810 .subspan(m_pBackdropDevice->GetPitch() * y)
813 int Bpp = m_pDevice->GetBPP() / 8;
814 bool bDestAlpha = m_pDevice->IsAlphaFormat() || m_pDevice->IsMaskFormat();
815 unsigned num_spans = sl.num_spans();
816 typename Scanline::const_iterator span = sl.begin();
822 uint8_t* dest_pos =
nullptr;
823 const uint8_t* backdrop_pos =
nullptr;
825 backdrop_pos = backdrop_scan ? backdrop_scan + x * Bpp :
nullptr;
826 dest_pos = dest_scan + x * Bpp;
828 dest_pos = dest_scan + x / 8;
829 backdrop_pos = backdrop_scan ? backdrop_scan + x / 8 :
nullptr;
831 const uint8_t* clip_pos =
nullptr;
834 clip_pos = m_pClipMask->GetBuffer().data() +
835 (y - m_ClipBox.top) * m_pClipMask->GetPitch() + x -
839 CompositeSpan(dest_pos, backdrop_pos, Bpp, bDestAlpha, x, span->len,
840 span->covers, m_ClipBox
.left, m_ClipBox
.right, clip_pos);
842 (
this->*m_CompositeSpanFunc)(dest_pos, Bpp, x, span->len, span->covers,
845 if (--num_spans == 0)
852void CFX_Renderer::CompositeSpan1bppHelper(uint8_t* dest_scan,
855 const uint8_t* cover_scan,
856 const uint8_t* clip_scan,
859 if (m_pDevice->HasPalette()) {
860 for (
int i = 0; i < 2; i++) {
861 if (m_pDevice->GetPaletteSpan()[i] == m_Color)
865 index = (
static_cast<uint8_t>(m_Color) == 0xff) ? 1 : 0;
867 uint8_t* dest_scan1 = dest_scan;
868 for (
int col = col_start; col < col_end; col++) {
869 int src_alpha = GetSourceAlpha(cover_scan, clip_scan, col);
872 *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8));
874 *dest_scan1 |= 1 << (7 - (col + span_left) % 8);
876 dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8;
880template <
class BaseRenderer>
881class RendererScanLineAaOffset {
883 typedef BaseRenderer base_ren_type;
884 typedef typename base_ren_type::color_type color_type;
885 RendererScanLineAaOffset(base_ren_type& ren,
unsigned left,
unsigned top)
886 : m_ren(&ren), m_left(left), m_top(top) {}
887 void color(
const color_type& c) { m_color = c; }
888 const color_type& color()
const {
return m_color; }
889 void prepare(
unsigned) {}
890 template <
class Scanline>
891 void render(
const Scanline& sl) {
893 unsigned num_spans = sl.num_spans();
894 typename Scanline::const_iterator span = sl.begin();
898 m_ren->blend_solid_hspan(x - m_left, y - m_top, (
unsigned)span->len,
899 m_color, span->covers);
901 m_ren->blend_hline(x - m_left, y - m_top, (
unsigned)(x - span->len - 1),
902 m_color, *(span->covers));
904 if (--num_spans == 0)
918agg::path_storage BuildAggPath(
const CFX_Path& path,
920 agg::path_storage agg_path;
921 pdfium::span<
const CFX_Path::
Point> points = path.GetPoints();
922 for (size_t i = 0; i < points.size(); ++i) {
923 CFX_PointF pos = points[i].m_Point;
930 agg_path.move_to(pos.x, pos.y);
933 (i + 1 == points.size() ||
935 points[i].m_Point == points[i - 1].m_Point) {
938 agg_path.line_to(pos.x, pos.y);
940 if (i > 0 && i + 2 < points.size()) {
941 CFX_PointF pos0 = points[i - 1].m_Point;
942 CFX_PointF pos2 = points[i + 1].m_Point;
943 CFX_PointF pos3 = points[i + 2].m_Point;
944 if (pObject2Device) {
949 pos0 = HardClip(pos0);
950 pos2 = HardClip(pos2);
951 pos3 = HardClip(pos3);
952 agg::curve4 curve(pos0.x, pos0.y, pos.x, pos.y, pos2.x, pos2.y, pos3.x,
955 agg_path.add_path(curve);
958 if (points[i].m_CloseFigure)
972 m_bRgbByteOrder(bRgbByteOrder),
973 m_bGroupKnockout(bGroupKnockout),
976 DCHECK_NE(m_pBitmap->GetFormat(), FXDIB_Format::k1bppMask);
977 DCHECK_NE(m_pBitmap->GetFormat(), FXDIB_Format::k1bppRgb);
985#if !BUILDFLAG(IS_APPLE)
986void CFX_AggDeviceDriver::InitPlatform() {}
988void CFX_AggDeviceDriver::DestroyPlatform() {}
990bool CFX_AggDeviceDriver::DrawDeviceText(
991 pdfium::span<
const TextCharPos> pCharPos,
993 const CFX_Matrix& mtObject2Device,
996 const CFX_TextRenderOptions& options) {
1008 return m_pBitmap->GetWidth();
1010 return m_pBitmap->GetHeight();
1012 return m_pBitmap->GetBPP();
1019 if (m_pBitmap->IsAlphaFormat()) {
1021 }
else if (m_pBitmap->IsMaskFormat()) {
1022 CHECK_NE(m_pBitmap->GetBPP(), 1);
1028 NOTREACHED_NORETURN();
1033 std::unique_ptr<CFX_ClipRgn> pClip;
1035 pClip = std::make_unique<CFX_ClipRgn>(*m_pClipRgn);
1036 m_StateStack.push_back(std::move(pClip));
1042 if (m_StateStack.empty())
1046 if (m_StateStack.back())
1047 m_pClipRgn = std::make_unique<CFX_ClipRgn>(*m_StateStack.back());
1049 m_pClipRgn = std::move(m_StateStack.back());
1050 m_StateStack.pop_back();
1054void CFX_AggDeviceDriver::SetClipMask(
agg::rasterizer_scanline_aa& rasterizer) {
1055 FX_RECT path_rect
(rasterizer.min_x()
, rasterizer.min_y()
,
1056 rasterizer.max_x() + 1
, rasterizer.max_y() + 1
);
1057 path_rect.Intersect(m_pClipRgn->GetBox());
1058 auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>();
1061 agg::rendering_buffer raw_buf(pThisLayer->GetWritableBuffer().data(),
1062 pThisLayer->GetWidth(), pThisLayer->GetHeight(),
1063 pThisLayer->GetPitch());
1064 agg::pixfmt_gray8 pixel_buf(raw_buf);
1065 agg::renderer_base<
agg::pixfmt_gray8> base_buf(pixel_buf);
1066 RendererScanLineAaOffset<
agg::renderer_base<
agg::pixfmt_gray8>> final_render(
1067 base_buf, path_rect.left, path_rect.top);
1068 final_render.color(
agg::gray8(255));
1069 agg::scanline_u8 scanline;
1070 agg::render_scanlines(rasterizer, scanline, final_render,
1072 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top,
1073 std::move(pThisLayer));
1080 DCHECK(fill_options.fill_type != CFX_FillRenderOptions::FillType::kNoFill);
1082 m_FillOptions = fill_options;
1084 m_pClipRgn = std::make_unique<CFX_ClipRgn>(
1087 absl::optional<CFX_FloatRect> maybe_rectf = path.GetRect(pObject2Device);
1088 if (maybe_rectf.has_value()) {
1094 m_pClipRgn->IntersectRect(rect);
1097 agg::path_storage path_data = BuildAggPath(path, pObject2Device);
1098 path_data.end_poly();
1099 agg::rasterizer_scanline_aa rasterizer;
1100 rasterizer.clip_box(0.0f, 0.0f,
1103 rasterizer.add_path(path_data);
1104 rasterizer.filling_rule(GetAlternateOrWindingFillType(fill_options));
1105 SetClipMask(rasterizer);
1114 m_pClipRgn = std::make_unique<CFX_ClipRgn>(
1117 agg::path_storage path_data = BuildAggPath(path,
nullptr);
1118 agg::rasterizer_scanline_aa rasterizer;
1119 rasterizer.clip_box(0.0f, 0.0f,
1122 RasterizeStroke(&rasterizer, &path_data, pObject2Device, pGraphState, 1.0f,
1124 rasterizer.filling_rule(
agg::fill_non_zero);
1125 SetClipMask(rasterizer);
1134 return m_pBitmap->MultiplyAlpha(alpha);
1139 return m_pBitmap->MultiplyAlphaMask(std::move(mask));
1142void CFX_AggDeviceDriver::
Clear(uint32_t color) {
1143 m_pBitmap->Clear(color);
1146void CFX_AggDeviceDriver::RenderRasterizer(
1147 agg::rasterizer_scanline_aa& rasterizer,
1150 bool bGroupKnockout) {
1151 RetainPtr<CFX_DIBitmap> pt = bGroupKnockout ? m_pBackdropBitmap :
nullptr;
1152 CFX_Renderer render(m_pBitmap, pt, m_pClipRgn.get(), color, bFullCover,
1154 agg::scanline_u8 scanline;
1155 agg::render_scanlines(rasterizer, scanline, render,
1162 uint32_t fill_color,
1163 uint32_t stroke_color,
1169 if (m_pBitmap->GetBuffer().empty())
1172 m_FillOptions = fill_options;
1175 agg::path_storage path_data = BuildAggPath(path, pObject2Device);
1176 agg::rasterizer_scanline_aa rasterizer;
1177 rasterizer.clip_box(0.0f, 0.0f,
1180 rasterizer.add_path(path_data);
1181 rasterizer.filling_rule(GetAlternateOrWindingFillType(fill_options));
1182 RenderRasterizer(rasterizer, fill_color, fill_options
.full_cover,
1185 int stroke_alpha =
FXARGB_A(stroke_color);
1186 if (!pGraphState || !stroke_alpha)
1190 agg::path_storage path_data = BuildAggPath(path, pObject2Device);
1191 agg::rasterizer_scanline_aa rasterizer;
1192 rasterizer.clip_box(0.0f, 0.0f,
1195 RasterizeStroke(&rasterizer, &path_data,
nullptr, pGraphState, 1,
1197 RenderRasterizer(rasterizer, stroke_color, fill_options
.full_cover,
1203 if (pObject2Device) {
1204 matrix1
.a =
std::max(fabs(pObject2Device
->a), fabs(pObject2Device
->b));
1205 matrix1
.d = matrix1
.a;
1207 pObject2Device
->a / matrix1
.a, pObject2Device
->b / matrix1
.a,
1208 pObject2Device
->c / matrix1
.d, pObject2Device
->d / matrix1
.d, 0
, 0
);
1213 agg::path_storage path_data = BuildAggPath(path, &matrix1);
1214 agg::rasterizer_scanline_aa rasterizer;
1215 rasterizer.clip_box(0.0f, 0.0f,
1218 RasterizeStroke(&rasterizer, &path_data, &matrix2, pGraphState, matrix1
.a,
1220 RenderRasterizer(rasterizer, stroke_color, fill_options
.full_cover,
1226 uint32_t fill_color,
1231 if (m_pBitmap->GetBuffer().empty())
1236 FX_RECT draw_rect = clip_rect;
1241 if (!m_pClipRgn || m_pClipRgn->GetType() == CFX_ClipRgn::kRectI) {
1242 if (m_bRgbByteOrder) {
1243 RgbByteOrderCompositeRect(m_pBitmap, draw_rect.left, draw_rect.top,
1244 draw_rect.Width(), draw_rect.Height(),
1247 m_pBitmap->CompositeRect(draw_rect.left, draw_rect.top, draw_rect.Width(),
1248 draw_rect.Height(), fill_color);
1252 m_pBitmap->CompositeMask(draw_rect.left, draw_rect.top, draw_rect.Width(),
1253 draw_rect.Height(), m_pClipRgn->GetMask(),
1254 fill_color, draw_rect.left - clip_rect.left,
1255 draw_rect.top - clip_rect.top, BlendMode::kNormal,
1256 nullptr, m_bRgbByteOrder);
1267 *pRect = m_pClipRgn->GetBox();
1274 if (m_pBitmap->GetBuffer().empty())
1277 FX_RECT rect(left, top, left + pBitmap->GetWidth(),
1278 top + pBitmap->GetHeight());
1280 if (m_pBackdropBitmap) {
1281 pBack = m_pBackdropBitmap->ClipTo(rect);
1285 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(),
1286 m_pBitmap, 0, 0, BlendMode::kNormal,
nullptr,
false);
1288 pBack = m_pBitmap->ClipTo(rect);
1293 left =
std::min(left, 0);
1294 top =
std::min(top, 0);
1295 if (m_bRgbByteOrder) {
1297 std::move(pBack), left, top);
1300 return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(),
1301 std::move(pBack), left, top);
1305 return m_pBackdropBitmap;
1314 if (m_pBitmap->GetBuffer().empty())
1317 if (pBitmap->IsMaskFormat()) {
1318 return m_pBitmap->CompositeMask(left, top, src_rect.Width(),
1319 src_rect.Height(), std::move(pBitmap), argb,
1320 src_rect.left, src_rect.top, blend_type,
1321 m_pClipRgn.get(), m_bRgbByteOrder);
1323 return m_pBitmap->CompositeBitmap(left, top, src_rect.Width(),
1324 src_rect.Height(), std::move(pBitmap),
1325 src_rect.left, src_rect.top, blend_type,
1326 m_pClipRgn.get(), m_bRgbByteOrder);
1338 if (m_pBitmap->GetBuffer().empty())
1341 if (dest_width == bitmap->GetWidth() && dest_height == bitmap->GetHeight()) {
1346 FX_RECT dest_rect
(dest_left
, dest_top
, dest_left + dest_width
,
1347 dest_top + dest_height
);
1349 FX_RECT dest_clip = dest_rect;
1351 CFX_BitmapComposer composer;
1352 composer.Compose(m_pBitmap, m_pClipRgn.get(), 1.0f, argb, dest_clip,
1353 false,
false,
false,
1354 m_bRgbByteOrder, blend_type);
1357 dest_height, dest_clip, options);
1369 std::unique_ptr<CFX_ImageRenderer>* handle,
1371 if (m_pBitmap->GetBuffer().empty())
1374 *handle = std::make_unique<CFX_ImageRenderer>(
1375 m_pBitmap, m_pClipRgn.get(), std::move(bitmap), alpha, argb, matrix,
1376 options, m_bRgbByteOrder);
1382 return m_pBitmap->GetBuffer().empty() || pHandle->Continue(pPause);
1387bool CFX_DefaultRenderDevice::AttachAggImpl(
1390 RetainPtr<CFX_DIBitmap> pBackdropBitmap,
1391 bool bGroupKnockout) {
1395 SetDeviceDriver(std::make_unique<pdfium::CFX_AggDeviceDriver>(
1396 std::move(pBitmap), bRgbByteOrder, std::move(pBackdropBitmap),
1401bool CFX_DefaultRenderDevice::CreateAgg(
1405 RetainPtr<CFX_DIBitmap> pBackdropBitmap) {
1406 auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
1407 if (!pBitmap->Create(width, height, format))
1411 SetDeviceDriver(std::make_unique<pdfium::CFX_AggDeviceDriver>(
1412 std::move(pBitmap),
false, std::move(pBackdropBitmap),
false));
const FX_RECT & GetBox() const
constexpr CFX_FloatRect(float l, float b, float r, float t)
void Intersect(const CFX_FloatRect &other_rect)
FX_RECT GetOuterRect() const
bool Continue(PauseIndicatorIface *pPause)
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
CFX_Matrix operator*(const CFX_Matrix &right) const
CFX_PointF Transform(const CFX_PointF &point) const
CFX_Matrix GetInverse() const
void SetBitmap(RetainPtr< CFX_DIBitmap > bitmap)
bool FillRectWithBlend(const FX_RECT &rect, uint32_t fill_color, BlendMode blend_type) override
~CFX_AggDeviceDriver() override
CFX_AggDeviceDriver(RetainPtr< CFX_DIBitmap > pBitmap, bool bRgbByteOrder, RetainPtr< CFX_DIBitmap > pBackdropBitmap, bool bGroupKnockout)
bool ContinueDIBits(CFX_ImageRenderer *handle, PauseIndicatorIface *pPause) override
void RestoreState(bool bKeepSaved) override
bool StartDIBits(RetainPtr< const CFX_DIBBase > bitmap, float alpha, uint32_t argb, const CFX_Matrix &matrix, const FXDIB_ResampleOptions &options, std::unique_ptr< CFX_ImageRenderer > *handle, BlendMode blend_type) override
bool GetClipBox(FX_RECT *pRect) override
int GetDeviceCaps(int caps_id) const override
bool GetDIBits(const RetainPtr< CFX_DIBitmap > &pBitmap, int left, int top) override
void SaveState() override
RetainPtr< CFX_DIBitmap > GetBackDrop() override
bool SetClip_PathStroke(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState) override
int GetDriverType() const override
bool MultiplyAlpha(float alpha) override
DeviceType GetDeviceType() const override
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options, BlendMode blend_type) override
bool MultiplyAlphaMask(const RetainPtr< const CFX_DIBBase > &mask) override
bool SetDIBits(const RetainPtr< const CFX_DIBBase > &pBitmap, uint32_t argb, const FX_RECT &src_rect, int left, int top, BlendMode blend_type) override
bool StretchDIBits(RetainPtr< const CFX_DIBBase > bitmap, uint32_t argb, int dest_left, int dest_top, int dest_width, int dest_height, const FX_RECT *pClipRect, const FXDIB_ResampleOptions &options, BlendMode blend_type) override
void Clear(uint32_t color)
bool SetClip_PathFill(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_FillRenderOptions &fill_options) override
#define FXRGB2GRAY(r, g, b)
#define FXARGB_SETRGBORDERDIB(p, argb)
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
#define FXARGB_TOBGRORDERDIB(argb)
#define FXARGB_SETDIB(p, argb)
#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha)
#define FXRC_ALPHA_OUTPUT
#define FXDC_PIXEL_HEIGHT
#define FXRC_BYTEMASK_OUTPUT
void Offset(int dx, int dy)
void Intersect(const FX_RECT &src)
constexpr FX_RECT(int l, int t, int r, int b)
#define UNOWNED_PTR_EXCLUSION