# -*- mode:python -*-
-# Copyright (c) 2013, 2015, 2016 ARM Limited
+# Copyright (c) 2013, 2015-2017 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
print "Warning: Header file <fenv.h> not found."
print " This host has no IEEE FP rounding mode control."
+# Check for <png.h> (libpng library needed if wanting to dump
+# frame buffer image in png format)
+have_png = conf.CheckHeader('png.h', '<>')
+if not have_png:
+ print "Warning: Header file <png.h> not found."
+ print " This host has no libpng library."
+ print " Disabling support for PNG framebuffers."
+
# Check if we should enable KVM-based hardware virtualization. The API
# we rely on exists since version 2.6.36 of the kernel, but somehow
# the KVM_API_VERSION does not reflect the change. We test for one of
False),
BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
- BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
- BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm),
+ BoolVariable('USE_PNG', 'Enable support for PNG images', have_png),
+ BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability',
+ False),
+ BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models',
+ have_kvm),
BoolVariable('USE_TUNTAP',
'Enable using a tap device to bridge to the host network',
have_tuntap),
# These variables get exported to #defines in config/*.hh (see src/SConscript).
export_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA',
'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP',
- 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_PERF_ATTR_EXCLUDE_HOST']
+ 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_PERF_ATTR_EXCLUDE_HOST',
+ 'USE_PNG']
###################################################
#
print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
print " FP results may deviate slightly from other platforms."
+ if not have_png and env['USE_PNG']:
+ print "Warning: <png.h> not available; " \
+ "forcing USE_PNG to False in", variant_dir + "."
+ env['USE_PNG'] = False
+
+ if env['USE_PNG']:
+ env.Append(LIBS=['png'])
+
if env['EFENCE']:
env.Append(LIBS=['efence'])
--- /dev/null
+# Copyright (c) 2017 ARM Limited
+# All rights reserved
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Giacomo Travaglini
+
+from m5.SimObject import SimObject
+from m5.params import *
+
+# Image Formats:
+# Auto option will let gem5 to choose the image format it prefers.
+class ImageFormat(Enum): vals = ['Auto', 'Bitmap', 'Png']
if env['CP_ANNOTATE']:
SimObject('CPA.py')
Source('cp_annotate.cc')
+SimObject('Graphics.py')
Source('atomicio.cc')
Source('bitfield.cc')
Source('bigint.cc')
-Source('bitmap.cc')
+Source('imgwriter.cc')
+Source('bmpwriter.cc')
Source('callback.cc')
Source('cprintf.cc')
Source('debug.cc')
if env['USE_FENV']:
Source('fenv.c')
+if env['USE_PNG']:
+ Source('pngwriter.cc')
Source('framebuffer.cc')
Source('hostinfo.cc')
Source('inet.cc')
+++ /dev/null
-/*
- * Copyright (c) 2010, 2015 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder. You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: William Wang
- * Ali Saidi
- * Chris Emmons
- * Andreas Sandberg
- */
-
-#include "base/bitmap.hh"
-
-#include <cassert>
-
-#include "base/misc.hh"
-
-// bitmap class ctor
-Bitmap::Bitmap(const FrameBuffer *_fb)
- : fb(*_fb)
-{
-}
-
-Bitmap::~Bitmap()
-{
-}
-
-const Bitmap::CompleteV1Header
-Bitmap::getCompleteHeader() const
-{
- const uint32_t pixel_array_size(sizeof(PixelType) * fb.area());
- const uint32_t file_size(sizeof(CompleteV1Header) + pixel_array_size);
-
- const CompleteV1Header header = {
- // File header
- {
- {'B','M'}, /* Magic */
- file_size,
- 0, 0, /* Reserved */
- sizeof(CompleteV1Header) /* Offset to pixel array */
- },
- // Info/DIB header
- {
- sizeof(InfoHeaderV1),
- fb.width(),
- fb.height(),
- 1, /* Color planes */
- 32, /* Bits per pixel */
- 0, /* No compression */
- pixel_array_size, /* Image size in bytes */
- 2835, /* x pixels per meter (assume 72 DPI) */
- 2835, /* y pixels per meter (assume 72 DPI) */
- 0, /* Colors in color table */
- 0 /* Important color count (0 == all are important) */
- }
- };
-
- return header;
-}
-
-void
-Bitmap::write(std::ostream &bmp) const
-{
- const CompleteV1Header header(getCompleteHeader());
-
- // 1. write the header
- bmp.write(reinterpret_cast<const char *>(&header), sizeof(header));
-
- // 2. write the bitmap data
- // BMP start store data left to right starting with the bottom row
- // so we need to do some creative flipping
- std::vector<PixelType> line_buffer(fb.width());
- for (int y = 0; y < fb.height(); ++y) {
- for (unsigned x = 0; x < fb.width(); ++x)
- line_buffer[x] = fb.pixel(x, fb.height() - y - 1);
-
- bmp.write(reinterpret_cast<const char *>(line_buffer.data()),
- line_buffer.size() * sizeof(line_buffer[0]));
- }
-
- bmp.flush();
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2010, 2015 ARM Limited
- * All rights reserved
- *
- * The license below extends only to copyright in the software and shall
- * not be construed as granting a license to any other intellectual
- * property including but not limited to intellectual property relating
- * to a hardware implementation of the functionality of the software
- * licensed hereunder. You may use the software subject to the license
- * terms below provided that you ensure that this notice is replicated
- * unmodified and in its entirety in all distributions of the software,
- * modified or unmodified, in source code or in binary form.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: William Wang
- * Ali Saidi
- * Chris Emmons
- * Andreas Sandberg
- */
-#ifndef __BASE_BITMAP_HH__
-#define __BASE_BITMAP_HH__
-
-#include <ostream>
-
-#include "base/compiler.hh"
-#include "base/framebuffer.hh"
-
-/**
- * @file Declaration of a class that writes a frame buffer to a bitmap
- */
-
-
-// write frame buffer into a bitmap picture
-class Bitmap
-{
- public:
- /**
- * Create a bitmap that takes data in a given mode & size and
- * outputs to an ostream.
- */
- Bitmap(const FrameBuffer *fb);
-
- ~Bitmap();
-
- /**
- * Write the frame buffer data into the provided ostream
- *
- * @param bmp stream to write to
- */
- void write(std::ostream &bmp) const;
-
-
- private:
- struct FileHeader {
- unsigned char magic_number[2];
- uint32_t size;
- uint16_t reserved1;
- uint16_t reserved2;
- uint32_t offset;
- } M5_ATTR_PACKED;
-
- struct InfoHeaderV1 { /* Aka DIB header */
- uint32_t Size;
- uint32_t Width;
- uint32_t Height;
- uint16_t Planes;
- uint16_t BitCount;
- uint32_t Compression;
- uint32_t SizeImage;
- uint32_t XPelsPerMeter;
- uint32_t YPelsPerMeter;
- uint32_t ClrUsed;
- uint32_t ClrImportant;
- } M5_ATTR_PACKED;
-
- struct CompleteV1Header {
- FileHeader file;
- InfoHeaderV1 info;
- } M5_ATTR_PACKED;
-
- struct BmpPixel32 {
- BmpPixel32 &operator=(const Pixel &rhs) {
- red = rhs.red;
- green = rhs.green;
- blue = rhs.blue;
- padding = 0;
-
- return *this;
- }
- uint8_t blue;
- uint8_t green;
- uint8_t red;
- uint8_t padding;
- } M5_ATTR_PACKED;
-
- typedef BmpPixel32 PixelType;
-
- const CompleteV1Header getCompleteHeader() const;
-
- const FrameBuffer &fb;
-};
-
-#endif // __BASE_BITMAP_HH__
-
--- /dev/null
+/*
+ * Copyright (c) 2010, 2015, 2017 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: William Wang
+ * Ali Saidi
+ * Chris Emmons
+ * Andreas Sandberg
+ */
+
+#include "base/bmpwriter.hh"
+
+#include <cassert>
+
+#include "base/misc.hh"
+
+const char* BmpWriter::_imgExtension = "bmp";
+
+// bitmap class ctor
+BmpWriter::BmpWriter(const FrameBuffer *_fb)
+ : ImgWriter(_fb)
+{
+}
+
+const BmpWriter::CompleteV1Header
+BmpWriter::getCompleteHeader() const
+{
+ const uint32_t pixel_array_size(sizeof(PixelType) * fb.area());
+ const uint32_t file_size(sizeof(CompleteV1Header) + pixel_array_size);
+
+ const CompleteV1Header header = {
+ // File header
+ {
+ {'B','M'}, /* Magic */
+ file_size,
+ 0, 0, /* Reserved */
+ sizeof(CompleteV1Header) /* Offset to pixel array */
+ },
+ // Info/DIB header
+ {
+ sizeof(InfoHeaderV1),
+ fb.width(),
+ fb.height(),
+ 1, /* Color planes */
+ 32, /* Bits per pixel */
+ 0, /* No compression */
+ pixel_array_size, /* Image size in bytes */
+ 2835, /* x pixels per meter (assume 72 DPI) */
+ 2835, /* y pixels per meter (assume 72 DPI) */
+ 0, /* Colors in color table */
+ 0 /* Important color count (0 == all are important) */
+ }
+ };
+
+ return header;
+}
+
+void
+BmpWriter::write(std::ostream &bmp) const
+{
+ const CompleteV1Header header(getCompleteHeader());
+
+ // 1. write the header
+ bmp.write(reinterpret_cast<const char *>(&header), sizeof(header));
+
+ // 2. write the bitmap data
+ // BMP start store data left to right starting with the bottom row
+ // so we need to do some creative flipping
+ std::vector<PixelType> line_buffer(fb.width());
+ for (int y = 0; y < fb.height(); ++y) {
+ for (unsigned x = 0; x < fb.width(); ++x)
+ line_buffer[x] = fb.pixel(x, fb.height() - y - 1);
+
+ bmp.write(reinterpret_cast<const char *>(line_buffer.data()),
+ line_buffer.size() * sizeof(line_buffer[0]));
+ }
+
+ bmp.flush();
+}
+
+
--- /dev/null
+/*
+ * Copyright (c) 2010, 2015, 2017 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: William Wang
+ * Ali Saidi
+ * Chris Emmons
+ * Andreas Sandberg
+ */
+#ifndef __BASE_BITMAP_HH__
+#define __BASE_BITMAP_HH__
+
+#include <ostream>
+
+#include "base/compiler.hh"
+#include "base/framebuffer.hh"
+#include "base/imgwriter.hh"
+
+/**
+ * @file Declaration of a class that writes a frame buffer to a bitmap
+ */
+
+// write frame buffer into a bitmap picture
+class BmpWriter : public ImgWriter
+{
+ public:
+ /**
+ * Create a bitmap that takes data in a given mode & size and
+ * outputs to an ostream.
+ */
+ BmpWriter(const FrameBuffer *fb);
+
+ ~BmpWriter() {};
+
+ /*
+ * Return Image format as a string
+ *
+ * @return img extension (e.g. bmp for Bitmap)
+ */
+ const char* getImgExtension() const override
+ { return _imgExtension; }
+
+ /**
+ * Write the frame buffer data into the provided ostream
+ *
+ * @param bmp stream to write to
+ */
+ void write(std::ostream &bmp) const override;
+
+ private:
+ struct FileHeader {
+ unsigned char magic_number[2];
+ uint32_t size;
+ uint16_t reserved1;
+ uint16_t reserved2;
+ uint32_t offset;
+ } M5_ATTR_PACKED;
+
+ struct InfoHeaderV1 { /* Aka DIB header */
+ uint32_t Size;
+ uint32_t Width;
+ uint32_t Height;
+ uint16_t Planes;
+ uint16_t BitCount;
+ uint32_t Compression;
+ uint32_t SizeImage;
+ uint32_t XPelsPerMeter;
+ uint32_t YPelsPerMeter;
+ uint32_t ClrUsed;
+ uint32_t ClrImportant;
+ } M5_ATTR_PACKED;
+
+ struct CompleteV1Header {
+ FileHeader file;
+ InfoHeaderV1 info;
+ } M5_ATTR_PACKED;
+
+ struct BmpPixel32 {
+ BmpPixel32 &operator=(const Pixel &rhs) {
+ red = rhs.red;
+ green = rhs.green;
+ blue = rhs.blue;
+ padding = 0;
+
+ return *this;
+ }
+ uint8_t blue;
+ uint8_t green;
+ uint8_t red;
+ uint8_t padding;
+ } M5_ATTR_PACKED;
+
+ typedef BmpPixel32 PixelType;
+
+ static const char* _imgExtension;
+
+ const CompleteV1Header getCompleteHeader() const;
+};
+
+
+#endif // __BASE_BITMAP_HH__
+
--- /dev/null
+/*
+ * Copyright (c) 2017 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Giacomo Travaglini
+ */
+
+#include "base/imgwriter.hh"
+#include "base/bmpwriter.hh"
+#include "base/misc.hh"
+
+#include "config/use_png.hh"
+
+#if USE_PNG
+#include "base/pngwriter.hh"
+#endif
+
+std::unique_ptr<ImgWriter>
+createImgWriter(Enums::ImageFormat type, const FrameBuffer *fb)
+{
+ switch (type) {
+ case Enums::Auto:
+ // The Auto option allows gem5 to choose automatically the
+ // writer type, and it will choose for the best fit in
+ // performance.
+ // gem5 will try PNG first, and it will fallback to BMP if not
+ // available.
+
+ /* FALLTHROUGH */
+#if USE_PNG
+ case Enums::Png:
+ return std::unique_ptr<PngWriter>(new PngWriter(fb));
+#endif
+ case Enums::Bitmap:
+ return std::unique_ptr<BmpWriter>(new BmpWriter(fb));
+ default:
+ warn("Invalid Image Type specified, defaulting to Bitmap\n");
+ return std::unique_ptr<BmpWriter>(new BmpWriter(fb));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Giacomo Travaglini
+ */
+#ifndef __BASE_IMGWRITER_HH__
+#define __BASE_IMGWRITER_HH__
+
+#include <ostream>
+
+#include "base/compiler.hh"
+#include "base/framebuffer.hh"
+
+#include "enums/ImageFormat.hh"
+
+// write frame buffer to an image
+class ImgWriter
+{
+ public:
+ ImgWriter(const FrameBuffer *_fb)
+ : fb(*_fb)
+ {}
+
+ virtual ~ImgWriter() {};
+ /**
+ * Write the frame buffer data into the provided ostream
+ *
+ * @param out output stream to write to
+ */
+ virtual void write(std::ostream &out) const = 0;
+ /*
+ * Return Image format as a string
+ *
+ * @return img extension (e.g. bmp for Bitmap)
+ */
+ virtual const char* getImgExtension() const = 0;
+
+ protected:
+ const FrameBuffer &fb;
+};
+
+/**
+ * Factory Function which allocates a ImgWriter object and returns
+ * a smart pointer to it. The dynamic type of the object being pointed
+ * depends upon the enum type passed as a first parameter.
+ * If the enum contains an invalid value, the function will produce a warning
+ * and will default to Bitamp.
+ *
+ * @param type Image writer type (e.g. Bitamp, Png)
+ * @param fb Pointer to a FrameBuffer object
+ * This contains the raw data which will be stored as an image
+ * when calling the appropriate object method
+ * @return smart pointer to the allocated Image Writer
+ */
+std::unique_ptr<ImgWriter>
+createImgWriter(Enums::ImageFormat type, const FrameBuffer *fb);
+
+#endif //__BASE_IMGWRITER_HH__
--- /dev/null
+/*
+ * Copyright (c) 2017 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Giacomo Travaglini
+ */
+
+/**
+ * @file Definition of a class that writes a frame buffer to a png
+ */
+
+#include "base/pngwriter.hh"
+
+extern "C"
+{
+#include <png.h>
+}
+
+#include <cstdio>
+#include <cstdlib>
+
+#include "base/misc.hh"
+
+const char* PngWriter::_imgExtension = "png";
+
+/**
+ * Write callback to use with libpng APIs
+ *
+ * @param pngPtr pointer to the png_struct structure
+ * @param data pointer to the data being written
+ * @param length number of bytes being written
+ */
+static void
+writePng(png_structp pngPtr, png_bytep data, png_size_t length)
+{
+ // Here we get our IO pointer back from the write struct
+ // and we cast it into a ostream* type.
+ std::ostream* strmPtr = reinterpret_cast<std::ostream*>(
+ png_get_io_ptr(pngPtr)
+ );
+
+ // Write length bytes to data
+ strmPtr->write(reinterpret_cast<const char *>(data), length);
+}
+
+struct PngWriter::PngStructHandle {
+ private:
+ // Make PngStructHandle uncopyable
+ PngStructHandle(const PngStructHandle&) = delete;
+ PngStructHandle& operator=(const PngStructHandle&) = delete;
+ public:
+
+ PngStructHandle() :
+ pngWriteP(NULL), pngInfoP(NULL)
+ {
+ // Creating write structure
+ pngWriteP = png_create_write_struct(
+ PNG_LIBPNG_VER_STRING, NULL, NULL, NULL
+ );
+
+ if (pngWriteP) {
+ // Creating info structure
+ pngInfoP = png_create_info_struct(pngWriteP);
+ }
+ }
+
+ ~PngStructHandle()
+ {
+ if (pngWriteP) {
+ png_destroy_write_struct(&pngWriteP, &pngInfoP);
+ }
+ }
+
+ /** Pointer to PNG Write struct */
+ png_structp pngWriteP;
+
+ /** Pointer to PNG Info struct */
+ png_infop pngInfoP;
+};
+
+void
+PngWriter::write(std::ostream &png) const
+{
+
+ // Height of the frame buffer
+ unsigned height = fb.height();
+ unsigned width = fb.width();
+
+ // Do not write if frame buffer is empty
+ if (!fb.area()) {
+ png.flush();
+ return;
+ }
+
+ // Initialize Png structures
+ PngStructHandle handle;
+
+ // Png info/write pointers.
+ png_structp pngPtr = handle.pngWriteP;
+ png_infop infoPtr = handle.pngInfoP;
+
+ if (!pngPtr) {
+ warn("Frame buffer dump aborted: Unable to create"
+ "Png Write Struct\n");
+ return;
+ }
+
+ if (!infoPtr) {
+ warn("Frame buffer dump aborted: Unable to create"
+ "Png Info Struct\n");
+ return;
+ }
+
+ // We cannot use default libpng write function since it requires
+ // a file pointer (FILE*), whereas we want to use the ostream.
+ // The following function replaces the write function with a custom
+ // one provided by us (writePng)
+ png_set_write_fn(pngPtr, (png_voidp)&png, writePng, NULL);
+
+ png_set_IHDR(pngPtr, infoPtr, width, height, 8,
+ PNG_COLOR_TYPE_RGB,
+ PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
+
+ png_write_info(pngPtr, infoPtr);
+
+ // libpng requires an array of pointers to the frame buffer's rows.
+ std::vector<PixelType> rowPacked(width);
+ for (unsigned y=0; y < height; ++y) {
+ for (unsigned x=0; x < height; ++x) {
+ rowPacked[x] = fb.pixel(x, y);
+ }
+
+ png_write_row(pngPtr,
+ reinterpret_cast<png_bytep>(rowPacked.data())
+ );
+ }
+
+ // End of write
+ png_write_end(pngPtr, NULL);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2017 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Giacomo Travaglini
+ */
+
+/**
+ * @file Declaration of a class that writes a frame buffer to a png
+ */
+
+#ifndef __BASE_PNG_HH__
+#define __BASE_PNG_HH__
+
+#include "base/compiler.hh"
+#include "base/framebuffer.hh"
+#include "base/imgwriter.hh"
+
+/** Image writer implementing support for PNG */
+class PngWriter : public ImgWriter
+{
+ public:
+ /**
+ * Create a png that takes data in a given mode & size and
+ * outputs to an ostream.
+ */
+ PngWriter(const FrameBuffer *_fb)
+ : ImgWriter(_fb)
+ {}
+
+ ~PngWriter() {};
+
+ /**
+ * Return Image format as a string
+ *
+ * @return img extension (e.g. .png for Png)
+ */
+ const char* getImgExtension() const override
+ { return _imgExtension; }
+
+ /**
+ * Write the frame buffer data into the provided ostream
+ *
+ * @param png stream to write to
+ */
+ void write(std::ostream &png) const override;
+ private:
+ /** Png Pixel type: not containing padding */
+ struct PngPixel24 {
+ PngPixel24 &operator=(const Pixel &rhs) {
+ red = rhs.red;
+ green = rhs.green;
+ blue = rhs.blue;
+
+ return *this;
+ }
+ uint8_t red;
+ uint8_t green;
+ uint8_t blue;
+ } M5_ATTR_PACKED;
+
+ /**
+ * Handle to resources used by libpng:
+ * - png_struct: Structure holding write informations
+ * - png_info : Structure holding image informations
+ *
+ * The class is automatically taking care of struct
+ * allocation/deallocation
+ */
+ struct PngStructHandle;
+
+ typedef PngPixel24 PixelType;
+
+ static const char* _imgExtension;
+};
+
+#endif // __BASE_PNG_HH__
from m5.SimObject import SimObject
from m5.params import *
+from Graphics import *
+
class VncInput(SimObject):
type = 'VncInput'
cxx_header = "base/vnc/vncinput.hh"
frame_capture = Param.Bool(False, "capture changed frames to files")
+ img_format = Param.ImageFormat(
+ "Bitmap", "Format of the dumped Framebuffer"
+ )
class VncServer(VncInput):
type = 'VncServer'
/*
- * Copyright (c) 2010, 2015 ARM Limited
+ * Copyright (c) 2010, 2015, 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
#include "base/misc.hh"
#include "base/output.hh"
+
#include "base/trace.hh"
#include "debug/VNC.hh"
fb(&FrameBuffer::dummy),
_videoWidth(fb->width()), _videoHeight(fb->height()),
captureEnabled(p->frame_capture),
- captureCurrentFrame(0), captureLastHash(0)
+ captureCurrentFrame(0), captureLastHash(0),
+ imgFormat(p->img_format)
{
if (captureEnabled) {
// remove existing frame output directory if it exists, then create a
fb = rfb;
- // create bitmap of the frame with new attributes
- if (captureEnabled)
- captureBitmap.reset(new Bitmap(rfb));
+ // Create the Image Writer object in charge of dumping
+ // the frame buffer raw data into a file in a specific format.
+ if (captureEnabled) {
+ captureImage = createImgWriter(imgFormat, rfb);
+ }
// Setting a new frame buffer means that we need to send an update
// to the client. Mark the internal buffers as dirty to do so.
void
VncInput::captureFrameBuffer()
{
- assert(captureBitmap);
+ assert(captureImage);
// skip identical frames
uint64_t new_hash = fb->getHash();
// get the filename for the current frame
char frameFilenameBuffer[64];
- snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.bmp.gz",
- captureCurrentFrame, static_cast<long long int>(curTick()));
+ snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.%s.gz",
+ captureCurrentFrame, static_cast<long long int>(curTick()),
+ captureImage->getImgExtension());
const string frameFilename(frameFilenameBuffer);
// create the compressed framebuffer file
OutputStream *fb_out(captureOutputDirectory->create(frameFilename, true));
- captureBitmap->write(*fb_out->stream());
+ captureImage->write(*fb_out->stream());
captureOutputDirectory->close(fb_out);
++captureCurrentFrame;
#include <iostream>
#include <memory>
-#include "base/bitmap.hh"
+#include "base/imgwriter.hh"
#include "params/VncInput.hh"
#include "sim/sim_object.hh"
/** Computed hash of the last captured frame */
uint64_t captureLastHash;
- /** Cached bitmap object for writing out frame buffers to file */
- std::unique_ptr<Bitmap> captureBitmap;
+ /** Cached ImgWriter object for writing out frame buffers to file */
+ std::unique_ptr<ImgWriter> captureImage;
+
+ /** image format */
+ Enums::ImageFormat imgFormat;
/** Captures the current frame buffer to a file */
void captureFrameBuffer();
#include <cstdio>
#include "base/atomicio.hh"
-#include "base/bitmap.hh"
#include "base/misc.hh"
#include "base/output.hh"
#include "base/socket.hh"
#include <iostream>
#include "base/vnc/vncinput.hh"
-#include "base/bitmap.hh"
#include "base/circlebuf.hh"
#include "base/pollevent.hh"
#include "base/socket.hh"
#include <fstream>
#include <memory>
-#include "base/bitmap.hh"
+#include "base/bmpwriter.hh"
#include "base/framebuffer.hh"
#include "base/output.hh"
#include "dev/arm/amba_device.hh"
EventFunctionWrapper virtRefreshEvent;
/** Helper to write out bitmaps */
- Bitmap bmp;
+ BmpWriter bmp;
/** Picture of what the current frame buffer looks like */
OutputStream *pic;
#include <fstream>
#include <memory>
-#include "base/bitmap.hh"
+#include "base/bmpwriter.hh"
#include "base/framebuffer.hh"
#include "base/output.hh"
#include "dev/arm/amba_device.hh"
VncInput *vnc;
/** Helper to write out bitmaps */
- Bitmap bmp;
+ BmpWriter bmp;
/** Picture of what the current frame buffer looks like */
OutputStream *pic;