Move scale factor-related wxBitmap functions out of line

This will make it possible to change them later without breaking ABI,
which is probably worth paying the price of a function call (assuming
the compiler could de-virtualize this call and inline it before).

No real changes.
This commit is contained in:
Vadim Zeitlin
2021-10-24 19:19:29 +02:00
parent 2c1f4c002d
commit 1056ba19af
4 changed files with 84 additions and 16 deletions

View File

@@ -177,8 +177,7 @@ public:
virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0; virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) = 0; virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
virtual bool CreateScaled(int w, int h, int d, double logicalScale) virtual bool CreateScaled(int w, int h, int d, double logicalScale);
{ return Create(wxRound(w*logicalScale), wxRound(h*logicalScale), d); }
virtual int GetHeight() const = 0; virtual int GetHeight() const = 0;
virtual int GetWidth() const = 0; virtual int GetWidth() const = 0;
@@ -188,12 +187,11 @@ public:
{ return wxSize(GetWidth(), GetHeight()); } { return wxSize(GetWidth(), GetHeight()); }
// support for scaled bitmaps // support for scaled bitmaps
virtual void SetScaleFactor(double WXUNUSED(scale)) { } virtual void SetScaleFactor(double scale);
virtual double GetScaleFactor() const { return 1.0; } virtual double GetScaleFactor() const;
virtual double GetScaledWidth() const { return GetWidth() / GetScaleFactor(); } virtual double GetScaledWidth() const;
virtual double GetScaledHeight() const { return GetHeight() / GetScaleFactor(); } virtual double GetScaledHeight() const;
virtual wxSize GetScaledSize() const virtual wxSize GetScaledSize() const;
{ return wxSize(wxRound(GetScaledWidth()), wxRound(GetScaledHeight())); }
#if wxUSE_IMAGE #if wxUSE_IMAGE
virtual wxImage ConvertToImage() const = 0; virtual wxImage ConvertToImage() const = 0;

View File

@@ -158,8 +158,7 @@ public:
virtual bool Create(int width, int height, const wxDC& dc); virtual bool Create(int width, int height, const wxDC& dc);
virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1); virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
virtual bool CreateScaled(int w, int h, int d, double logicalScale) virtual bool CreateScaled(int w, int h, int d, double logicalScale);
{ return Create(wxRound(w*logicalScale), wxRound(h*logicalScale), d); }
virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE); virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
@@ -185,12 +184,12 @@ public:
void UseAlpha(bool use = true); void UseAlpha(bool use = true);
void ResetAlpha() { UseAlpha(false); } void ResetAlpha() { UseAlpha(false); }
// support for scaled bitmaps // provide stabs of scaled bitmaps functions, they are trivial here
virtual void SetScaleFactor(double WXUNUSED(scale)) { } virtual void SetScaleFactor(double scale);
virtual double GetScaleFactor() const { return 1.0; } virtual double GetScaleFactor() const;
virtual double GetScaledWidth() const { return GetWidth(); } virtual double GetScaledWidth() const;
virtual double GetScaledHeight() const { return GetHeight(); } virtual double GetScaledHeight() const;
virtual wxSize GetScaledSize() const { return GetSize(); } virtual wxSize GetScaledSize() const;
// implementation only from now on // implementation only from now on
// ------------------------------- // -------------------------------

View File

@@ -196,6 +196,39 @@ public:
wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule); wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule);
// ----------------------------------------------------------------------------
// Trivial implementations of scale-factor related functions
// ----------------------------------------------------------------------------
bool wxBitmapBase::CreateScaled(int w, int h, int d, double logicalScale)
{
return Create(wxRound(w*logicalScale), wxRound(h*logicalScale), d);
}
void wxBitmapBase::SetScaleFactor(double WXUNUSED(scale))
{
}
double wxBitmapBase::GetScaleFactor() const
{
return 1.0;
}
double wxBitmapBase::GetScaledWidth() const
{
return GetWidth() / GetScaleFactor();
}
double wxBitmapBase::GetScaledHeight() const
{
return GetHeight() / GetScaleFactor();
}
wxSize wxBitmapBase::GetScaledSize() const
{
return wxSize(wxRound(GetScaledWidth()), wxRound(GetScaledHeight()));
}
#endif // wxUSE_BITMAP_BASE #endif // wxUSE_BITMAP_BASE
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -745,6 +745,11 @@ bool wxBitmap::Create(int width, int height, const wxDC& dc)
return false; return false;
} }
bool wxBitmap::CreateScaled(int w, int h, int d, double logicalScale)
{
return Create(wxRound(w*logicalScale), wxRound(h*logicalScale), d);
}
bool wxBitmap::DoCreate(int w, int h, int d, WXHDC hdc) bool wxBitmap::DoCreate(int w, int h, int d, WXHDC hdc)
{ {
UnRef(); UnRef();
@@ -1357,6 +1362,39 @@ bool wxBitmap::InitFromHBITMAP(WXHBITMAP bmp, int width, int height, int depth)
return IsOk(); return IsOk();
} }
// ----------------------------------------------------------------------------
// scale factor-related functions
// ----------------------------------------------------------------------------
// Note: currently we don't use scale factor at all and don't even store it
// because this seems useless, but we define these functions out of line here
// and not inline in the header to make it possible to change this later
// without breaking ABI if necessary.
void wxBitmap::SetScaleFactor(double WXUNUSED(scale))
{
}
double wxBitmap::GetScaleFactor() const
{
return 1.0;
}
double wxBitmap::GetScaledWidth() const
{
return GetWidth();
}
double wxBitmap::GetScaledHeight() const
{
return GetHeight();
}
wxSize wxBitmap::GetScaledSize() const
{
return GetSize();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// raw bitmap access support // raw bitmap access support
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------