5#ifndef CORE_FXCRT_MAYBE_OWNED_H_
6#define CORE_FXCRT_MAYBE_OWNED_H_
11#include "core/fxcrt/unowned_ptr.h"
12#include "third_party/abseil-cpp/absl/types/variant.h"
20template <
typename T,
typename D =
std::default_delete<T>>
23 using OwnedType =
std::unique_ptr<T, D>;
39 void Reset(T* ptr =
nullptr) { ptr_ = UnownedType(ptr); }
40 void Reset(OwnedType ptr) { ptr_ = std::move(ptr); }
42 bool IsOwned()
const {
return absl::holds_alternative<OwnedType>(ptr_); }
51 return absl::visit([](
const auto& obj) {
return obj.get(); }, ptr_);
54 auto local_variable_preventing_move_elision = std::move(ptr_);
55 return absl::visit([](
const auto& obj) {
return obj.get(); },
56 local_variable_preventing_move_elision);
61 auto result = std::move(absl::get<OwnedType>(ptr_));
62 ptr_ = UnownedType(result.get());
68 auto result = std::move(absl::get<OwnedType>(ptr_));
82 Reset(
std::move(ptr));
87 bool operator==(
const OwnedType& ptr)
const {
return Get() == ptr.get(); }
88 bool operator==(T* ptr)
const {
return Get() == ptr; }
91 bool operator!=(
const OwnedType ptr)
const {
return !(*
this == ptr); }
92 bool operator!=(T* ptr)
const {
return !(*
this == ptr); }
94 explicit operator bool()
const {
return !!Get(); }
99 absl::variant<UnownedType, OwnedType> ptr_;
104using fxcrt::MaybeOwned;
bool TransferBitmap(int dest_left, int dest_top, int width, int height, RetainPtr< const CFX_DIBBase > source, int src_left, int src_top)
bool SetAlphaFromBitmap(RetainPtr< const CFX_DIBBase > source)
bool SetUniformOpaqueAlpha()
bool Create(int width, int height, FXDIB_Format format)
pdfium::span< const uint8_t > GetBuffer() const
static absl::optional< PitchAndSize > CalculatePitchAndSize(int width, int height, FXDIB_Format format, uint32_t pitch)
bool CompositeMask(int dest_left, int dest_top, int width, int height, const RetainPtr< const CFX_DIBBase > &pMask, uint32_t color, int src_left, int src_top, BlendMode blend_type, const CFX_ClipRgn *pClipRgn, bool bRgbByteOrder)
bool SetRedFromBitmap(RetainPtr< const CFX_DIBBase > source)
bool MultiplyAlphaMask(RetainPtr< const CFX_DIBBase > source)
pdfium::span< uint8_t > GetWritableScanline(int line)
bool CompositeBitmap(int dest_left, int dest_top, int width, int height, RetainPtr< const CFX_DIBBase > source, int src_left, int src_top, BlendMode blend_type, const CFX_ClipRgn *pClipRgn, bool bRgbByteOrder)
bool ConvertColorScale(uint32_t forecolor, uint32_t backcolor)
bool ConvertFormat(FXDIB_Format format)
bool CompositeRect(int dest_left, int dest_top, int width, int height, uint32_t color)
pdfium::span< const uint8_t > GetScanline(int line) const override
size_t GetEstimatedImageMemoryBurden() const override
bool MultiplyAlpha(float alpha)
pdfium::span< uint8_t > GetWritableBuffer()
bool Create(int width, int height, FXDIB_Format format, uint8_t *pBuffer, uint32_t pitch)
void TakeOver(RetainPtr< CFX_DIBitmap > &&pSrcBitmap)
void Clear(uint32_t color)
bool Copy(RetainPtr< const CFX_DIBBase > source)
void CompositeOneBPPMask(int dest_left, int dest_top, int width, int height, RetainPtr< const CFX_DIBBase > source, int src_left, int src_top)
FX_RECT ToRoundedFxRect() const
CFX_FloatRect(const FX_RECT &rect)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
const CFX_Matrix & matrix() const
static float TextUnitToGlyphUnit(float fTextUnit)
void Transform(CPDF_Font::FormIface *pForm, const CFX_Matrix &matrix)
void InitializeFromStreamData(bool bColored, pdfium::span< const float > pData)
RetainPtr< CFX_DIBitmap > GetBitmap()
static void TextUnitRectToGlyphUnitRect(CFX_FloatRect *pRect)
const FX_RECT & bbox() const
const CPDF_Font::FormIface * form() const
bool LoadBitmapFromSoleImageOfForm()
void SetForm(std::unique_ptr< CPDF_Font::FormIface > pForm)
MaybeOwned(OwnedType ptr)
MaybeOwned & operator=(const MaybeOwned &that)=delete
void Reset(T *ptr=nullptr)
MaybeOwned & operator=(const UnownedType &ptr)
bool operator==(const OwnedType &ptr) const
MaybeOwned & operator=(MaybeOwned &&that) noexcept=default
MaybeOwned(const MaybeOwned &that)=delete
bool operator==(const MaybeOwned &that) const
bool operator!=(const MaybeOwned &that) const
bool operator!=(T *ptr) const
MaybeOwned & operator=(T *ptr)
bool operator!=(const OwnedType ptr) const
OwnedType ReleaseAndClear()
MaybeOwned & operator=(OwnedType ptr)
MaybeOwned(MaybeOwned &&that) noexcept=default
MaybeOwned(const UnownedType &ptr)
void Reset(OwnedType ptr)
bool operator==(T *ptr) const
#define CONSTRUCT_VIA_MAKE_RETAIN
FX_RECT & operator=(const FX_RECT &that)=default