[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog backend/render_handler_tri.cpp ...
From: |
Bastiaan Jacques |
Subject: |
[Gnash-commit] gnash ChangeLog backend/render_handler_tri.cpp ... |
Date: |
Fri, 21 Sep 2007 20:18:41 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Bastiaan Jacques <bjacques> 07/09/21 20:18:41
Modified files:
. : ChangeLog
backend : render_handler_tri.cpp render_handler_tri.h
Log message:
* backend/render_handler_tri.{cpp,h}: Don't assume the
elements in a std::vector are stored in contiguous memory.
Whenver that must be true, copy the elements into a new
block of memory. Store mesh_sets in the cache as non-
pointer types, so we get automatic memory management. Use
std::sort rather than qsort on the cache vector.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4370&r2=1.4371
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/render_handler_tri.cpp?cvsroot=gnash&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/render_handler_tri.h?cvsroot=gnash&r1=1.15&r2=1.16
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4370
retrieving revision 1.4371
diff -u -b -r1.4370 -r1.4371
--- ChangeLog 21 Sep 2007 13:40:31 -0000 1.4370
+++ ChangeLog 21 Sep 2007 20:18:39 -0000 1.4371
@@ -1,3 +1,12 @@
+2007-09-21 Bastiaan Jacques <address@hidden>
+
+ * backend/render_handler_tri.{cpp,h}: Don't assume the
+ elements in a std::vector are stored in contiguous memory.
+ Whenver that must be true, copy the elements into a new
+ block of memory. Store mesh_sets in the cache as non-
+ pointer types, so we get automatic memory management. Use
+ std::sort rather than qsort on the cache vector.
+
2007-09-21 Chad Musick <address@hidden>
* libbase/tu_file.h: Add support for reading 64-bit doubles.
Index: backend/render_handler_tri.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/render_handler_tri.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- backend/render_handler_tri.cpp 4 Sep 2007 02:12:55 -0000 1.21
+++ backend/render_handler_tri.cpp 21 Sep 2007 20:18:40 -0000 1.22
@@ -18,7 +18,7 @@
//
//
-/* $Id: render_handler_tri.cpp,v 1.21 2007/09/04 02:12:55 cmusick Exp $ */
+/* $Id: render_handler_tri.cpp,v 1.22 2007/09/21 20:18:40 bjacques Exp $ */
#include "render_handler_tri.h"
@@ -32,33 +32,42 @@
#include "log.h"
+#include <boost/scoped_array.hpp>
+
namespace gnash {
-// helper function for tri_cache_manager
-static int sort_by_decreasing_error(const void* A, const void* B)
+bool SortByDecreasingError(const mesh_set& lhs, const mesh_set& rhs)
+{
+ float ltol = lhs.get_error_tolerance();
+ float rtol = rhs.get_error_tolerance();
+
+ return ltol < rtol;
+}
+
+/// Takes a vector and copies all the values into an array. The array's memory
+/// is guaranteed to be contiguous, unlike the vector's.
+template <typename T>
+void vector_to_array(const std::vector<T>& vec, boost::scoped_array<T>& array)
{
- const mesh_set* a = *(const mesh_set* const *) A;
- const mesh_set* b = *(const mesh_set* const *) B;
- float atol = a->get_error_tolerance();
- float btol = b->get_error_tolerance();
-
- if (atol < btol) {
- return 1;
- } else if (atol > btol) {
- return -1;
- } else {
- return 0;
+ using namespace boost;
+ size_t vec_size = vec.size();
+
+ array.reset(new T[vec_size]);
+
+ for (size_t i = 0; i < vec_size; i++) {
+ array[i] = vec[i];
}
}
+
//------------------------------------------------------------------------------
mesh_set* tri_cache_manager::search_candidate(float max_error) {
for (unsigned int i=0,n=m_cached_meshes.size(); i<n; i++) {
- mesh_set* candidate = m_cached_meshes[i];
- float candidate_etol = candidate->get_error_tolerance();
+ mesh_set& candidate = m_cached_meshes[i];
+ float candidate_etol = candidate.get_error_tolerance();
if (max_error > candidate_etol * 3.0f) {
// Mesh is too high-res; the remaining meshes are higher res,
@@ -68,7 +77,7 @@
if (max_error > candidate_etol) {
// found it!
- return candidate;
+ return &candidate;
}
} // for
@@ -81,7 +90,7 @@
/// Adds a mesh set to the cache.
void tri_cache_manager::add(mesh_set* m) {
- m_cached_meshes.push_back(m);
+ m_cached_meshes.push_back(*m);
sort_and_clean_meshes();
} // add
@@ -91,21 +100,17 @@
void tri_cache_manager::sort_and_clean_meshes() {
// Re-sort.
- if (m_cached_meshes.size() > 0) {
+ if (!m_cached_meshes.size()) {
+ return;
+ }
- qsort(
- &m_cached_meshes[0],
- m_cached_meshes.size(),
- sizeof(m_cached_meshes[0]),
- sort_by_decreasing_error
- );
+ std::sort(m_cached_meshes.begin(), m_cached_meshes.end(),
+ SortByDecreasingError);
// TODO: The cache will grow forever, without any limit. Add code that
// limits the vector to a certain size. The older Gnash implementation
// appears to never have removed unused cache objects!
- }
-
// Sort check omitted!
} // sort_and_clean_meshes
@@ -194,8 +199,11 @@
if (!the_mesh.m_triangle_strip.size()) continue; // nothing to draw
apply_fill_style(the_style, 0, ratio);
- draw_mesh_strip(&the_mesh.m_triangle_strip[0],
- the_mesh.m_triangle_strip.size() / 2);
+
+ boost::scoped_array<int16_t> coords;
+ vector_to_array(the_mesh.m_triangle_strip, coords);
+
+ draw_mesh_strip(coords.get(), the_mesh.m_triangle_strip.size() / 2);
}
// draw outlines
@@ -208,7 +216,10 @@
assert((strip.m_coords.size() & 1) == 0);
apply_line_style(line_styles[style], ratio);
- draw_line_strip(&strip.m_coords[0], strip.m_coords.size() >> 1);
+ boost::scoped_array<int16_t> coords;
+ vector_to_array(strip.m_coords, coords);
+
+ draw_line_strip(coords.get(), strip.m_coords.size() / 2);
}
@@ -341,7 +352,7 @@
def->m_render_cache = new tri_cache_manager;
}
- return (tri_cache_manager*) def->m_render_cache;
+ return static_cast<tri_cache_manager*> (def->m_render_cache);
} // get_cache_of
@@ -364,11 +375,6 @@
tri_cache_manager::~tri_cache_manager()
{
- for (MeshSetList::iterator i=m_cached_meshes.begin(),
e=m_cached_meshes.end();
- i != e; ++i)
- {
- delete *i;
- }
}
Index: backend/render_handler_tri.h
===================================================================
RCS file: /sources/gnash/gnash/backend/render_handler_tri.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- backend/render_handler_tri.h 23 Aug 2007 09:53:03 -0000 1.15
+++ backend/render_handler_tri.h 21 Sep 2007 20:18:41 -0000 1.16
@@ -18,7 +18,7 @@
//
//
-/* $Id: render_handler_tri.h,v 1.15 2007/08/23 09:53:03 udog Exp $ */
+/* $Id: render_handler_tri.h,v 1.16 2007/09/21 20:18:41 bjacques Exp $ */
#ifndef GNASH_RENDER_HANDLER_TRI_H
#define GNASH_RENDER_HANDLER_TRI_H
@@ -57,7 +57,7 @@
///
/// This instance owns the mesh_sets
///
- typedef std::vector <mesh_set*> MeshSetList;
+ typedef std::vector <mesh_set> MeshSetList;
MeshSetList m_cached_meshes;
public:
- [Gnash-commit] gnash ChangeLog backend/render_handler_tri.cpp ...,
Bastiaan Jacques <=