2 Copyright (C) 2009 Red Hat, Inc.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "red_drawable.h"
23 #include "pixels_source_p.h"
27 static const uint64_t lock_timout = 1000 * 1000 * 10; /*10ms*/
29 void RedDrawable::copy_pixels(const PixelsSource& src, int src_x, int src_y, const SpiceRect& dest)
31 PixelsSource_p* dest_p_data = (PixelsSource_p*)get_opaque();
32 PixelsSource_p* src_p_data = (PixelsSource_p*)src.get_opaque();
35 Lock lock(*dest_p_data->_mutex);
36 Lock timed_lock(*src_p_data->_mutex, lock_timout);
37 if (!timed_lock.is_locked()) {
40 BitBlt(dest_p_data->dc, dest.left + _origin.x, dest.top + _origin.y,
41 dest.right - dest.left, dest.bottom - dest.top,
42 src_p_data->dc, src_x + src._origin.x,
43 src_y + src._origin.y, SRCCOPY);
48 void RedDrawable::blend_pixels(const PixelsSource& src, int src_x, int src_y, const SpiceRect& dest)
50 static BLENDFUNCTION blend_func = { AC_SRC_OVER, 0, 0xff, AC_SRC_ALPHA};
52 int width = dest.right - dest.left;
53 int height = dest.bottom - dest.top;
54 PixelsSource_p* dest_p_data = (PixelsSource_p*)get_opaque();
55 PixelsSource_p* src_p_data = (PixelsSource_p*)src.get_opaque();
57 RecurciveLock lock(*dest_p_data->_mutex);
58 RecurciveLock timed_lock(*src_p_data->_mutex, lock_timout);
59 if (!timed_lock.is_locked()) {
62 AlphaBlend(dest_p_data->dc, dest.left + _origin.x, dest.top + _origin.y, width, height,
63 src_p_data->dc, src_x + src._origin.x, src_y + src._origin.y, width, height,
69 void RedDrawable::combine_pixels(const PixelsSource& src, int src_x, int src_y, const SpiceRect& dest,
84 THROW("invalid op %d", op);
87 PixelsSource_p* dest_p_data = (PixelsSource_p*)get_opaque();
88 PixelsSource_p* src_p_data = (PixelsSource_p*)src.get_opaque();
90 RecurciveLock lock(*dest_p_data->_mutex);
91 RecurciveLock timed_lock(*src_p_data->_mutex, lock_timout);
92 if (!timed_lock.is_locked()) {
95 BitBlt(dest_p_data->dc, dest.left + _origin.x, dest.top + _origin.y,
96 dest.right - dest.left, dest.bottom - dest.top,
97 src_p_data->dc, src_x + src._origin.x,
98 src_y + src._origin.y, rop);
103 void RedDrawable::erase_rect(const SpiceRect& rect, rgb32_t color)
106 r.left = rect.left + _origin.x;
107 r.right = rect.right + _origin.x;
108 r.top = rect.top + _origin.y;
109 r.bottom = rect.bottom + _origin.y;
111 PixelsSource_p* dest_p_data = (PixelsSource_p*)get_opaque();
112 RecurciveLock lock(*dest_p_data->_mutex);
113 FillRect(dest_p_data->dc, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
116 void RedDrawable::fill_rect(const SpiceRect& rect, rgb32_t color)
119 r.left = rect.left + _origin.x;
120 r.right = rect.right + _origin.x;
121 r.top = rect.top + _origin.y;
122 r.bottom = rect.bottom + _origin.y;
124 HBRUSH brush = CreateSolidBrush(RGB(rgb32_get_red(color),
125 rgb32_get_green(color),
126 rgb32_get_blue(color)));
128 PixelsSource_p* dest_p_data = (PixelsSource_p*)get_opaque();
129 RecurciveLock lock(*dest_p_data->_mutex);
130 FillRect(dest_p_data->dc, &r, brush);
136 void RedDrawable::frame_rect(const SpiceRect& rect, rgb32_t color)
139 r.left = rect.left + _origin.x;
140 r.right = rect.right + _origin.x;
141 r.top = rect.top + _origin.y;
142 r.bottom = rect.bottom + _origin.y;
143 HBRUSH brush = CreateSolidBrush(RGB(rgb32_get_red(color),
144 rgb32_get_green(color),
145 rgb32_get_blue(color)));
147 PixelsSource_p* dest_p_data = (PixelsSource_p*)get_opaque();
148 RecurciveLock lock(*dest_p_data->_mutex);
149 FrameRect(dest_p_data->dc, &r, brush);