workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / vcl / cairo.hxx
blobe9978526915d520914f853ed9a2f8faa4be0bcc6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <sal/config.h>
23 #include <osl/endian.h>
24 #include <vcl/vclptr.hxx>
25 #include <config_cairo_rgba.h>
26 #include <memory>
28 // Using formats that match cairo's formats.
29 // SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory.
32 For internal cairo we have the option --enable-cairo-rgba which is potentially
33 useful for Android or Online to switch the rgb components. For Android cairo then
34 matches the OpenGL GL_RGBA format so we can use it there where we don't have
35 GL_BGRA support. Similarly for Online we can then use cairo's pixel data
36 without needing to swizzle it for use as a canvas ImageData.
38 #if ENABLE_CAIRO_RGBA
39 #define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb)
40 #define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba)
41 #define SVP_CAIRO_BLUE 1
42 #define SVP_CAIRO_GREEN 2
43 #define SVP_CAIRO_RED 0
44 #define SVP_CAIRO_ALPHA 3
45 #elif defined OSL_BIGENDIAN
46 #define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb)
47 #define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb)
48 #define SVP_CAIRO_BLUE 3
49 #define SVP_CAIRO_GREEN 2
50 #define SVP_CAIRO_RED 1
51 #define SVP_CAIRO_ALPHA 0
52 #else
53 #define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcBgr)
54 #define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra)
55 #define SVP_CAIRO_BLUE 0
56 #define SVP_CAIRO_GREEN 1
57 #define SVP_CAIRO_RED 2
58 #define SVP_CAIRO_ALPHA 3
59 #endif
61 typedef struct _cairo_surface cairo_surface_t;
62 typedef struct _cairo cairo_t;
64 class VirtualDevice;
66 namespace cairo {
68 typedef std::shared_ptr<cairo_surface_t> CairoSurfaceSharedPtr;
69 typedef std::shared_ptr<cairo_t> CairoSharedPtr;
70 struct Surface;
71 typedef std::shared_ptr<Surface> SurfaceSharedPtr;
73 /** Cairo surface interface
75 For each cairo-supported platform, there's an implementation of
76 this interface
78 struct Surface
80 public:
81 virtual ~Surface() {}
83 // Query methods
84 virtual CairoSharedPtr getCairo() const = 0;
85 virtual CairoSurfaceSharedPtr getCairoSurface() const = 0;
86 virtual SurfaceSharedPtr getSimilar(int cairo_content_type, int width, int height) const = 0;
88 /// factory for VirDev on this surface
89 virtual VclPtr<VirtualDevice> createVirtualDevice() const = 0;
91 /// Resize the surface (possibly destroying content), only possible for X11 typically
92 /// so on failure caller must create a new surface instead
93 virtual bool Resize( int /*width*/, int /*height*/ ) { return false; }
95 /// Flush all pending output to surface
96 virtual void flush() const = 0;
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */