framebuffer.cc revision 12366:3b4b6fa339a9
12623SN/A/*
211147Smitch.hayenga@arm.com * Copyright (c) 2015 ARM Limited
38926Sandreas.hansson@arm.com * All rights reserved
48926Sandreas.hansson@arm.com *
58926Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68926Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78926Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88926Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98926Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108926Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118926Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128926Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138926Sandreas.hansson@arm.com *
142623SN/A * Redistribution and use in source and binary forms, with or without
152623SN/A * modification, are permitted provided that the following conditions are
162623SN/A * met: redistributions of source code must retain the above copyright
172623SN/A * notice, this list of conditions and the following disclaimer;
182623SN/A * redistributions in binary form must reproduce the above copyright
192623SN/A * notice, this list of conditions and the following disclaimer in the
202623SN/A * documentation and/or other materials provided with the distribution;
212623SN/A * neither the name of the copyright holders nor the names of its
222623SN/A * contributors may be used to endorse or promote products derived from
232623SN/A * this software without specific prior written permission.
242623SN/A *
252623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
262623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
272623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
282623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
312623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
322623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
332623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
342623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
352623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
362623SN/A *
372623SN/A * Authors: Andreas Sandberg
382623SN/A */
392665Ssaidi@eecs.umich.edu
402665Ssaidi@eecs.umich.edu#include "base/framebuffer.hh"
412623SN/A
422623SN/A#include <zlib.h>
432623SN/A
442623SN/A#include "base/bitfield.hh"
452623SN/A
462623SN/Aconst FrameBuffer FrameBuffer::dummy(320, 240);
4711147Smitch.hayenga@arm.com
485529Snate@binkert.orgFrameBuffer::FrameBuffer(unsigned width, unsigned height)
4910381Sdam.sunwoo@arm.com    : pixels(width * height),
509647Sdam.sunwoo@arm.com      _width(width), _height(height)
512623SN/A{
522623SN/A    clear();
532623SN/A}
542623SN/A
555529Snate@binkert.orgFrameBuffer::FrameBuffer()
562623SN/A    : _width(0), _height(0)
572623SN/A{
582623SN/A}
592623SN/A
602623SN/AFrameBuffer::~FrameBuffer()
612623SN/A{
622623SN/A}
632623SN/A
642623SN/A
652623SN/Avoid
662623SN/AFrameBuffer::serialize(CheckpointOut &cp) const
672623SN/A{
685336Shines@cs.fsu.edu    SERIALIZE_SCALAR(_width);
692623SN/A    SERIALIZE_SCALAR(_height);
702623SN/A    SERIALIZE_CONTAINER(pixels);
712623SN/A}
722623SN/A
732623SN/Avoid
746078Sgblack@eecs.umich.eduFrameBuffer::unserialize(CheckpointIn &cp)
755487Snate@binkert.org{
765487Snate@binkert.org    UNSERIALIZE_SCALAR(_width);
772623SN/A    UNSERIALIZE_SCALAR(_height);
782623SN/A    UNSERIALIZE_CONTAINER(pixels);
792623SN/A}
802623SN/A
818707Sandreas.hansson@arm.comvoid
829443SAndreas.Sandberg@ARM.comFrameBuffer::resize(unsigned width, unsigned height)
839443SAndreas.Sandberg@ARM.com{
849443SAndreas.Sandberg@ARM.com    _width = width;
859443SAndreas.Sandberg@ARM.com    _height = height;
869443SAndreas.Sandberg@ARM.com
879443SAndreas.Sandberg@ARM.com    pixels.resize(width * height);
889443SAndreas.Sandberg@ARM.com}
899443SAndreas.Sandberg@ARM.com
909443SAndreas.Sandberg@ARM.comvoid
919443SAndreas.Sandberg@ARM.comFrameBuffer::fill(const Pixel &pixel)
929443SAndreas.Sandberg@ARM.com{
939443SAndreas.Sandberg@ARM.com    for (auto &p : pixels)
949443SAndreas.Sandberg@ARM.com        p = pixel;
959443SAndreas.Sandberg@ARM.com}
969443SAndreas.Sandberg@ARM.com
979443SAndreas.Sandberg@ARM.comvoid
989443SAndreas.Sandberg@ARM.comFrameBuffer::clear()
999443SAndreas.Sandberg@ARM.com{
10011147Smitch.hayenga@arm.com    static const Pixel black(0, 0, 0);
10111147Smitch.hayenga@arm.com
10211147Smitch.hayenga@arm.com    fill(black);
1039443SAndreas.Sandberg@ARM.com}
10411147Smitch.hayenga@arm.com
1059443SAndreas.Sandberg@ARM.comvoid
1069443SAndreas.Sandberg@ARM.comFrameBuffer::copyIn(const uint8_t *fb, const PixelConverter &conv)
1079443SAndreas.Sandberg@ARM.com{
1089443SAndreas.Sandberg@ARM.com    for (auto &p : pixels) {
1099443SAndreas.Sandberg@ARM.com        p = conv.toPixel(fb);
1109443SAndreas.Sandberg@ARM.com        fb += conv.length;
1119443SAndreas.Sandberg@ARM.com    }
1129443SAndreas.Sandberg@ARM.com}
1139443SAndreas.Sandberg@ARM.com
1149443SAndreas.Sandberg@ARM.comvoid
1158707Sandreas.hansson@arm.comFrameBuffer::copyOut(uint8_t *fb, const PixelConverter &conv) const
1169608Sandreas.hansson@arm.com{
1179608Sandreas.hansson@arm.com    for (auto &p : pixels) {
1189608Sandreas.hansson@arm.com        conv.fromPixel(fb, p);
1198707Sandreas.hansson@arm.com        fb += conv.length;
1209608Sandreas.hansson@arm.com    }
1212623SN/A}
1228707Sandreas.hansson@arm.com
1232623SN/Auint64_t
1242623SN/AFrameBuffer::getHash() const
12510030SAli.Saidi@ARM.com{
1269608Sandreas.hansson@arm.com    return adler32(0UL,
1272623SN/A                   reinterpret_cast<const Bytef *>(pixels.data()),
1282623SN/A                   area() * sizeof(Pixel));
1292623SN/A}
13010030SAli.Saidi@ARM.com