changeset 94d5a1476c5b in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=94d5a1476c5b
description:
        base: Add serialization support to Pixels and FrameBuffer

        Serialize pixels as unsigned 32 bit integers by adding the required
        to_number() and stream operators. This is used by the FrameBuffer,
        which now implements the Serializable interface. Users of frame
        buffers are expected to serialize it into its own section by calling
        serializeSection().

diffstat:

 src/base/framebuffer.cc |  17 +++++++++++++++++
 src/base/framebuffer.hh |  29 +++++++++++++++++++++++++++--
 src/sim/serialize.cc    |   2 ++
 3 files changed, 46 insertions(+), 2 deletions(-)

diffs (116 lines):

diff -r 3ab1d7ed6545 -r 94d5a1476c5b src/base/framebuffer.cc
--- a/src/base/framebuffer.cc   Tue Jul 07 09:51:04 2015 +0100
+++ b/src/base/framebuffer.cc   Tue Jul 07 09:51:04 2015 +0100
@@ -122,6 +122,23 @@
 {
 }
 
+
+void
+FrameBuffer::serialize(CheckpointOut &cp) const
+{
+    SERIALIZE_SCALAR(_width);
+    SERIALIZE_SCALAR(_height);
+    SERIALIZE_CONTAINER(pixels);
+}
+
+void
+FrameBuffer::unserialize(CheckpointIn &cp)
+{
+    UNSERIALIZE_SCALAR(_width);
+    UNSERIALIZE_SCALAR(_height);
+    UNSERIALIZE_CONTAINER(pixels);
+}
+
 void
 FrameBuffer::resize(unsigned width, unsigned height)
 {
diff -r 3ab1d7ed6545 -r 94d5a1476c5b src/base/framebuffer.hh
--- a/src/base/framebuffer.hh   Tue Jul 07 09:51:04 2015 +0100
+++ b/src/base/framebuffer.hh   Tue Jul 07 09:51:04 2015 +0100
@@ -43,9 +43,14 @@
 #include <cmath>
 #include <cstdint>
 
+#include <string>
 #include <vector>
 
+#include "base/compiler.hh"
+#include "base/cprintf.hh"
+#include "base/str.hh"
 #include "base/types.hh"
+#include "sim/serialize.hh"
 
 /**
  * Internal gem5 representation of a Pixel.
@@ -73,7 +78,6 @@
         lhs.padding == rhs.padding;
 }
 
-
 /**
  * Configurable RGB pixel converter.
  *
@@ -208,6 +212,24 @@
     static const PixelConverter rgb565_be;
 };
 
+inline bool
+to_number(const std::string &value, Pixel &retval)
+{
+    uint32_t num;
+    if (!to_number(value, num))
+        return false;
+
+    retval = PixelConverter::rgba8888_le.toPixel(num);
+    return true;
+}
+
+inline std::ostream &
+operator<<(std::ostream &os, const Pixel &pxl)
+{
+    os << csprintf("0x%.08x", PixelConverter::rgba8888_le.fromPixel(pxl));
+    return os;
+}
+
 /**
  * Internal gem5 representation of a frame buffer
  *
@@ -219,7 +241,7 @@
  * corner. The backing store is a linear vector of Pixels ordered left
  * to right starting in the upper left corner.
  */
-class FrameBuffer
+class FrameBuffer : public Serializable
 {
   public:
     /**
@@ -234,6 +256,9 @@
 
     virtual ~FrameBuffer();
 
+    void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+    void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
+
     /**
      * Resize the frame buffer.
      *
diff -r 3ab1d7ed6545 -r 94d5a1476c5b src/sim/serialize.cc
--- a/src/sim/serialize.cc      Tue Jul 07 09:51:04 2015 +0100
+++ b/src/sim/serialize.cc      Tue Jul 07 09:51:04 2015 +0100
@@ -55,6 +55,7 @@
 #include <string>
 #include <vector>
 
+#include "base/framebuffer.hh"
 #include "base/inifile.hh"
 #include "base/misc.hh"
 #include "base/output.hh"
@@ -418,6 +419,7 @@
 INSTANTIATE_PARAM_TEMPLATES(float)
 INSTANTIATE_PARAM_TEMPLATES(double)
 INSTANTIATE_PARAM_TEMPLATES(string)
+INSTANTIATE_PARAM_TEMPLATES(Pixel)
 
 
 /////////////////////////////
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to