office-gobmx/drawinglayer
Armin Le Grand (allotropia) a57c9e1aca CairoSDPR: Support direct RGBA for convertToBitmapEx
Added general interfaces to be able to render directly
to an RGBA target SDPR:

- processor2d::createPixelProcessor2DFromScratch creates
  a target-SDPR with given pixel size and RGB or RGBA,
  owning and using a cairo surface internally
- processor2d::extractBitmapExFromBaseProcessor2D extracts
  rendered content to BitmapEx, including alpha

All this is currently only implemented for Ciaro, thus
the internal impls are encapsulated by USE_HEADLESS_CODE,
but already created gererally available. The return values
have to be checked to see if an evtl. shortcut is possible.

For convertToBitmapEx this means that it can do conversions
much faster than up to now for cairo when CairoSDPR is
available, else it has to to the older slower way that
also works and is the default: Create RGB content, create
Mask, RemoveBlendedStartColor (see convertToBitmapEx
implementation). This works and has the same quality,
but needs two renderings and one bitmap operation, thus
is clearly slower.

Note that these interfaces can and will be supported for
other SDPR implementations in the future, thus will make
this converter automatically faster on systems where we
will have a SDPR in the future, too.

Also note that this is the gereral converter from
a sequence of Primitives to Bitmap data, already used in
many places, inculding UNO API, thus is expected to have
some impact on conversion efficiency - if Cairo is used,
so e.g. also headless.

Change-Id: Ia638a549a04b19622892d91651317ec6727b6cd0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174266
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Tested-by: Jenkins
2024-10-01 11:14:14 +02:00
..
inc cid#1554812 COPY_INSTEAD_OF_MOVE 2024-07-29 14:50:38 +02:00
qa/unit Fix typo 2024-09-23 17:09:05 +02:00
source CairoSDPR: Support direct RGBA for convertToBitmapEx 2024-10-01 11:14:14 +02:00
CppunitTest_drawinglayer_border.mk Use less libxml2 external headers dependency 2023-09-29 00:20:57 +02:00
CppunitTest_drawinglayer_processors.mk Prepare to run (select) tests during Emscripten build 2024-05-02 07:52:03 +02:00
drawinglayer.component drawinglayer: create instances with uno constructors 2020-07-07 11:56:41 +02:00
IwyuFilter_drawinglayer.yaml tdf#42949 Fix new IWYU warnings in directories d* 2020-11-09 16:04:18 +01:00
Library_drawinglayer.mk tdf#161826 - Add uniform Glow effect for texts in shapes 2024-08-29 19:59:24 +02:00
Library_drawinglayercore.mk Use less libxml2 external headers dependency 2023-09-29 00:20:57 +02:00
Makefile re-base on ALv2 code. Includes (at least) relevant parts of: 2012-11-06 11:58:16 +00:00
Module_drawinglayer.mk Separate core drawinglayer func. into drawinglayercore library 2021-12-22 12:10:10 +01:00
README.md Update README.md files 2022-04-16 20:43:11 +02:00

Drawing API

Drawing API that can specify what to draw via a kind of display list.

Example of the DrawingLayer use is eg. in svx/source/xoutdev/xtabhtch.cxx:121. A stripped down version with extended comments:

 // Create a hatch primitive (here a rectangle that will be filled with
 // the appropriate hatching, but has no border).
 // This will not draw it yet; it's so far only constructed to add it to a
 // display list later.
 const drawinglayer::primitive2d::Primitive2DReference aHatchPrimitive(
     new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(...));

 // Create a rectangle around the hatch, to give it a border.
 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
     new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(...));

 // Here we want to render to a virtual device (to later obtain the bitmap
 // out of that), so prepare it.
 VirtualDevice aVirtualDevice;

 // Create processor and draw primitives, to get it ready for rendering.
 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(
     drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(...));

 // Fill-in the display list.
 drawinglayer::primitive2d::Primitive2DSequence aSequence(2);

 aSequence[0] = aHatchPrimitive;
 aSequence[1] = aBlackRectanglePrimitive;

 // Render it to the virtual device.
 pProcessor2D->process(aSequence);
 pProcessor2D.reset();

 // Obtain the bitmap that was rendered from the virtual device, to re-use
 // it in the widget.
 aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel());

DrawingLayer Glossary

Primitives - classes that represent what should be drawn. It holds the data what to draw, but does not contain any kind of the rendering. Some of the primitives are 'Basic primitives', that are primitives that cannot be decomposed. The rest of the primitives can be decomposed to the basic primitives.

Decomposition - a way how to break down the more complicated primitives into the basic primitives, and represent them via them; this logically makes the plain Primitive2DSequence display list a hierarchy. Eg. PolygonMarkerPrimitive2D can be decomposed to 2 hairlines PolyPolygonHairlinePrimitive2D's, each with different color.

Processor - a class that goes through the hierarchy of the Primitives, and renders it some way. Various processors, like VclPixelProcessor2D (renders to the screen), VclMetafileProcessor2D (renders to the VCL metafile, eg. for printing), etc.

How to Implement a New Primitive ("Something New to Draw")

  • Create an ancestor of BasePrimitive2D (or of its ancestor if it fits the purpose better)

    • Assign it an ID [in drawinglayer_primitivetypes2d.hxx]

    • Implement its decomposition [virtual Primitive2DSequence create2DDecomposition(...)]

  • Extend the (various) processor(s) If you need more than relying on just the decomposition

Where is DrawingLayer Used

  • SdrObject(s) (rectangles, Circles, predefined shapes etc.)

  • Selections

  • Various smaller cases to 'just draw something'

    • Draw to a virtual device, and use the resulting bitmap (like the example above)
  • Custom widgets (like the Header / Footer indicator button)

Dumping DrawingLayer Primitives as XML

For debugging purposes, it is possible to dump the drawinglayer primitives as an xml file. The drawinglayer xml dump can show possible problems with the rendering.

For example, in emfio/qa/cppunit/emf/EmfImportTest.cxx, one can write:

Primitive2DSequence aSequence = parseEmf(u"emfio/qa/cppunit/wmf/data/stockobject.emf");
drawinglayer::Primitive2dXmlDump dumper;
Primitive2DContainer aContainer(aSequence);
dumper.dump(aContainer, "/tmp/drawyinglayer.xml");

Then, after invoking make CppunitTest_emfio_emf, /tmp/drawyinglayer.xml will be the dump of the drawinglayer primitives used to draw the emf file in LibreOffice. The top level tag will be .