mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 14:41:25 +00:00
While the fix could have been more effective, it seems like this patch stream better with the coding logic that was there..., maybe later we will want to change the locking into more effective way. (There is just the primary surface to protect in reiality) Signed-off-by: Izik Eidus <ieidus@redhat.com>
109 lines
3.0 KiB
C++
109 lines
3.0 KiB
C++
/*
|
|
Copyright (C) 2009 Red Hat, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of
|
|
the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "common.h"
|
|
#include "pixels_source.h"
|
|
#include "pixels_source_p.h"
|
|
#include "platform_utils.h"
|
|
#include "threads.h"
|
|
#include "debug.h"
|
|
|
|
|
|
static SpicePoint get_bitmap_size(HDC dc)
|
|
{
|
|
BITMAP bitmap_info;
|
|
SpicePoint size;
|
|
|
|
GetObject(GetCurrentObject(dc, OBJ_BITMAP), sizeof(bitmap_info), &bitmap_info);
|
|
|
|
size.x = bitmap_info.bmWidth;
|
|
size.y = bitmap_info.bmHeight;
|
|
return size;
|
|
}
|
|
|
|
PixelsSource::PixelsSource()
|
|
{
|
|
ASSERT(sizeof(_opaque) >= sizeof(PixelsSource_p));
|
|
_origin.x = _origin.y = 0;
|
|
memset(_opaque, 0, sizeof(_opaque));
|
|
PixelsSource_p* p_data = (PixelsSource_p*)_opaque;
|
|
p_data->_mutex = new RecurciveMutex();
|
|
}
|
|
|
|
PixelsSource::~PixelsSource()
|
|
{
|
|
PixelsSource_p* p_data = (PixelsSource_p*)_opaque;
|
|
delete p_data->_mutex;
|
|
}
|
|
|
|
struct ResImage_p {
|
|
PixelsSource_p source_p;
|
|
HBITMAP prev_bitmap;
|
|
};
|
|
|
|
|
|
ImageFromRes::ImageFromRes(int res_id)
|
|
{
|
|
AutoDC dc(create_compatible_dc());
|
|
((ResImage_p*)get_opaque())->prev_bitmap = (HBITMAP)SelectObject(dc.get(),
|
|
get_bitmap_res(res_id));
|
|
((ResImage_p*)get_opaque())->source_p.dc = dc.release();
|
|
}
|
|
|
|
ImageFromRes::~ImageFromRes()
|
|
{
|
|
HDC dc = ((ResImage_p*)get_opaque())->source_p.dc;
|
|
if (dc) {
|
|
HGDIOBJ bitmap = SelectObject(dc, ((ResImage_p*)get_opaque())->prev_bitmap);
|
|
DeleteObject(bitmap);
|
|
DeleteDC(dc);
|
|
}
|
|
}
|
|
|
|
SpicePoint ImageFromRes::get_size()
|
|
{
|
|
ResImage_p* p_data = (ResImage_p*)get_opaque();
|
|
Lock lock(*p_data->source_p._mutex);
|
|
return get_bitmap_size(p_data->source_p.dc);
|
|
}
|
|
|
|
AlphaImageFromRes::AlphaImageFromRes(int res_id)
|
|
{
|
|
AutoDC dc(create_compatible_dc());
|
|
((ResImage_p*)get_opaque())->prev_bitmap = (HBITMAP)SelectObject(dc.get(),
|
|
get_alpha_bitmap_res(res_id));
|
|
((ResImage_p*)get_opaque())->source_p.dc = dc.release();
|
|
}
|
|
|
|
AlphaImageFromRes::~AlphaImageFromRes()
|
|
{
|
|
HDC dc = ((ResImage_p*)get_opaque())->source_p.dc;
|
|
if (dc) {
|
|
HGDIOBJ bitmap = SelectObject(dc, ((ResImage_p*)get_opaque())->prev_bitmap);
|
|
DeleteObject(bitmap);
|
|
DeleteDC(dc);
|
|
}
|
|
}
|
|
|
|
SpicePoint AlphaImageFromRes::get_size()
|
|
{
|
|
ResImage_p* p_data = (ResImage_p*)get_opaque();
|
|
Lock lock(*p_data->source_p._mutex);
|
|
return get_bitmap_size(p_data->source_p.dc);
|
|
}
|
|
|