Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
bce9f685
Commit
bce9f685
authored
May 13, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Cairo issues and some possible memory leaks
parent
e8f33ac9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
31 deletions
+49
-31
cairo_gal.cpp
common/gal/cairo/cairo_gal.cpp
+38
-15
opengl_gal.cpp
common/gal/opengl/opengl_gal.cpp
+3
-7
view.cpp
common/view/view.cpp
+1
-7
cairo_gal.h
include/gal/cairo/cairo_gal.h
+7
-2
No files found.
common/gal/cairo/cairo_gal.cpp
View file @
bce9f685
...
@@ -40,7 +40,7 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
...
@@ -40,7 +40,7 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
// Default values
// Default values
fillColor
=
COLOR4D
(
0
,
0
,
0
,
1
);
fillColor
=
COLOR4D
(
0
,
0
,
0
,
1
);
strokeColor
=
COLOR4D
(
1
,
1
,
1
,
1
);
strokeColor
=
COLOR4D
(
1
,
1
,
1
,
1
);
screenSize
=
VECTOR2D
(
20
,
20
);
// window will be soon resized
screenSize
=
VECTOR2D
(
aParent
->
GetSize
()
);
parentWindow
=
aParent
;
parentWindow
=
aParent
;
mouseListener
=
aMouseListener
;
mouseListener
=
aMouseListener
;
...
@@ -101,7 +101,11 @@ CAIRO_GAL::~CAIRO_GAL()
...
@@ -101,7 +101,11 @@ CAIRO_GAL::~CAIRO_GAL()
delete
cursorPixels
;
delete
cursorPixels
;
delete
cursorPixelsSaved
;
delete
cursorPixelsSaved
;
// TODO Deleting of list contents like groups and paths
for
(
int
i
=
groups
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
DeleteGroup
(
i
);
}
deleteBitmaps
();
deleteBitmaps
();
}
}
...
@@ -133,7 +137,7 @@ void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent )
...
@@ -133,7 +137,7 @@ void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent )
}
}
void
CAIRO_GAL
::
BeginDrawing
()
throw
(
int
)
void
CAIRO_GAL
::
initSurface
(
)
{
{
// The size of the client area needs to be greater than zero
// The size of the client area needs to be greater than zero
clientRectangle
=
parentWindow
->
GetClientRect
();
clientRectangle
=
parentWindow
->
GetClientRect
();
...
@@ -141,13 +145,15 @@ void CAIRO_GAL::BeginDrawing() throw( int )
...
@@ -141,13 +145,15 @@ void CAIRO_GAL::BeginDrawing() throw( int )
if
(
clientRectangle
.
width
==
0
||
clientRectangle
.
height
==
0
)
if
(
clientRectangle
.
width
==
0
||
clientRectangle
.
height
==
0
)
throw
EXCEPTION_ZERO_CLIENT_RECTANGLE
;
throw
EXCEPTION_ZERO_CLIENT_RECTANGLE
;
// clientDC = new wxClientDC( this );
// Create the Cairo surface
// Create the CAIRO surface
cairoSurface
=
cairo_image_surface_create_for_data
(
(
unsigned
char
*
)
bitmapBuffer
,
cairoSurface
=
cairo_image_surface_create_for_data
(
(
unsigned
char
*
)
bitmapBuffer
,
CAIRO_FORMAT_RGB24
,
clientRectangle
.
width
,
CAIRO_FORMAT_RGB24
,
clientRectangle
.
width
,
clientRectangle
.
height
,
stride
);
clientRectangle
.
height
,
stride
);
cairoImage
=
cairo_create
(
cairoSurface
);
cairoImage
=
cairo_create
(
cairoSurface
);
#ifdef __WXDEBUG__
cairo_status_t
status
=
cairo_status
(
cairoImage
);
wxASSERT_MSG
(
status
==
CAIRO_STATUS_SUCCESS
,
"Cairo context creation error"
);
#endif
/* __WXDEBUG__ */
// -----------------------------------------------------------------
// -----------------------------------------------------------------
...
@@ -178,6 +184,20 @@ void CAIRO_GAL::BeginDrawing() throw( int )
...
@@ -178,6 +184,20 @@ void CAIRO_GAL::BeginDrawing() throw( int )
lineWidth
=
0
;
lineWidth
=
0
;
isDeleteSavedPixels
=
true
;
isDeleteSavedPixels
=
true
;
}
void
CAIRO_GAL
::
deinitSurface
()
{
// Destroy Cairo objects
cairo_destroy
(
cairoImage
);
cairo_surface_destroy
(
cairoSurface
);
}
void
CAIRO_GAL
::
BeginDrawing
()
throw
(
int
)
{
initSurface
();
cairo_push_group
(
cairoImage
);
cairo_push_group
(
cairoImage
);
}
}
...
@@ -211,9 +231,7 @@ void CAIRO_GAL::EndDrawing()
...
@@ -211,9 +231,7 @@ void CAIRO_GAL::EndDrawing()
wxBufferedDC
dc
;
wxBufferedDC
dc
;
dc
.
Init
(
&
client_dc
,
bmp
);
dc
.
Init
(
&
client_dc
,
bmp
);
// Destroy Cairo objects
deinitSurface
();
cairo_destroy
(
cairoImage
);
cairo_surface_destroy
(
cairoSurface
);
}
}
...
@@ -637,6 +655,8 @@ void CAIRO_GAL::Restore()
...
@@ -637,6 +655,8 @@ void CAIRO_GAL::Restore()
int
CAIRO_GAL
::
BeginGroup
()
int
CAIRO_GAL
::
BeginGroup
()
{
{
initSurface
();
// If the grouping is started: the actual path is stored in the group, when
// If the grouping is started: the actual path is stored in the group, when
// a attribute was changed or when grouping stops with the end group method.
// a attribute was changed or when grouping stops with the end group method.
storePath
();
storePath
();
...
@@ -651,6 +671,8 @@ void CAIRO_GAL::EndGroup()
...
@@ -651,6 +671,8 @@ void CAIRO_GAL::EndGroup()
{
{
storePath
();
storePath
();
isGrouping
=
false
;
isGrouping
=
false
;
deinitSurface
();
}
}
...
@@ -659,11 +681,12 @@ void CAIRO_GAL::DeleteGroup( int aGroupNumber )
...
@@ -659,11 +681,12 @@ void CAIRO_GAL::DeleteGroup( int aGroupNumber )
storePath
();
storePath
();
// Delete the Cairo paths
// Delete the Cairo paths
for
(
std
::
deque
<
GroupElement
>::
iterator
it
=
groups
[
aGroupNumber
].
begin
();
for
(
std
::
deque
<
GroupElement
>::
iterator
it
=
groups
[
aGroupNumber
].
begin
()
,
end
=
groups
[
aGroupNumber
].
end
()
;
it
!=
groups
[
aGroupNumber
].
end
()
;
++
it
)
it
!=
end
;
++
it
)
{
{
if
(
it
->
command
==
CMD_FILL_PATH
||
it
->
command
==
CMD_STROKE_PATH
)
if
(
it
->
command
==
CMD_FILL_PATH
||
it
->
command
==
CMD_STROKE_PATH
)
{
{
if
(
it
->
cairoPath
->
status
==
CAIRO_STATUS_SUCCESS
)
cairo_path_destroy
(
it
->
cairoPath
);
cairo_path_destroy
(
it
->
cairoPath
);
}
}
}
}
...
@@ -817,7 +840,7 @@ void CAIRO_GAL::storePath()
...
@@ -817,7 +840,7 @@ void CAIRO_GAL::storePath()
// add this command to the group list;
// add this command to the group list;
cairo_path_t
*
path
=
cairo_copy_path
(
cairoImage
);
cairo_path_t
*
path
=
cairo_copy_path
(
cairoImage
);
pathList
.
push_back
(
path
);
// pathList.push_back( path ); // FIXME: it's not used anywhere else?
if
(
isStrokeEnabled
)
if
(
isStrokeEnabled
)
{
{
...
@@ -924,7 +947,7 @@ void CAIRO_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP
...
@@ -924,7 +947,7 @@ void CAIRO_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP
void
CAIRO_GAL
::
allocateBitmaps
()
void
CAIRO_GAL
::
allocateBitmaps
()
{
{
// Create buffer, use the system independent C
AIRO image back
end
// Create buffer, use the system independent C
airo image back
end
stride
=
cairo_format_stride_for_width
(
CAIRO_FORMAT_RGB24
,
screenSize
.
x
);
stride
=
cairo_format_stride_for_width
(
CAIRO_FORMAT_RGB24
,
screenSize
.
x
);
bufferSize
=
stride
*
screenSize
.
y
;
bufferSize
=
stride
*
screenSize
.
y
;
...
...
common/gal/opengl/opengl_gal.cpp
View file @
bce9f685
...
@@ -1488,19 +1488,15 @@ void OPENGL_GAL::EndGroup()
...
@@ -1488,19 +1488,15 @@ void OPENGL_GAL::EndGroup()
void
OPENGL_GAL
::
DeleteGroup
(
int
aGroupNumber
)
void
OPENGL_GAL
::
DeleteGroup
(
int
aGroupNumber
)
{
{
if
(
aGroupNumber
>=
vboItems
.
size
()
)
wxASSERT_MSG
(
aGroupNumber
<
vboItems
.
size
(),
{
"OPENGL_GAL: Tried to delete not existing group"
);
// This should not happen
wxLogDebug
(
wxT
(
"Tried to delete not existing group"
)
);
return
;
}
std
::
deque
<
VBO_ITEM
*>::
iterator
it
=
vboItems
.
begin
();
std
::
deque
<
VBO_ITEM
*>::
iterator
it
=
vboItems
.
begin
();
std
::
advance
(
it
,
aGroupNumber
);
std
::
advance
(
it
,
aGroupNumber
);
//vboSize -= it->GetSize(); // FIXME?
//vboSize -= it->GetSize(); // FIXME?
delete
*
it
;
delete
*
it
;
//vboItems.erase( it );
//vboItems.erase( it );
// makes change to group numbers - that's veeery bad
vboNeedsUpdate
=
true
;
vboNeedsUpdate
=
true
;
}
}
...
...
common/view/view.cpp
View file @
bce9f685
...
@@ -469,8 +469,8 @@ struct VIEW::recacheItem
...
@@ -469,8 +469,8 @@ struct VIEW::recacheItem
if
(
immediately
)
if
(
immediately
)
{
{
int
group
=
gal
->
BeginGroup
();
int
group
=
gal
->
BeginGroup
();
view
->
m_painter
->
Draw
(
static_cast
<
EDA_ITEM
*>
(
aItem
),
layer
);
aItem
->
setGroup
(
layer
,
group
);
aItem
->
setGroup
(
layer
,
group
);
view
->
m_painter
->
Draw
(
static_cast
<
EDA_ITEM
*>
(
aItem
),
layer
);
gal
->
EndGroup
();
gal
->
EndGroup
();
}
}
else
else
...
@@ -603,9 +603,6 @@ void VIEW::RecacheAllItems( bool aImmediately )
...
@@ -603,9 +603,6 @@ void VIEW::RecacheAllItems( bool aImmediately )
r
.
SetMaximum
();
r
.
SetMaximum
();
//if( aImmediately )
m_gal
->
BeginDrawing
();
wxLogDebug
(
wxT
(
"RecacheAllItems::immediately: %u"
),
aImmediately
);
wxLogDebug
(
wxT
(
"RecacheAllItems::immediately: %u"
),
aImmediately
);
for
(
LayerMapIter
i
=
m_layers
.
begin
();
i
!=
m_layers
.
end
();
++
i
)
for
(
LayerMapIter
i
=
m_layers
.
begin
();
i
!=
m_layers
.
end
();
++
i
)
...
@@ -614,7 +611,4 @@ void VIEW::RecacheAllItems( bool aImmediately )
...
@@ -614,7 +611,4 @@ void VIEW::RecacheAllItems( bool aImmediately )
recacheItem
visitor
(
this
,
m_gal
,
l
->
id
,
aImmediately
);
recacheItem
visitor
(
this
,
m_gal
,
l
->
id
,
aImmediately
);
l
->
items
->
Query
(
r
,
visitor
);
l
->
items
->
Query
(
r
,
visitor
);
}
}
//if( aImmediately )
m_gal
->
EndDrawing
();
}
}
include/gal/cairo/cairo_gal.h
View file @
bce9f685
...
@@ -359,7 +359,6 @@ private:
...
@@ -359,7 +359,6 @@ private:
unsigned
int
*
bitmapBuffer
;
///< Storage of the cairo image
unsigned
int
*
bitmapBuffer
;
///< Storage of the cairo image
unsigned
int
*
bitmapBufferBackup
;
///< Backup storage of the cairo image
unsigned
int
*
bitmapBufferBackup
;
///< Backup storage of the cairo image
int
stride
;
///< Stride value for Cairo
int
stride
;
///< Stride value for Cairo
// wxClientDC* clientDC; ///< Pointer to the clientDC
// Mapping between Cairo and GAL line attributes
// Mapping between Cairo and GAL line attributes
std
::
map
<
LineCap
,
cairo_line_cap_t
>
lineCapMap
;
///< Line cap style mapping
std
::
map
<
LineCap
,
cairo_line_cap_t
>
lineCapMap
;
///< Line cap style mapping
...
@@ -395,6 +394,12 @@ private:
...
@@ -395,6 +394,12 @@ private:
/// Allocate the bitmaps for drawing
/// Allocate the bitmaps for drawing
void
deleteBitmaps
();
void
deleteBitmaps
();
/// Prepare Cairo surfaces for drawing
void
initSurface
();
// Destroy Cairo surfaces when are not needed anymore
void
deinitSurface
();
};
};
}
// namespace KiGfx
}
// namespace KiGfx
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment