aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/XRenderResources.cc
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbcompose/XRenderResources.cc')
-rw-r--r--util/fbcompose/XRenderResources.cc130
1 files changed, 130 insertions, 0 deletions
diff --git a/util/fbcompose/XRenderResources.cc b/util/fbcompose/XRenderResources.cc
new file mode 100644
index 0000000..e868609
--- /dev/null
+++ b/util/fbcompose/XRenderResources.cc
@@ -0,0 +1,130 @@
1/** XRenderResources.cc file for the fluxbox compositor. */
2
3// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21// THE SOFTWARE.
22
23
24#include "XRenderResources.hh"
25
26#include "XRenderScreen.hh"
27
28using namespace FbCompositor;
29
30
31//--- XRENDER PICTURE WRAPPER --------------------------------------------------
32
33//------- CONSTRUCTORS AND DESTRUCTORS -----------------------------------------
34
35// Constructor.
36XRenderPicture::XRenderPicture(const XRenderScreen &screen, XRenderPictFormat *pict_format, const char *pict_filter) :
37 m_drawable(None),
38 m_gc(None),
39 m_picture(None),
40 m_resources_managed(false),
41 m_pict_filter(pict_filter),
42 m_pict_format(pict_format),
43 m_screen(screen) {
44
45 m_display = (Display*)(screen.display());
46}
47
48// Destructor.
49XRenderPicture::~XRenderPicture() {
50 freeResources();
51}
52
53
54//------- MUTATORS -------------------------------------------------------------
55
56// Associate the picture with the given pixmap.
57void XRenderPicture::setPixmap(Pixmap pixmap, bool manage_pixmap, XRenderPictureAttributes pa, long pa_mask) {
58 if (m_drawable != pixmap) {
59 freeResources();
60
61 m_drawable = pixmap;
62 m_gc = XCreateGC(m_display, pixmap, 0, NULL);
63
64 m_picture = XRenderCreatePicture(m_display, pixmap, m_pict_format, pa_mask, &pa);
65 XRenderSetPictureFilter(m_display, m_picture, m_pict_filter, NULL, 0);
66 }
67
68 m_resources_managed = manage_pixmap;
69}
70
71// Associate the picture with the given window.
72void XRenderPicture::setWindow(Window window, XRenderPictureAttributes pa, long pa_mask) {
73 if (m_drawable != window) {
74 freeResources();
75
76 m_drawable = window;
77 m_gc = XCreateGC(m_display, window, 0, NULL);
78
79 m_picture = XRenderCreatePicture(m_display, window, m_pict_format, pa_mask, &pa);
80 XRenderSetPictureFilter(m_display, m_picture, m_pict_filter, NULL, 0);
81 }
82
83 m_resources_managed = false;
84}
85
86
87// Reset the picture's transformation matrix.
88void XRenderPicture::resetPictureTransform() {
89 XTransform transform = { {
90 { XDoubleToFixed(1.0), XDoubleToFixed(0.0), XDoubleToFixed(0.0) },
91 { XDoubleToFixed(0.0), XDoubleToFixed(1.0), XDoubleToFixed(0.0) },
92 { XDoubleToFixed(0.0), XDoubleToFixed(0.0), XDoubleToFixed(1.0) }
93 } };
94 setPictureTransform(transform);
95}
96
97// Scale the picture by the given inverse quotients.
98void XRenderPicture::scalePicture(double x_factor_inv, double y_factor_inv) {
99 XTransform transform = { {
100 { XDoubleToFixed(x_factor_inv), XDoubleToFixed(0.0), XDoubleToFixed(0.0) },
101 { XDoubleToFixed(0.0), XDoubleToFixed(y_factor_inv), XDoubleToFixed(0.0) },
102 { XDoubleToFixed(0.0), XDoubleToFixed(0.0), XDoubleToFixed(1.0) }
103 } };
104 setPictureTransform(transform);
105}
106
107// Set the picture's transformation matrix.
108void XRenderPicture::setPictureTransform(const XTransform &transform) {
109 XRenderSetPictureTransform(m_display, m_picture, (XTransform*)(&transform));
110}
111
112
113//--- OTHER FUNCTIONS ----------------------------------------------------------
114
115// Free held resources, if any.
116void XRenderPicture::freeResources() {
117 if (m_picture) {
118 XRenderFreePicture(m_display, m_picture);
119 m_picture = None;
120 }
121 if (m_gc) {
122 XFreeGC(m_display, m_gc);
123 m_gc = None;
124 }
125
126 if (m_resources_managed && m_drawable) {
127 XFreePixmap(m_display, m_drawable); // Windows will never be managed.
128 m_drawable = None;
129 }
130}