// vi:set ft=cpp: -*- Mode: C++ -*-
/*
 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
 *               Alexander Warg <warg@os.inf.tu-dresden.de>
 *     economic rights: Technische Universität Dresden (Germany)
 *
 * This file is part of TUD:OS and distributed under the terms of the
 * GNU General Public License 2.
 * Please see the COPYING-GPL-2 file for details.
 *
 * As a special exception, you may use this file as part of a free software
 * library without restriction.  Specifically, if other files instantiate
 * templates or use macros or inline functions from this file, or you compile
 * this file and link it with other files to produce an executable, this
 * file does not by itself cause the resulting executable to be covered by
 * the GNU General Public License.  This exception does not however
 * invalidate any other reasons why the executable file might be covered by
 * the GNU General Public License.
 */
#pragma once

#include <l4/re/video/goos>

namespace L4Re { namespace Util { namespace Video {

class Goos_fb
{
private:
  L4::Cap<L4Re::Video::Goos> _goos;
  L4Re::Video::View _view;
  L4::Cap<L4Re::Dataspace> _buffer;

  enum Flags
  {
    F_dyn_buffer = 0x01,
    F_dyn_view   = 0x02,
    F_dyn_goos   = 0x04,
  };
  unsigned _flags;

  unsigned _buffer_index;

private:
  void init();

  Goos_fb(Goos_fb const &);
  void operator = (Goos_fb const &);

public:
  Goos_fb() : _goos(L4_INVALID_CAP), _buffer(L4_INVALID_CAP), _flags(0) {}

  explicit Goos_fb(L4::Cap<L4Re::Video::Goos> goos);
  explicit Goos_fb(char const *name);

  void setup(L4::Cap<L4Re::Video::Goos> goos);
  void setup(char const *name);

  ~Goos_fb();

  int view_info(L4Re::Video::View::Info *info)
  { return _view.info(info); }

  L4Re::Video::View const *view() const { return &_view; }
  L4Re::Video::View *view() { return &_view; }

  L4::Cap<L4Re::Dataspace> buffer() const { return _buffer; }
  void *attach_buffer();

  int refresh(int x, int y, int w, int h)
  { return _view.refresh(x, y, w, h); }

  L4::Cap<L4Re::Video::Goos> goos() const { return _goos; }
};
}}}
