Add more initialization checks for wxSTC SurfaceD2D target
Return early if the check fails. No functional changes. This commit is best viewed ignoring whitespace changes. Closes https://github.com/wxWidgets/wxWidgets/pull/1914
This commit is contained in:
committed by
Vadim Zeitlin
parent
a2823983a3
commit
dec895e1d7
@@ -1201,8 +1201,8 @@ static float RoundFloat(float f)
|
|||||||
|
|
||||||
void SurfaceD2D::LineTo(int x_, int y_)
|
void SurfaceD2D::LineTo(int x_, int y_)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
int xDiff = x_ - m_x;
|
int xDiff = x_ - m_x;
|
||||||
int xDelta = Delta(xDiff);
|
int xDelta = Delta(xDiff);
|
||||||
int yDiff = y_ - m_y;
|
int yDiff = y_ - m_y;
|
||||||
@@ -1238,13 +1238,12 @@ void SurfaceD2D::LineTo(int x_, int y_)
|
|||||||
m_x = x_;
|
m_x = x_;
|
||||||
m_y = y_;
|
m_y = y_;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::Polygon(Point *pts, int npts, ColourDesired fore,
|
void SurfaceD2D::Polygon(Point *pts, int npts, ColourDesired fore,
|
||||||
ColourDesired back)
|
ColourDesired back)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
wxCOMPtr<ID2D1Factory> pFactory;
|
wxCOMPtr<ID2D1Factory> pFactory;
|
||||||
wxCOMPtr<ID2D1PathGeometry> geometry;
|
wxCOMPtr<ID2D1PathGeometry> geometry;
|
||||||
wxCOMPtr<ID2D1GeometrySink> sink;
|
wxCOMPtr<ID2D1GeometrySink> sink;
|
||||||
@@ -1274,13 +1273,12 @@ void SurfaceD2D::Polygon(Point *pts, int npts, ColourDesired fore,
|
|||||||
m_pRenderTarget->DrawGeometry(geometry, m_pSolidBrush);
|
m_pRenderTarget->DrawGeometry(geometry, m_pSolidBrush);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::RectangleDraw(PRectangle rc, ColourDesired fore,
|
void SurfaceD2D::RectangleDraw(PRectangle rc, ColourDesired fore,
|
||||||
ColourDesired back)
|
ColourDesired back)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
D2D1_RECT_F rectangle1 = D2D1::RectF(RoundFloat(rc.left) + 0.5f,
|
D2D1_RECT_F rectangle1 = D2D1::RectF(RoundFloat(rc.left) + 0.5f,
|
||||||
rc.top + 0.5f, RoundFloat(rc.right) - 0.5f, rc.bottom - 0.5f);
|
rc.top + 0.5f, RoundFloat(rc.right) - 0.5f, rc.bottom - 0.5f);
|
||||||
D2DPenColour(back);
|
D2DPenColour(back);
|
||||||
@@ -1288,21 +1286,21 @@ void SurfaceD2D::RectangleDraw(PRectangle rc, ColourDesired fore,
|
|||||||
D2DPenColour(fore);
|
D2DPenColour(fore);
|
||||||
m_pRenderTarget->DrawRectangle(&rectangle1, m_pSolidBrush);
|
m_pRenderTarget->DrawRectangle(&rectangle1, m_pSolidBrush);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::FillRectangle(PRectangle rc, ColourDesired back)
|
void SurfaceD2D::FillRectangle(PRectangle rc, ColourDesired back)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
D2DPenColour(back);
|
D2DPenColour(back);
|
||||||
D2D1_RECT_F rectangle1 = D2D1::RectF(RoundFloat(rc.left), rc.top,
|
D2D1_RECT_F rectangle1 = D2D1::RectF(RoundFloat(rc.left), rc.top,
|
||||||
RoundFloat(rc.right), rc.bottom);
|
RoundFloat(rc.right), rc.bottom);
|
||||||
m_pRenderTarget->FillRectangle(&rectangle1, m_pSolidBrush);
|
m_pRenderTarget->FillRectangle(&rectangle1, m_pSolidBrush);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::FillRectangle(PRectangle rc, Surface &surfacePattern)
|
void SurfaceD2D::FillRectangle(PRectangle rc, Surface &surfacePattern)
|
||||||
{
|
{
|
||||||
|
wxCHECK( Initialised(), void() );
|
||||||
|
|
||||||
SurfaceD2D &surfOther = static_cast<SurfaceD2D &>(surfacePattern);
|
SurfaceD2D &surfOther = static_cast<SurfaceD2D &>(surfacePattern);
|
||||||
surfOther.FlushDrawing();
|
surfOther.FlushDrawing();
|
||||||
|
|
||||||
@@ -1342,8 +1340,8 @@ void SurfaceD2D::FillRectangle(PRectangle rc, Surface &surfacePattern)
|
|||||||
void SurfaceD2D::RoundedRectangle(PRectangle rc, ColourDesired fore,
|
void SurfaceD2D::RoundedRectangle(PRectangle rc, ColourDesired fore,
|
||||||
ColourDesired back)
|
ColourDesired back)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
D2D1_ROUNDED_RECT roundedRectFill = {
|
D2D1_ROUNDED_RECT roundedRectFill = {
|
||||||
D2D1::RectF(rc.left + 1.0f, rc.top + 1.0f, rc.right - 1.0f, rc.bottom - 1.0f),
|
D2D1::RectF(rc.left + 1.0f, rc.top + 1.0f, rc.right - 1.0f, rc.bottom - 1.0f),
|
||||||
4, 4 };
|
4, 4 };
|
||||||
@@ -1356,15 +1354,14 @@ void SurfaceD2D::RoundedRectangle(PRectangle rc, ColourDesired fore,
|
|||||||
D2DPenColour(fore);
|
D2DPenColour(fore);
|
||||||
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pSolidBrush);
|
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pSolidBrush);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::AlphaRectangle(PRectangle rc, int cornerSize,
|
void SurfaceD2D::AlphaRectangle(PRectangle rc, int cornerSize,
|
||||||
ColourDesired fill, int alphaFill,
|
ColourDesired fill, int alphaFill,
|
||||||
ColourDesired outline, int alphaOutline,
|
ColourDesired outline, int alphaOutline,
|
||||||
int /* flags*/ )
|
int /* flags*/ )
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
if ( cornerSize == 0 )
|
if ( cornerSize == 0 )
|
||||||
{
|
{
|
||||||
// When corner size is zero, draw square rectangle to prevent
|
// When corner size is zero, draw square rectangle to prevent
|
||||||
@@ -1397,13 +1394,12 @@ void SurfaceD2D::AlphaRectangle(PRectangle rc, int cornerSize,
|
|||||||
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pSolidBrush);
|
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pSolidBrush);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::DrawRGBAImage(PRectangle rc, int width, int height,
|
void SurfaceD2D::DrawRGBAImage(PRectangle rc, int width, int height,
|
||||||
const unsigned char *pixelsImage)
|
const unsigned char *pixelsImage)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
if ( rc.Width() > width )
|
if ( rc.Width() > width )
|
||||||
rc.left += static_cast<int>((rc.Width() - width) / 2);
|
rc.left += static_cast<int>((rc.Width() - width) / 2);
|
||||||
rc.right = rc.left + width;
|
rc.right = rc.left + width;
|
||||||
@@ -1439,12 +1435,11 @@ void SurfaceD2D::DrawRGBAImage(PRectangle rc, int width, int height,
|
|||||||
m_pRenderTarget->DrawBitmap(bitmap, rcDestination);
|
m_pRenderTarget->DrawBitmap(bitmap, rcDestination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)
|
void SurfaceD2D::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
FLOAT radius = rc.Width() / 2.0f;
|
FLOAT radius = rc.Width() / 2.0f;
|
||||||
D2D1_ELLIPSE ellipse = {
|
D2D1_ELLIPSE ellipse = {
|
||||||
D2D1::Point2F((rc.left + rc.right) / 2.0f,
|
D2D1::Point2F((rc.left + rc.right) / 2.0f,
|
||||||
@@ -1456,9 +1451,11 @@ void SurfaceD2D::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)
|
|||||||
PenColour(fore);
|
PenColour(fore);
|
||||||
m_pRenderTarget->DrawEllipse(ellipse, m_pSolidBrush);
|
m_pRenderTarget->DrawEllipse(ellipse, m_pSolidBrush);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::Copy(PRectangle rc, Point from, Surface &surfaceSource) {
|
void SurfaceD2D::Copy(PRectangle rc, Point from, Surface& surfaceSource)
|
||||||
|
{
|
||||||
|
wxCHECK( Initialised(), void() );
|
||||||
|
|
||||||
SurfaceD2D& surfOther = static_cast<SurfaceD2D&>(surfaceSource);
|
SurfaceD2D& surfOther = static_cast<SurfaceD2D&>(surfaceSource);
|
||||||
surfOther.FlushDrawing();
|
surfOther.FlushDrawing();
|
||||||
|
|
||||||
@@ -1488,40 +1485,37 @@ void SurfaceD2D::DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase,
|
|||||||
const char *s, int len, ColourDesired fore,
|
const char *s, int len, ColourDesired fore,
|
||||||
ColourDesired back)
|
ColourDesired back)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
FillRectangle(rc, back);
|
FillRectangle(rc, back);
|
||||||
D2DPenColour(fore);
|
D2DPenColour(fore);
|
||||||
DrawTextCommon(rc, font_, ybase, s, len, ETO_OPAQUE);
|
DrawTextCommon(rc, font_, ybase, s, len, ETO_OPAQUE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase,
|
void SurfaceD2D::DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase,
|
||||||
const char *s, int len, ColourDesired fore,
|
const char *s, int len, ColourDesired fore,
|
||||||
ColourDesired back)
|
ColourDesired back)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
FillRectangle(rc, back);
|
FillRectangle(rc, back);
|
||||||
D2DPenColour(fore);
|
D2DPenColour(fore);
|
||||||
DrawTextCommon(rc, font_, ybase, s, len, ETO_OPAQUE | ETO_CLIPPED);
|
DrawTextCommon(rc, font_, ybase, s, len, ETO_OPAQUE | ETO_CLIPPED);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::DrawTextTransparent(PRectangle rc, Font &font_,
|
void SurfaceD2D::DrawTextTransparent(PRectangle rc, Font &font_,
|
||||||
XYPOSITION ybase, const char *s, int len,
|
XYPOSITION ybase, const char *s, int len,
|
||||||
ColourDesired fore)
|
ColourDesired fore)
|
||||||
{
|
{
|
||||||
|
wxCHECK( Initialised(), void() );
|
||||||
|
|
||||||
// Avoid drawing spaces in transparent mode
|
// Avoid drawing spaces in transparent mode
|
||||||
for ( int i=0; i<len; i++ )
|
for ( int i=0; i<len; i++ )
|
||||||
{
|
{
|
||||||
if ( s[i] != ' ' )
|
if ( s[i] != ' ' )
|
||||||
{
|
|
||||||
if ( m_pRenderTarget.get() )
|
|
||||||
{
|
{
|
||||||
D2DPenColour(fore);
|
D2DPenColour(fore);
|
||||||
DrawTextCommon(rc, font_, ybase, s, len, 0);
|
DrawTextCommon(rc, font_, ybase, s, len, 0);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1708,13 +1702,12 @@ XYPOSITION SurfaceD2D::AverageCharWidth(Font &font_)
|
|||||||
|
|
||||||
void SurfaceD2D::SetClip(PRectangle rc)
|
void SurfaceD2D::SetClip(PRectangle rc)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
D2D1_RECT_F rcClip = { rc.left, rc.top, rc.right, rc.bottom };
|
D2D1_RECT_F rcClip = { rc.left, rc.top, rc.right, rc.bottom };
|
||||||
m_pRenderTarget->PushAxisAlignedClip(rcClip, D2D1_ANTIALIAS_MODE_ALIASED);
|
m_pRenderTarget->PushAxisAlignedClip(rcClip, D2D1_ANTIALIAS_MODE_ALIASED);
|
||||||
m_clipsActive++;
|
m_clipsActive++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::FlushCachedState()
|
void SurfaceD2D::FlushCachedState()
|
||||||
{
|
{
|
||||||
@@ -1747,7 +1740,7 @@ void SurfaceD2D::SetFont(Font &font_)
|
|||||||
m_yInternalLeading = sfd->GetInternalLeading();
|
m_yInternalLeading = sfd->GetInternalLeading();
|
||||||
m_averageCharWidth = sfd->GetAverageCharWidth();
|
m_averageCharWidth = sfd->GetAverageCharWidth();
|
||||||
|
|
||||||
if ( m_pRenderTarget.get() )
|
if ( Initialised() )
|
||||||
{
|
{
|
||||||
D2D1_TEXT_ANTIALIAS_MODE aaMode = sfd->GetFontQuality();
|
D2D1_TEXT_ANTIALIAS_MODE aaMode = sfd->GetFontQuality();
|
||||||
|
|
||||||
@@ -1775,13 +1768,14 @@ void SurfaceD2D::SetFont(Font &font_)
|
|||||||
|
|
||||||
HRESULT SurfaceD2D::FlushDrawing()
|
HRESULT SurfaceD2D::FlushDrawing()
|
||||||
{
|
{
|
||||||
|
wxCHECK( Initialised(), E_POINTER );
|
||||||
return m_pRenderTarget->Flush();
|
return m_pRenderTarget->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SurfaceD2D::D2DPenColour(ColourDesired fore, int alpha)
|
void SurfaceD2D::D2DPenColour(ColourDesired fore, int alpha)
|
||||||
{
|
{
|
||||||
if ( m_pRenderTarget.get() )
|
wxCHECK( Initialised(), void() );
|
||||||
{
|
|
||||||
D2D_COLOR_F col;
|
D2D_COLOR_F col;
|
||||||
col.r = (fore.AsLong() & 0xff) / 255.0f;
|
col.r = (fore.AsLong() & 0xff) / 255.0f;
|
||||||
col.g = ((fore.AsLong() & 0xff00) >> 8) / 255.0f;
|
col.g = ((fore.AsLong() & 0xff00) >> 8) / 255.0f;
|
||||||
@@ -1800,14 +1794,15 @@ void SurfaceD2D::D2DPenColour(ColourDesired fore, int alpha)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SurfaceD2D::DrawTextCommon(PRectangle rc, Font &font_, XYPOSITION ybase,
|
void SurfaceD2D::DrawTextCommon(PRectangle rc, Font &font_, XYPOSITION ybase,
|
||||||
const char *s, int len, UINT fuOptions)
|
const char *s, int len, UINT fuOptions)
|
||||||
{
|
{
|
||||||
|
wxCHECK( Initialised(), void() );
|
||||||
|
|
||||||
SetFont(font_);
|
SetFont(font_);
|
||||||
|
|
||||||
if ( m_pRenderTarget.get() && m_pSolidBrush.get() && m_pTextFormat.get() )
|
if ( m_pSolidBrush.get() && m_pTextFormat.get() )
|
||||||
{
|
{
|
||||||
// Explicitly creating a text layout appears a little faster
|
// Explicitly creating a text layout appears a little faster
|
||||||
wxCOMPtr<IDWriteTextLayout> pTextLayout;
|
wxCOMPtr<IDWriteTextLayout> pTextLayout;
|
||||||
|
Reference in New Issue
Block a user