Files
odfstudio/include/vcl/virdev.hxx
T
Noel Grandin 088a7c7c45 remove alpha device from OutputDevice
and render to a combined color+alpha bitmap

The strategy is to remove the mpAlphaVDev from OutputDevice,
and have the OutputDevice create 32-bit SalBitmap's
and then have the various backends correctly render to
those 32-bit bitmaps.

However, whenever we extract a BitmapEx from OutputDevice
(e.g. via VirtualDevice) and hand it to the rest of the
system, we split the color and alpha information.
So the rest of the codebase doesn't have to deal with
this yet.

We have some major problems to overcome here:
(*) Cairo uses 32-bit data, even if we ask for 24-bit color with no alpha.
    This is because the current version of cairo does not support RGB 24-bit data.
(*) Sometimes we want the bitmap to be initialised with an opaque white background,
    sometimes we want it to be transparent.
(*) Sometimes when we extract a bitmap from a device, we want the alpha channel,
    sometimes not.
(*) There are lots of left-over bits of previous attempts of this change lying around,
    e.g. in skia.

Notes
(*) we allow Bitmap (ie. SalBitmap) to hold color+alpha
(*) The BitmapEx(Bitmap) constructor checks if the incoming
Bitmap is color+alpha, and if so, splits into a color bitmap and an alpha bitmap
(*) Because the underlying image data is stored pre-multipled, if
we write a transparent pixel with color, and then read the pixel value back,
we might lose the color information.

Change-Id: I0fc0042d6e5be5edd99b320892fb00a8eb2842fe
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173937
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2025-07-21 10:49:25 +02:00

164 lines
6.0 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_VCL_VIRDEV_HXX
#define INCLUDED_VCL_VIRDEV_HXX
#include <vcl/dllapi.h>
#include <vcl/outdev.hxx>
#include <vcl/salgtype.hxx>
#include <memory>
class SalVirtualDevice;
struct SystemGraphicsData;
typedef struct _cairo_surface cairo_surface_t;
class SAL_WARN_UNUSED VCL_DLLPUBLIC VirtualDevice : public OutputDevice
{
friend class Application;
friend class ::OutputDevice;
friend class Printer;
friend cairo_surface_t* get_underlying_cairo_surface(const VirtualDevice&);
public:
// reference device modes for different compatibility levels
enum class RefDevMode { NONE = 0,
Dpi600 = 1, // 600 dpi
MSO1 = 3,
PDF1 = 4,
Custom = 5
};
private:
std::unique_ptr<SalVirtualDevice> mpVirDev;
VclPtr<VirtualDevice> mpPrev;
VclPtr<VirtualDevice> mpNext;
sal_uInt16 mnBitCount;
bool mbScreenComp;
const DeviceFormat meFormatAndAlpha;
RefDevMode meRefDevMode;
bool mbForceZeroExtleadBug;
SAL_DLLPRIVATE void ImplInitVirDev( const OutputDevice* pOutDev, tools::Long nDX, tools::Long nDY, const SystemGraphicsData *pData = nullptr );
SAL_DLLPRIVATE bool InnerImplSetOutputSizePixel( const Size& rNewSize, bool bErase, bool bAlphaMaskTransparent );
VirtualDevice (const VirtualDevice &) = delete;
VirtualDevice & operator= (const VirtualDevice &) = delete;
/** Used for alpha VDev, to set areas to opaque
@since \#i32109#
*/
SAL_DLLPRIVATE void ImplFillOpaqueRectangle( const tools::Rectangle& rRect );
protected:
virtual bool AcquireGraphics() const override;
virtual void ReleaseGraphics( bool bRelease = true ) override;
/** Create a virtual device of size 1x1
@param pCompDev
The generated vdev will be compatible to this device.
If it's the nullptr, it uses Application::GetDefaultDevice().
@param eFormat
Device format of the generated virtual device.
@param eOutDevType
This real virtual output device type.
*/
explicit VirtualDevice(const OutputDevice* pCompDev, DeviceFormat eFormat,
OutDevType eOutDevType);
public:
/** Create a virtual device of size 1x1
@param eFormat
Device format of the generated virtual device.
*/
explicit VirtualDevice(DeviceFormat eFormat = DeviceFormat::WITHOUT_ALPHA)
: VirtualDevice(nullptr, eFormat, OUTDEV_VIRDEV) {}
/** Create a virtual device of size 1x1
@param rCompDev
The generated vdev will be compatible to this device.
@param eFormat
Device format of the generated virtual device.
*/
explicit VirtualDevice(const OutputDevice& rCompDev,
DeviceFormat eFormat = DeviceFormat::WITHOUT_ALPHA)
: VirtualDevice(&rCompDev, eFormat, OUTDEV_VIRDEV) {}
/** Create a virtual device using an existing system dependent device or graphics context
Any rendering will happen directly on the context and not on any intermediate bitmap.
Note: This might not be supported on all platforms !
*/
explicit VirtualDevice(const SystemGraphicsData& rData, const Size &rSize,
DeviceFormat eFormat);
virtual ~VirtualDevice() override;
virtual void dispose() override;
bool CanEnableNativeWidget() const override;
bool CanAnimate() const override { return false; }
virtual void EnableRTL( bool bEnable = true ) override;
bool SetOutputSizePixel( const Size& rNewSize, bool bErase = true, bool bAlphaMaskTransparent = false );
bool SetOutputSizePixelScaleOffsetAndLOKBuffer( const Size& rNewSize,
const Fraction& rScale,
const Point& rNewOffset,
sal_uInt8* pBuffer);
bool SetOutputSize( const Size& rNewSize )
{ return SetOutputSizePixel( LogicToPixel( rNewSize ) ); }
void SetReferenceDevice( RefDevMode );
void Compat_ZeroExtleadBug(); // enable workaround for #i60495#
void SetReferenceDevice( sal_Int32 i_nDPIX, sal_Int32 i_nDPIY );
virtual sal_uInt16 GetBitCount() const override;
bool IsVirtual() const override;
bool IsScreenComp() const override { return mbScreenComp; }
bool IsWithoutAlpha() const { return meFormatAndAlpha == DeviceFormat::WITHOUT_ALPHA; }
virtual bool HasAlpha() const override { return meFormatAndAlpha != DeviceFormat::WITHOUT_ALPHA; }
private:
SAL_DLLPRIVATE void ImplSetReferenceDevice( RefDevMode, sal_Int32 i_nDPIX, sal_Int32 i_nDPIY );
protected:
virtual bool UsePolyPolygonForComplexGradient() override;
virtual tools::Long GetFontExtLeading() const override;
};
#endif // INCLUDED_VCL_VIRDEV_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */