base: Add serialization support to Pixels and FrameBuffer
authorAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 7 Jul 2015 08:51:04 +0000 (09:51 +0100)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 7 Jul 2015 08:51:04 +0000 (09:51 +0100)
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().

src/base/framebuffer.cc
src/base/framebuffer.hh
src/sim/serialize.cc

index dc4c2e1c2c780251cbed774782258e4998f305bb..73f7248926c0c84bf0c480dad56477797468e04b 100644 (file)
@@ -122,6 +122,23 @@ FrameBuffer::~FrameBuffer()
 {
 }
 
+
+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)
 {
index 457c6d06de9d0c2d2461cd2a35ccfbe37a2a6058..eaac2511129a524eba5e790671cdcd68e265b95f 100644 (file)
 #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 @@ operator==(const Pixel &lhs, const Pixel &rhs)
         lhs.padding == rhs.padding;
 }
 
-
 /**
  * Configurable RGB pixel converter.
  *
@@ -208,6 +212,24 @@ class PixelConverter
     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 @@ class PixelConverter
  * 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 @@ class FrameBuffer
 
     virtual ~FrameBuffer();
 
+    void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+    void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
+
     /**
      * Resize the frame buffer.
      *
index a7c1834cfd960087e3ea558daf7810f6f5c3400b..b74b4bc9d01f6e591ae9fcd21b4c872baccb7541 100644 (file)
@@ -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(bool)
 INSTANTIATE_PARAM_TEMPLATES(float)
 INSTANTIATE_PARAM_TEMPLATES(double)
 INSTANTIATE_PARAM_TEMPLATES(string)
+INSTANTIATE_PARAM_TEMPLATES(Pixel)
 
 
 /////////////////////////////