#include "core/fxge/agg/cfx_agg_devicedriver.h"
#include <math.h>
#include <stdint.h>
#include <algorithm>
#include <utility>
#include "build/build_config.h"
#include "core/fxcrt/check.h"
#include "core/fxcrt/check_op.h"
#include "core/fxcrt/compiler_specific.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/notreached.h"
#include "core/fxcrt/span.h"
#include "core/fxcrt/stl_util.h"
#include "core/fxcrt/unowned_ptr_exclusion.h"
#include "core/fxcrt/zip.h"
#include "core/fxge/agg/cfx_agg_cliprgn.h"
#include "core/fxge/agg/cfx_agg_imagerenderer.h"
#include "core/fxge/cfx_defaultrenderdevice.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_path.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/dib/cfx_imagestretcher.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#if defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
#include "third_party/agg23/agg_clip_liang_barsky.h"
#include "third_party/agg23/agg_conv_dash.h"
#include "third_party/agg23/agg_conv_stroke.h"
#include "third_party/agg23/agg_curves.h"
#include "third_party/agg23/agg_path_storage.h"
#include "third_party/agg23/agg_pixfmt_gray.h"
#include "third_party/agg23/agg_rasterizer_scanline_aa.h"
#include "third_party/agg23/agg_renderer_scanline.h"
#include "third_party/agg23/agg_scanline_u.h"
#if defined(__clang__)
#pragma GCC diagnostic pop
#endif
namespace pdfium {
namespace {
const float kMaxPos = …;
CFX_PointF HardClip(const CFX_PointF& pos) { … }
template <typename T>
void DoAlphaMerge(T& pixel, int src_r, int src_g, int src_b, int src_alpha) { … }
void RgbByteOrderCompositeRect(const RetainPtr<CFX_DIBitmap>& bitmap,
int left,
int top,
int width,
int height,
FX_ARGB src_argb) { … }
void RgbByteOrderTransferBitmap(RetainPtr<CFX_DIBitmap> pBitmap,
int width,
int height,
RetainPtr<const CFX_DIBBase> pSrcBitmap,
int src_left,
int src_top) { … }
void RasterizeStroke(agg::rasterizer_scanline_aa* rasterizer,
agg::path_storage* path_data,
const CFX_Matrix* pObject2Device,
const CFX_GraphStateData* pGraphState,
float scale,
bool bTextMode) { … }
agg::filling_rule_e GetAlternateOrWindingFillType(
const CFX_FillRenderOptions& fill_options) { … }
RetainPtr<CFX_DIBitmap> GetClipMaskFromRegion(const CFX_AggClipRgn* r) { … }
FX_RECT GetClipBoxFromRegion(const RetainPtr<CFX_DIBitmap>& device,
const CFX_AggClipRgn* region) { … }
class CFX_AggRenderer { … };
void CFX_AggRenderer::CompositeSpan(uint8_t* dest_scan,
const uint8_t* backdrop_scan,
int bytes_per_pixel,
bool bDestAlpha,
int col_start,
int col_end,
const uint8_t* cover_scan,
const uint8_t* clip_scan) { … }
void CFX_AggRenderer::CompositeSpanGray(uint8_t* dest_scan,
int bytes_per_pixel,
int col_start,
int col_end,
const uint8_t* cover_scan,
const uint8_t* clip_scan) { … }
void CFX_AggRenderer::CompositeSpanARGB(uint8_t* dest_scan,
int bytes_per_pixel,
int col_start,
int col_end,
const uint8_t* cover_scan,
const uint8_t* clip_scan) { … }
void CFX_AggRenderer::CompositeSpanRGB(uint8_t* dest_scan,
int bytes_per_pixel,
int col_start,
int col_end,
const uint8_t* cover_scan,
const uint8_t* clip_scan) { … }
CFX_AggRenderer::CFX_AggRenderer(const RetainPtr<CFX_DIBitmap>& pDevice,
const RetainPtr<CFX_DIBitmap>& pBackdropDevice,
const CFX_AggClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
bool bRgbByteOrder)
: … { … }
template <class Scanline>
void CFX_AggRenderer::render(const Scanline& sl) { … }
template <class BaseRenderer>
class RendererScanLineAaOffset { … };
agg::path_storage BuildAggPath(const CFX_Path& path,
const CFX_Matrix* pObject2Device) { … }
}
CFX_AggDeviceDriver::CFX_AggDeviceDriver(
RetainPtr<CFX_DIBitmap> pBitmap,
bool bRgbByteOrder,
RetainPtr<CFX_DIBitmap> pBackdropBitmap,
bool bGroupKnockout)
: … { … }
CFX_AggDeviceDriver::~CFX_AggDeviceDriver() { … }
#if !BUILDFLAG(IS_APPLE)
void CFX_AggDeviceDriver::InitPlatform() { … }
void CFX_AggDeviceDriver::DestroyPlatform() { … }
bool CFX_AggDeviceDriver::DrawDeviceText(
pdfium::span<const TextCharPos> pCharPos,
CFX_Font* pFont,
const CFX_Matrix& mtObject2Device,
float font_size,
uint32_t color,
const CFX_TextRenderOptions& options) { … }
#endif
DeviceType CFX_AggDeviceDriver::GetDeviceType() const { … }
int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) const { … }
void CFX_AggDeviceDriver::SaveState() { … }
void CFX_AggDeviceDriver::RestoreState(bool bKeepSaved) { … }
void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { … }
bool CFX_AggDeviceDriver::SetClip_PathFill(
const CFX_Path& path,
const CFX_Matrix* pObject2Device,
const CFX_FillRenderOptions& fill_options) { … }
bool CFX_AggDeviceDriver::SetClip_PathStroke(
const CFX_Path& path,
const CFX_Matrix* pObject2Device,
const CFX_GraphStateData* pGraphState) { … }
int CFX_AggDeviceDriver::GetDriverType() const { … }
bool CFX_AggDeviceDriver::MultiplyAlpha(float alpha) { … }
bool CFX_AggDeviceDriver::MultiplyAlphaMask(
RetainPtr<const CFX_DIBitmap> mask) { … }
void CFX_AggDeviceDriver::Clear(uint32_t color) { … }
void CFX_AggDeviceDriver::RenderRasterizer(
agg::rasterizer_scanline_aa& rasterizer,
uint32_t color,
bool bFullCover,
bool bGroupKnockout) { … }
bool CFX_AggDeviceDriver::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) { … }
bool CFX_AggDeviceDriver::FillRect(const FX_RECT& rect, uint32_t fill_color) { … }
FX_RECT CFX_AggDeviceDriver::GetClipBox() const { … }
bool CFX_AggDeviceDriver::GetDIBits(RetainPtr<CFX_DIBitmap> bitmap,
int left,
int top) const { … }
RetainPtr<const CFX_DIBitmap> CFX_AggDeviceDriver::GetBackDrop() const { … }
bool CFX_AggDeviceDriver::SetDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t argb,
const FX_RECT& src_rect,
int left,
int top,
BlendMode blend_type) { … }
bool CFX_AggDeviceDriver::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) { … }
RenderDeviceDriverIface::StartResult CFX_AggDeviceDriver::StartDIBits(
RetainPtr<const CFX_DIBBase> bitmap,
float alpha,
uint32_t argb,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
BlendMode blend_type) { … }
bool CFX_AggDeviceDriver::ContinueDIBits(CFX_AggImageRenderer* pHandle,
PauseIndicatorIface* pPause) { … }
}
bool CFX_DefaultRenderDevice::AttachAggImpl(
RetainPtr<CFX_DIBitmap> pBitmap,
bool bRgbByteOrder,
RetainPtr<CFX_DIBitmap> pBackdropBitmap,
bool bGroupKnockout) { … }
bool CFX_DefaultRenderDevice::CreateAgg(
int width,
int height,
FXDIB_Format format,
RetainPtr<CFX_DIBitmap> pBackdropBitmap) { … }