move misc surface helpers to wxIDirectFBSurface class
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -28,44 +28,6 @@
|
||||
#define wxSTR_TO_DFB(s) wxConvUTF8.cWC2MB((s).wc_str(*wxConvUI))
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// surface manipulation helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Mode of wxDfbCloneSurface() call
|
||||
enum wxDfbCloneSurfaceMode
|
||||
{
|
||||
/// Don't copy surface pixels, just clone surface size and attributes
|
||||
wxDfbCloneSurface_NoPixels = 0,
|
||||
/// Make exact copy, including the pixels
|
||||
wxDfbCloneSurface_CopyPixels
|
||||
};
|
||||
|
||||
/**
|
||||
Creates surface that is compatible with given @a surface (i.e. has same
|
||||
capabilities, pixel format etc.) and has given @a size.
|
||||
*/
|
||||
wxIDirectFBSurfacePtr wxDfbCreateCompatibleSurface(
|
||||
const wxIDirectFBSurfacePtr& surface,
|
||||
const wxSize& size);
|
||||
|
||||
/**
|
||||
Creates a new surface by cloning existing one. Depending on @a mode,
|
||||
either makes exact copy (wxDfbCloneSurface_CopyPixels) or only creates a
|
||||
new surface with the same size and attributes (wxDfbCloneSurface_NoPixels).
|
||||
*/
|
||||
wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
|
||||
wxDfbCloneSurfaceMode mode);
|
||||
|
||||
/// Returns bit depth used by the surface
|
||||
int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s);
|
||||
|
||||
/// Returns interface to the primary display layer:
|
||||
wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer();
|
||||
|
||||
/// Returns interface to the primary surface:
|
||||
wxIDirectFBSurfacePtr wxDfbGetPrimarySurface();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// misc helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@@ -266,10 +266,33 @@ struct wxIDirectFBSurface : public wxDfbWrapper<IDirectFBSurface>
|
||||
bool Blit(const wxIDirectFBSurfacePtr& source,
|
||||
const DFBRectangle *source_rect,
|
||||
int x, int y)
|
||||
{
|
||||
return Check(
|
||||
m_ptr->Blit(m_ptr, source->GetRaw(), source_rect, x, y));
|
||||
}
|
||||
{ return Blit(source->GetRaw(), source_rect, x, y); }
|
||||
|
||||
bool Blit(IDirectFBSurface *source,
|
||||
const DFBRectangle *source_rect,
|
||||
int x, int y)
|
||||
{ return Check(m_ptr->Blit(m_ptr, source, source_rect, x, y)); }
|
||||
|
||||
|
||||
/// Returns bit depth used by the surface or -1 on error
|
||||
int GetDepth();
|
||||
|
||||
/**
|
||||
Creates a new surface by cloning this one. New surface will have same
|
||||
capabilities, pixel format and pixel data as the existing one.
|
||||
|
||||
@see CreateCompatible
|
||||
*/
|
||||
wxIDirectFBSurfacePtr Clone();
|
||||
|
||||
/**
|
||||
Creates a surface compatible with this one, i.e. surface with the same
|
||||
capabilities and pixel format, but with different and size.
|
||||
|
||||
@param size Size of the surface to create. If wxDefaultSize, use the
|
||||
size of this surface.
|
||||
*/
|
||||
wxIDirectFBSurfacePtr CreateCompatible(const wxSize& size = wxDefaultSize);
|
||||
};
|
||||
|
||||
|
||||
@@ -446,7 +469,8 @@ struct wxIDirectFB : public wxDfbWrapper<IDirectFB>
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxIDirectFBDisplayLayerPtr GetDisplayLayer(DFBDisplayLayerID id)
|
||||
wxIDirectFBDisplayLayerPtr
|
||||
GetDisplayLayer(DFBDisplayLayerID id = DLID_PRIMARY)
|
||||
{
|
||||
IDirectFBDisplayLayer *l;
|
||||
if ( Check(m_ptr->GetDisplayLayer(m_ptr, id, &l)) )
|
||||
@@ -455,6 +479,9 @@ struct wxIDirectFB : public wxDfbWrapper<IDirectFB>
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/// Returns primary surface
|
||||
wxIDirectFBSurfacePtr GetPrimarySurface();
|
||||
|
||||
private:
|
||||
wxIDirectFB(IDirectFB *ptr) { Init(ptr); }
|
||||
|
||||
|
@@ -71,12 +71,12 @@ static wxVideoMode GetCurrentVideoMode()
|
||||
{
|
||||
wxVideoMode m;
|
||||
|
||||
wxIDirectFBSurfacePtr surface(wxDfbGetPrimarySurface());
|
||||
wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->GetPrimarySurface());
|
||||
if ( !surface )
|
||||
return m; // invalid
|
||||
|
||||
surface->GetSize(&m.w, &m.h);
|
||||
m.bpp = wxDfbGetSurfaceDepth(surface);
|
||||
m.bpp = surface->GetDepth();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
@@ -158,8 +158,9 @@ public:
|
||||
|
||||
wxBitmapRefData(const wxBitmapRefData& data)
|
||||
{
|
||||
m_surface = wxDfbCloneSurface(data.m_surface,
|
||||
wxDfbCloneSurface_NoPixels);
|
||||
if ( data.m_surface )
|
||||
m_surface = data.m_surface->Clone();
|
||||
|
||||
m_mask = data.m_mask ? new wxMask(*data.m_mask) : NULL;
|
||||
#if wxUSE_PALETTE
|
||||
m_palette = data.m_palette ? new wxPalette(*data.m_palette) : NULL;
|
||||
@@ -294,7 +295,7 @@ int wxBitmap::GetDepth() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
|
||||
|
||||
return wxDfbGetSurfaceDepth(M_BITMAP->m_surface);
|
||||
return M_BITMAP->m_surface->GetDepth();
|
||||
}
|
||||
|
||||
wxMask *wxBitmap::GetMask() const
|
||||
|
@@ -130,7 +130,7 @@ void wxDC::DestroyClippingRegion()
|
||||
|
||||
int wxDC::GetDepth() const
|
||||
{
|
||||
return wxDfbGetSurfaceDepth(m_surface);
|
||||
return m_surface->GetDepth();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@@ -65,7 +65,7 @@ void wxWindowDC::InitForWin(wxWindow *win, const wxRect *rect)
|
||||
// so let's create a dummy surface that has the same format as the real
|
||||
// one would have and let the code paint on it:
|
||||
wxSize size(rect ? rect->GetSize() : win->GetSize());
|
||||
surface = wxDfbCreateCompatibleSurface(win->GetDfbSurface(), size);
|
||||
surface = win->GetDfbSurface()->CreateCompatible(size);
|
||||
}
|
||||
else if ( !rect )
|
||||
{
|
||||
|
@@ -38,7 +38,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxDC)
|
||||
|
||||
wxScreenDC::wxScreenDC()
|
||||
{
|
||||
Init(wxDfbGetPrimarySurface());
|
||||
Init(wxIDirectFB::Get()->GetPrimarySurface());
|
||||
}
|
||||
|
||||
#warning "FIXME: does wxScreenDC need Flip call in dtor?"
|
||||
|
@@ -122,7 +122,7 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent,
|
||||
pos.y = 0;
|
||||
|
||||
// create DirectFB window:
|
||||
wxIDirectFBDisplayLayerPtr layer = wxDfbGetDisplayLayer();
|
||||
wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
|
||||
wxCHECK_MSG( layer, false, _T("no display layer") );
|
||||
|
||||
DFBWindowDescription desc;
|
||||
|
@@ -83,90 +83,6 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height)
|
||||
wxDisplaySize(width, height);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// surface manipulation helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
wxIDirectFBSurfacePtr wxDfbCreateCompatibleSurface(
|
||||
const wxIDirectFBSurfacePtr& s,
|
||||
const wxSize& size)
|
||||
{
|
||||
if ( !s )
|
||||
return NULL;
|
||||
|
||||
DFBSurfaceDescription desc;
|
||||
desc.flags = (DFBSurfaceDescriptionFlags)(
|
||||
DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
|
||||
s->GetCapabilities(&desc.caps);
|
||||
s->GetPixelFormat(&desc.pixelformat);
|
||||
desc.width = size.x;
|
||||
desc.height = size.y;
|
||||
|
||||
wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
|
||||
if ( !snew )
|
||||
return NULL;
|
||||
|
||||
if ( desc.pixelformat == DSPF_LUT8 )
|
||||
{
|
||||
wxIDirectFBPalettePtr pal(s->GetPalette());
|
||||
if ( s )
|
||||
{
|
||||
if ( !snew->SetPalette(pal) )
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return snew;
|
||||
}
|
||||
|
||||
wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
|
||||
wxDfbCloneSurfaceMode mode)
|
||||
{
|
||||
if ( !s )
|
||||
return NULL;
|
||||
|
||||
wxSize size;
|
||||
if ( !s->GetSize(&size.x, &size.y) )
|
||||
return NULL;
|
||||
|
||||
wxIDirectFBSurfacePtr snew(wxDfbCreateCompatibleSurface(s, size));
|
||||
if ( !snew )
|
||||
return NULL;
|
||||
|
||||
if ( mode == wxDfbCloneSurface_CopyPixels )
|
||||
{
|
||||
if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
|
||||
return NULL;
|
||||
if ( !snew->Blit(s, NULL, 0, 0) )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return snew;
|
||||
}
|
||||
|
||||
int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s)
|
||||
{
|
||||
wxCHECK_MSG( s, -1, _T("invalid surface") );
|
||||
|
||||
DFBSurfacePixelFormat format = DSPF_UNKNOWN;
|
||||
|
||||
if ( !s->GetPixelFormat(&format) )
|
||||
return -1;
|
||||
|
||||
return DFB_BITS_PER_PIXEL(format);
|
||||
}
|
||||
|
||||
wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer()
|
||||
{
|
||||
return wxIDirectFB::Get()->GetDisplayLayer(DLID_PRIMARY);
|
||||
}
|
||||
|
||||
wxIDirectFBSurfacePtr wxDfbGetPrimarySurface()
|
||||
{
|
||||
wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
|
||||
return layer ? layer->GetSurface() : NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// mouse
|
||||
@@ -174,7 +90,7 @@ wxIDirectFBSurfacePtr wxDfbGetPrimarySurface()
|
||||
|
||||
void wxGetMousePosition(int *x, int *y)
|
||||
{
|
||||
wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
|
||||
wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
|
||||
if ( layer )
|
||||
layer->GetCursorPosition(x, y);
|
||||
}
|
||||
|
@@ -370,7 +370,7 @@ void wxWindowDFB::WarpPointer(int x, int y)
|
||||
if ( x >= w ) x = w-1;
|
||||
if ( y >= h ) y = h-1;
|
||||
|
||||
wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
|
||||
wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
|
||||
wxCHECK_RET( layer, _T("no display layer") );
|
||||
|
||||
layer->WarpCursor(x, y);
|
||||
|
@@ -95,3 +95,74 @@ void wxIDirectFB::CleanUp()
|
||||
{
|
||||
ms_ptr.Reset();
|
||||
}
|
||||
|
||||
wxIDirectFBSurfacePtr wxIDirectFB::GetPrimarySurface()
|
||||
{
|
||||
wxIDirectFBDisplayLayerPtr layer(GetDisplayLayer());
|
||||
return layer ? layer->GetSurface() : NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFBSurface
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int wxIDirectFBSurface::GetDepth()
|
||||
{
|
||||
DFBSurfacePixelFormat format = DSPF_UNKNOWN;
|
||||
|
||||
if ( !GetPixelFormat(&format) )
|
||||
return -1;
|
||||
|
||||
return DFB_BITS_PER_PIXEL(format);
|
||||
}
|
||||
|
||||
wxIDirectFBSurfacePtr wxIDirectFBSurface::CreateCompatible(const wxSize& sz)
|
||||
{
|
||||
wxSize size(sz);
|
||||
if ( size == wxDefaultSize )
|
||||
{
|
||||
if ( !GetSize(&size.x, &size.y) )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxCHECK_MSG( size.x > 0 && size.y > 0, NULL, _T("invalid size") );
|
||||
|
||||
DFBSurfaceDescription desc;
|
||||
desc.flags = (DFBSurfaceDescriptionFlags)(
|
||||
DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
|
||||
GetCapabilities(&desc.caps);
|
||||
GetPixelFormat(&desc.pixelformat);
|
||||
desc.width = size.x;
|
||||
desc.height = size.y;
|
||||
|
||||
wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
|
||||
if ( !snew )
|
||||
return NULL;
|
||||
|
||||
if ( desc.pixelformat == DSPF_LUT8 )
|
||||
{
|
||||
wxIDirectFBPalettePtr pal(GetPalette());
|
||||
if ( pal )
|
||||
{
|
||||
if ( !snew->SetPalette(pal) )
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return snew;
|
||||
}
|
||||
|
||||
wxIDirectFBSurfacePtr wxIDirectFBSurface::Clone()
|
||||
{
|
||||
wxIDirectFBSurfacePtr snew(CreateCompatible());
|
||||
if ( !snew )
|
||||
return NULL;
|
||||
|
||||
if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
|
||||
return NULL;
|
||||
|
||||
if ( !snew->Blit(GetRaw(), NULL, 0, 0) )
|
||||
return NULL;
|
||||
|
||||
return snew;
|
||||
}
|
||||
|
Reference in New Issue
Block a user