diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /canvas/inc/rendering | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'canvas/inc/rendering')
-rw-r--r-- | canvas/inc/rendering/icolorbuffer.hxx | 74 | ||||
-rw-r--r-- | canvas/inc/rendering/irendermodule.hxx | 134 | ||||
-rw-r--r-- | canvas/inc/rendering/isurface.hxx | 69 | ||||
-rw-r--r-- | canvas/inc/rendering/isurfaceproxy.hxx | 98 | ||||
-rw-r--r-- | canvas/inc/rendering/isurfaceproxymanager.hxx | 66 |
5 files changed, 441 insertions, 0 deletions
diff --git a/canvas/inc/rendering/icolorbuffer.hxx b/canvas/inc/rendering/icolorbuffer.hxx new file mode 100644 index 000000000..6e0c250c5 --- /dev/null +++ b/canvas/inc/rendering/icolorbuffer.hxx @@ -0,0 +1,74 @@ +/* -*- 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 . + */ + +#pragma once + +#include <sal/types.h> + +namespace canvas +{ + /** Interface for a raw memory pixel container + + Use this interface to represent a surface of raw pixel (e.g. a + bitmap) to the canvas rendering framework. + */ + struct IColorBuffer + { + /// The underlying pixel format for this buffer + enum class Format + { + // 32-bit ARGB pixel format with alpha, 8 bits per channel. + A8R8G8B8, + + // 32-bit RGB pixel format, 8 bits per channel. + X8R8G8B8 + }; + + virtual ~IColorBuffer() {} + + /** Get a pointer to the raw memory bits of the pixel + */ + virtual sal_uInt8* lock() const = 0; + + /** unlock previous locked buffer + */ + virtual void unlock() const = 0; + + /** Get width in pixel + */ + virtual sal_uInt32 getWidth() const = 0; + + /** Get height in pixel + */ + virtual sal_uInt32 getHeight() const = 0; + + /** Offset, in bytes, between consecutive scan lines of the bitmap. + If the stride is positive, the bitmap is top-down. + If the stride is negative, the bitmap is bottom-up. + The returned value is only valid while the buffer is locked. + */ + virtual sal_uInt32 getStride() const = 0; + + /** Get format of the color buffer + */ + virtual Format getFormat() const = 0; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/inc/rendering/irendermodule.hxx b/canvas/inc/rendering/irendermodule.hxx new file mode 100644 index 000000000..ed16f7eb6 --- /dev/null +++ b/canvas/inc/rendering/irendermodule.hxx @@ -0,0 +1,134 @@ +/* -*- 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 . + */ + +#pragma once + +#include <memory> +#include <utility> + +namespace basegfx +{ + class B2IVector; +} + +namespace canvas +{ + struct ISurface; + + struct Vertex + { + float r,g,b,a; + float u,v; + float x,y,z; + }; + + /** Output module interface for backend render implementations. + + Implement this interface for each operating system- or + library-specific rendering backend, which needs coupling with + the canvas rendering framework (which can be shared between + all backend implementations). + */ + struct IRenderModule + { + /** Type of primitive passed to the render module via + pushVertex() + */ + enum class PrimitiveType + { + Unknown, + Triangle, + Quad + }; + + virtual ~IRenderModule() {} + + /// Lock rendermodule against concurrent access + virtual void lock() const = 0; + + /// Unlock rendermodule for concurrent access + virtual void unlock() const = 0; + + /** Maximal size of VRAM pages available + + This is typically the maximum texture size of the + hardware, or some arbitrary limit if the backend is + software. + */ + virtual ::basegfx::B2IVector getPageSize() = 0; + + /** Create a (possibly hardware-accelerated) surface + + @return a pointer to a surface, which is an abstraction of + a piece of (possibly hardware-accelerated) texture memory. + */ + virtual std::shared_ptr<ISurface> createSurface( const ::basegfx::B2IVector& surfaceSize ) = 0; + + /** Begin rendering the given primitive. + + Each beginPrimitive() call must be matched with an + endPrimitive() call. + */ + virtual void beginPrimitive( PrimitiveType eType ) = 0; + + /** Finish rendering a primitive. + + Each beginPrimitive() call must be matched with an + endPrimitive() call. + */ + virtual void endPrimitive() = 0; + + /** Add given vertex to current primitive + + After issuing a beginPrimitive(), each pushVertex() adds a + vertex to the active primitive. + */ + virtual void pushVertex( const Vertex& vertex ) = 0; + + /** Query error status + + @returns true, if an error occurred during primitive + construction. + */ + virtual bool isError() = 0; + }; + + /// Little RAII wrapper for guarding access to IRenderModule interface + class RenderModuleGuard + { + public: + explicit RenderModuleGuard( std::shared_ptr<IRenderModule> xRenderModule ) : + mpRenderModule(std::move( xRenderModule )) + { + mpRenderModule->lock(); + } + + ~RenderModuleGuard() + { + mpRenderModule->unlock(); + } + + RenderModuleGuard(const RenderModuleGuard&) = delete; + RenderModuleGuard& operator=( const RenderModuleGuard& ) = delete; + private: + const std::shared_ptr<IRenderModule> mpRenderModule; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/inc/rendering/isurface.hxx b/canvas/inc/rendering/isurface.hxx new file mode 100644 index 000000000..f3d3beaf0 --- /dev/null +++ b/canvas/inc/rendering/isurface.hxx @@ -0,0 +1,69 @@ +/* -*- 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 . + */ + +#pragma once + +namespace basegfx +{ + class B2IRange; + class B2IPoint; +} + +namespace canvas +{ + struct IColorBuffer; + + struct ISurface + { + virtual ~ISurface() {} + + /** Select texture behind this interface to be the current one + for primitive output. + */ + virtual bool selectTexture() = 0; + + /** Tells whether the surface is valid or not + */ + virtual bool isValid() = 0; + + /** Update surface content from given IColorBuffer + + This method updates the given subarea of the surface from + the given color buffer bits. + + @param rDestPos + Position in the surface, where the subset update should + have its left, top edge + + @param rSourceRect + Size and position of the rectangular subset update in the + source color buffer + + @param rSource + Source bits to use for the update + + @return true, if the update was successful + */ + virtual bool update( const ::basegfx::B2IPoint& rDestPos, + const ::basegfx::B2IRange& rSourceRect, + IColorBuffer& rSource ) = 0; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/inc/rendering/isurfaceproxy.hxx b/canvas/inc/rendering/isurfaceproxy.hxx new file mode 100644 index 000000000..ebe8abc10 --- /dev/null +++ b/canvas/inc/rendering/isurfaceproxy.hxx @@ -0,0 +1,98 @@ +/* -*- 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 . + */ + +#pragma once + +namespace basegfx +{ + class B2DRange; + class B2DPoint; + class B2DPolyPolygon; + class B2DHomMatrix; +} + +namespace canvas +{ + struct ISurfaceProxy + { + virtual ~ISurfaceProxy() {} + + /** Notify the proxy that the color buffer has changed + */ + virtual void setColorBufferDirty() = 0; + + /** Render the surface content to screen. + + @param fAlpha + Overall alpha for content + + @param rPos + Output position + + @param rTransform + Output transformation (does not affect output position) + */ + virtual bool draw( double fAlpha, + const ::basegfx::B2DPoint& rPos, + const ::basegfx::B2DHomMatrix& rTransform ) = 0; + + /** Render the surface content to screen. + + @param fAlpha + Overall alpha for content + + @param rPos + Output position + + @param rArea + Subset of the surface to render. Coordinate system are + surface area pixel, given area will be clipped to the + surface bounds. + + @param rTransform + Output transformation (does not affect output position) + */ + virtual bool draw( double fAlpha, + const ::basegfx::B2DPoint& rPos, + const ::basegfx::B2DRange& rArea, + const ::basegfx::B2DHomMatrix& rTransform ) = 0; + + /** Render the surface content to screen. + + @param fAlpha + Overall alpha for content + + @param rPos + Output position + + @param rClipPoly + Clip polygon for the surface. The clip polygon is also + subject to the output transformation. + + @param rTransform + Output transformation (does not affect output position) + */ + virtual bool draw( double fAlpha, + const ::basegfx::B2DPoint& rPos, + const ::basegfx::B2DPolyPolygon& rClipPoly, + const ::basegfx::B2DHomMatrix& rTransform ) = 0; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/inc/rendering/isurfaceproxymanager.hxx b/canvas/inc/rendering/isurfaceproxymanager.hxx new file mode 100644 index 000000000..71b12b29e --- /dev/null +++ b/canvas/inc/rendering/isurfaceproxymanager.hxx @@ -0,0 +1,66 @@ +/* -*- 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 . + */ + +#pragma once + +#include <canvas/canvastoolsdllapi.h> +#include <memory> + +namespace canvas +{ + struct ISurfaceProxy; + struct IColorBuffer; + struct IRenderModule; + + /** Manager interface, which handles surface proxy objects. + + Typically, each canvas instantiation has one + SurfaceProxyManager object, to handle their surfaces. Surfaces + itself are opaque objects, which encapsulate a framebuffer to + render upon, plus an optional (possibly accelerated) texture. + */ + struct ISurfaceProxyManager + { + virtual ~ISurfaceProxyManager() {} + + /** Create a surface proxy for a color buffer. + + The whole idea is build around the concept that you create + some arbitrary buffer which contains the image data and + tell the texture manager about it. From there on you can + draw into this image using any kind of graphics api you + want. In the technical sense we allocate some space in + local videomemory or AGP memory which will be filled on + demand, which means if there exists any rendering + operation that needs to read from this memory location. + This method creates a logical hardware surface object + which uses the given color buffer as the image source. + Internally this texture may even be distributed to several + real hardware surfaces. + */ + virtual std::shared_ptr< ISurfaceProxy > createSurfaceProxy( + const std::shared_ptr<IColorBuffer>& pBuffer ) const = 0; + }; + + /** Create a surface proxy for the given render module. + */ + CANVASTOOLS_DLLPUBLIC std::shared_ptr<ISurfaceProxyManager> createSurfaceProxyManager( const std::shared_ptr<IRenderModule>& rRenderModule ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |