Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / vcl / cairo.hxx
blob9596b24ccb243922f243a7093781da00e212857e
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/Scanline.hxx>
25 #include <vcl/vclptr.hxx>
26 #include <config_features.h>
27 #include <config_cairo_rgba.h>
28 #include <memory>
30 // Using formats that match cairo's formats.
31 // SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory.
34 For internal cairo we have the option --enable-cairo-rgba which is potentially
35 useful for Android or Online to switch the rgb components. For Android cairo then
36 matches the OpenGL GL_RGBA format so we can use it there where we don't have
37 GL_BGRA support. Similarly for Online we can then use cairo's pixel data
38 without needing to swizzle it for use as a canvas ImageData.
40 #if ENABLE_CAIRO_RGBA
41 #define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown)
42 #define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown)
43 #define SVP_CAIRO_BLUE 1
44 #define SVP_CAIRO_GREEN 2
45 #define SVP_CAIRO_RED 0
46 #define SVP_CAIRO_ALPHA 3
47 #elif defined OSL_BIGENDIAN
48 #define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown)
49 #define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown)
50 #define SVP_CAIRO_BLUE 3
51 #define SVP_CAIRO_GREEN 2
52 #define SVP_CAIRO_RED 1
53 #define SVP_CAIRO_ALPHA 0
54 #else
55 #define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcBgr | ScanlineFormat::TopDown)
56 #define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown)
57 #define SVP_CAIRO_BLUE 0
58 #define SVP_CAIRO_GREEN 1
59 #define SVP_CAIRO_RED 2
60 #define SVP_CAIRO_ALPHA 3
61 #endif
63 typedef struct _cairo_surface cairo_surface_t;
64 typedef struct _cairo cairo_t;
66 class VirtualDevice;
68 namespace cairo {
70 typedef std::shared_ptr<cairo_surface_t> CairoSurfaceSharedPtr;
71 typedef std::shared_ptr<cairo_t> CairoSharedPtr;
72 struct Surface;
73 typedef std::shared_ptr<Surface> SurfaceSharedPtr;
75 /** Cairo surface interface
77 For each cairo-supported platform, there's an implementation of
78 this interface
80 struct Surface
82 public:
83 virtual ~Surface() {}
85 // Query methods
86 virtual CairoSharedPtr getCairo() const = 0;
87 virtual CairoSurfaceSharedPtr getCairoSurface() const = 0;
88 virtual SurfaceSharedPtr getSimilar(int cairo_content_type, int width, int height) const = 0;
90 /// factory for VirDev on this surface
91 virtual VclPtr<VirtualDevice> createVirtualDevice() const = 0;
93 /// Resize the surface (possibly destroying content), only possible for X11 typically
94 /// so on failure caller must create a new surface instead
95 virtual bool Resize( int /*width*/, int /*height*/ ) { return false; }
97 /// Flush all pending output to surface
98 virtual void flush() const = 0;
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */