Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
graphics.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Display backend interface.
4 * Copyright (C) 2022 PBS <pbs3141@gmail.com>
5 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
6 */
7
8#ifndef INKSCAPE_UI_WIDGET_CANVAS_GRAPHICS_H
9#define INKSCAPE_UI_WIDGET_CANVAS_GRAPHICS_H
10
11#include <cstdint>
12#include <memory>
13#include <optional>
14#include <utility>
15#include <vector>
16
17#include <2geom/rect.h>
18#include <cairomm/refptr.h>
19#include "display/rendermode.h"
20#include "fragment.h"
21
22namespace Cairo {
23class Context;
24class ImageSurface;
25} // namespace Cairo
26
27namespace Inkscape::UI::Widget {
28
29class Stores;
30class Prefs;
31
33{
34 std::vector<Geom::Rect> pages;
35};
36
38{
39public:
40 // Creation/destruction.
41 static std::unique_ptr<Graphics> create_gl (Prefs const &prefs, Stores const &stores, PageInfo const &pi);
42 static std::unique_ptr<Graphics> create_cairo(Prefs const &prefs, Stores const &stores, PageInfo const &pi);
43 virtual ~Graphics() = default;
44
45 // State updating.
46 virtual void set_scale_factor(int) = 0;
47 virtual void set_outlines_enabled(bool) = 0;
48 virtual void set_background_in_stores(bool) = 0;
49
51 virtual void set_colours(std::uint32_t page, std::uint32_t desk, std::uint32_t border) = 0;
52
53 // Store manipulation.
54 virtual void recreate_store(Geom::IntPoint const &dims) = 0;
55 virtual void shift_store(Fragment const &dest) = 0;
56 virtual void swap_stores() = 0;
57 virtual void fast_snapshot_combine() = 0;
58 virtual void snapshot_combine(Fragment const &dest) = 0;
59 virtual void invalidate_snapshot() = 0;
60
61 // Misc.
62 virtual bool is_opengl() const = 0;
63 virtual void invalidated_glstate() = 0;
64
65 // Tile drawing.
68 virtual Cairo::RefPtr<Cairo::ImageSurface> request_tile_surface(Geom::IntRect const &rect, bool nogl) = 0;
71 virtual void draw_tile(Fragment const &fragment, Cairo::RefPtr<Cairo::ImageSurface> surface, Cairo::RefPtr<Cairo::ImageSurface> outline_surface) = 0;
74 virtual void junk_tile_surface(Cairo::RefPtr<Cairo::ImageSurface> surface) = 0;
75
76 // Widget painting.
87 virtual void paint_widget(Fragment const &view, PaintArgs const &args, Cairo::RefPtr<Cairo::Context> const &cr) = 0;
88
89 // Static functions providing common functionality.
90 static bool check_single_page(Fragment const &view, PageInfo const &pi);
91 static std::pair<Geom::IntRect, Geom::IntRect> calc_splitview_cliprects(Geom::IntPoint const &size, Geom::Point const &splitfrac, SplitDirection splitdir);
92 static void paint_splitview_controller(Geom::IntPoint const &size, Geom::Point const &splitfrac, SplitDirection splitdir, SplitDirection hoverdir, Cairo::RefPtr<Cairo::Context> const &cr);
93 static void paint_background(Fragment const &fragment, PageInfo const &pi,
94 std::uint32_t page, std::uint32_t desk,
95 Cairo::RefPtr<Cairo::Context> const &cr);
96};
97
98} // namespace Inkscape::UI::Widget
99
100#endif // INKSCAPE_UI_WIDGET_CANVAS_GRAPHICS_H
101
102/*
103 Local Variables:
104 mode:c++
105 c-file-style:"stroustrup"
106 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107 indent-tabs-mode:nil
108 fill-column:99
109 End:
110*/
111// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Cairo::RefPtr< Cairo::ImageSurface > surface
Definition canvas.cpp:137
uint64_t page
Definition canvas.cpp:171
uint64_t desk
Definition canvas.cpp:171
Cairo::RefPtr< Cairo::ImageSurface > outline_surface
Definition canvas.cpp:138
Fragment fragment
Definition canvas.cpp:136
Axis aligned, non-empty, generic rectangle.
Two-dimensional point with integer coordinates.
Definition int-point.h:57
Two-dimensional point that doubles as a vector.
Definition point.h:66
virtual void junk_tile_surface(Cairo::RefPtr< Cairo::ImageSurface > surface)=0
Get rid of a surface previously issued by request_tile_surface() without committing it to the canvas.
virtual bool is_opengl() const =0
Whether this is an OpenGL backend.
virtual void set_scale_factor(int)=0
Set the HiDPI scale factor.
static void paint_splitview_controller(Geom::IntPoint const &size, Geom::Point const &splitfrac, SplitDirection splitdir, SplitDirection hoverdir, Cairo::RefPtr< Cairo::Context > const &cr)
Definition graphics.cpp:119
virtual void shift_store(Fragment const &dest)=0
Called when the store fragment shifts position to dest.
virtual void invalidate_snapshot()=0
Indicate that the content in the snapshot store is not going to be used again.
static std::unique_ptr< Graphics > create_gl(Prefs const &prefs, Stores const &stores, PageInfo const &pi)
virtual void recreate_store(Geom::IntPoint const &dims)=0
Set the store to a surface of the given size, of unspecified contents.
static bool check_single_page(Fragment const &view, PageInfo const &pi)
Definition graphics.cpp:165
virtual void set_outlines_enabled(bool)=0
Whether to maintain a second layer of outline content.
static std::unique_ptr< Graphics > create_cairo(Prefs const &prefs, Stores const &stores, PageInfo const &pi)
virtual void fast_snapshot_combine()=0
Paste the store onto the snapshot.
virtual void snapshot_combine(Fragment const &dest)=0
Paste the snapshot followed by the store onto a new snapshot at dest.
virtual void set_background_in_stores(bool)=0
Whether to assume the first layer is drawn on top of background or transparency.
virtual void invalidated_glstate()=0
Tells the Graphics to no longer rely on any OpenGL state it had set up.
virtual void paint_widget(Fragment const &view, PaintArgs const &args, Cairo::RefPtr< Cairo::Context > const &cr)=0
virtual Cairo::RefPtr< Cairo::ImageSurface > request_tile_surface(Geom::IntRect const &rect, bool nogl)=0
Return a surface for drawing on.
virtual void swap_stores()=0
Exchange the store and snapshot surfaces.
virtual void set_colours(std::uint32_t page, std::uint32_t desk, std::uint32_t border)=0
Set colours for background/page shadow drawing.
static void paint_background(Fragment const &fragment, PageInfo const &pi, std::uint32_t page, std::uint32_t desk, Cairo::RefPtr< Cairo::Context > const &cr)
Definition graphics.cpp:54
virtual void draw_tile(Fragment const &fragment, Cairo::RefPtr< Cairo::ImageSurface > surface, Cairo::RefPtr< Cairo::ImageSurface > outline_surface)=0
Commit the contents of a surface previously issued by request_tile_surface() to the canvas.
static std::pair< Geom::IntRect, Geom::IntRect > calc_splitview_cliprects(Geom::IntPoint const &size, Geom::Point const &splitfrac, SplitDirection splitdir)
Definition graphics.cpp:96
Control handle rendering/caching.
Custom widgets.
Definition desktop.h:126
Axis-aligned rectangle.
TODO: insert short description here.
A "fragment" is a rectangle of drawn content at a specfic place.
Definition fragment.h:12
std::optional< Geom::Point > mouse
Definition graphics.h:79
std::vector< Geom::Rect > pages
Definition graphics.h:34
double border