Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 22:38:16 +00:00
|
|
|
/*
|
2016-09-03 21:46:10 +00:00
|
|
|
* Copyright (c) 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 22:38:16 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* sortix/kernel/textbuffer.h
|
|
|
|
* Provides a indexable text buffer for used by text mode terminals.
|
|
|
|
*/
|
2012-07-22 22:01:12 +00:00
|
|
|
|
2022-07-07 23:09:15 +00:00
|
|
|
#ifndef _INCLUDE_SORTIX_KERNEL_TEXTBUFFER_H
|
|
|
|
#define _INCLUDE_SORTIX_KERNEL_TEXTBUFFER_H
|
2012-07-22 22:01:12 +00:00
|
|
|
|
2014-02-25 21:39:57 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2014-04-19 18:28:54 +00:00
|
|
|
#include <stddef.h>
|
2014-02-25 21:39:57 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-07-22 22:01:12 +00:00
|
|
|
#include <sortix/kernel/kthread.h>
|
|
|
|
#include <sortix/kernel/refcount.h>
|
|
|
|
|
|
|
|
namespace Sortix {
|
|
|
|
|
2016-09-25 10:08:15 +00:00
|
|
|
static const uint16_t ATTR_INVERSE = 1 << 0;
|
2015-10-04 16:55:06 +00:00
|
|
|
static const uint16_t ATTR_BOLD = 1 << 1;
|
|
|
|
static const uint16_t ATTR_UNDERLINE = 1 << 2;
|
|
|
|
|
2012-07-22 22:01:12 +00:00
|
|
|
struct TextPos
|
|
|
|
{
|
|
|
|
TextPos() { }
|
|
|
|
TextPos(size_t x, size_t y) : x(x), y(y) { }
|
|
|
|
size_t x;
|
|
|
|
size_t y;
|
|
|
|
};
|
|
|
|
|
2014-04-19 18:28:54 +00:00
|
|
|
struct TextCharPOD
|
|
|
|
{
|
|
|
|
wchar_t c;
|
|
|
|
uint8_t vgacolor; // Format of <sortix/vga.h>
|
2015-10-04 16:55:06 +00:00
|
|
|
uint16_t attr;
|
2016-09-25 10:08:15 +00:00
|
|
|
uint32_t fg;
|
|
|
|
uint32_t bg;
|
2014-04-19 18:28:54 +00:00
|
|
|
};
|
|
|
|
|
2012-07-22 22:01:12 +00:00
|
|
|
struct TextChar
|
|
|
|
{
|
|
|
|
TextChar() { }
|
2015-10-04 16:55:06 +00:00
|
|
|
TextChar(const TextCharPOD& o) :
|
2016-09-25 10:08:15 +00:00
|
|
|
c(o.c), vgacolor(o.vgacolor), attr(o.attr), fg(o.fg), bg(o.bg) { }
|
|
|
|
TextChar(wchar_t c, uint8_t vgacolor, uint16_t attr, uint32_t fg, uint32_t bg) :
|
|
|
|
c(c), vgacolor(vgacolor), attr(attr), fg(fg), bg(bg) { }
|
|
|
|
operator TextCharPOD() { return TextCharPOD{c, vgacolor, attr, fg, bg}; }
|
2014-04-19 18:28:54 +00:00
|
|
|
wchar_t c;
|
2012-07-22 22:01:12 +00:00
|
|
|
uint8_t vgacolor; // Format of <sortix/vga.h>
|
2015-10-04 16:55:06 +00:00
|
|
|
uint16_t attr;
|
2016-09-25 10:08:15 +00:00
|
|
|
uint32_t fg; // 32-bit foreground color.
|
|
|
|
uint32_t bg; // 32-bit background color.
|
2012-07-22 22:01:12 +00:00
|
|
|
};
|
|
|
|
|
2012-12-23 18:14:58 +00:00
|
|
|
static inline bool IsTextPosBeforeTextPos(const TextPos& a, const TextPos& b)
|
|
|
|
{
|
|
|
|
return a.y < b.y || (a.y == b.y && a.x < b.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsTextPosAfterTextPos(const TextPos& a, const TextPos& b)
|
|
|
|
{
|
|
|
|
return a.y > b.y || (a.y == b.y && a.x > b.x);
|
|
|
|
}
|
|
|
|
|
2012-07-22 22:01:12 +00:00
|
|
|
class TextBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~TextBuffer() { }
|
2016-09-03 21:46:10 +00:00
|
|
|
virtual size_t Width() = 0;
|
|
|
|
virtual size_t Height() = 0;
|
|
|
|
virtual TextChar GetChar(TextPos pos) = 0;
|
2012-07-22 22:01:12 +00:00
|
|
|
virtual void SetChar(TextPos pos, TextChar c) = 0;
|
|
|
|
virtual void Scroll(ssize_t off, TextChar fillwith) = 0;
|
|
|
|
virtual void Move(TextPos to, TextPos from, size_t numchars) = 0;
|
2015-10-04 16:55:06 +00:00
|
|
|
virtual void Fill(TextPos from, TextPos to, TextChar fillwith) = 0;
|
2016-09-03 21:46:10 +00:00
|
|
|
virtual bool GetCursorEnabled() = 0;
|
2012-07-22 22:01:12 +00:00
|
|
|
virtual void SetCursorEnabled(bool enablecursor) = 0;
|
2016-09-03 21:46:10 +00:00
|
|
|
virtual TextPos GetCursorPos() = 0;
|
2012-07-22 22:01:12 +00:00
|
|
|
virtual void SetCursorPos(TextPos cursorpos) = 0;
|
2015-03-19 23:08:08 +00:00
|
|
|
virtual void SpawnThreads() = 0;
|
2015-05-10 18:28:33 +00:00
|
|
|
virtual void Invalidate() = 0;
|
2013-11-11 21:21:56 +00:00
|
|
|
virtual bool EmergencyIsImpaired() = 0;
|
|
|
|
virtual bool EmergencyRecoup() = 0;
|
|
|
|
virtual void EmergencyReset() = 0;
|
2016-09-03 21:46:10 +00:00
|
|
|
virtual void Resume() = 0;
|
|
|
|
virtual void Pause() = 0;
|
2012-07-22 22:01:12 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// The purpose of this handle class is such that the terminal driver can have
|
|
|
|
// its backing storage replaced at runtime, for instance if the user changes
|
|
|
|
// the screen resolution or the graphics driver. The backing text buffer can
|
|
|
|
// only be changed when there are no references (but our own) to the text buffer
|
|
|
|
// so don't forget to release it when you are done.
|
2015-03-19 13:27:28 +00:00
|
|
|
class TextBufferHandle
|
2012-07-22 22:01:12 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-03-19 13:27:28 +00:00
|
|
|
TextBufferHandle(TextBuffer* textbuf = NULL);
|
|
|
|
~TextBufferHandle();
|
2012-07-22 22:01:12 +00:00
|
|
|
TextBuffer* Acquire();
|
|
|
|
void Release(TextBuffer* textbuf);
|
2016-09-03 21:46:10 +00:00
|
|
|
void BeginReplace();
|
|
|
|
void CancelReplace();
|
|
|
|
void FinishReplace(TextBuffer* newtextbuf);
|
2013-11-11 21:21:56 +00:00
|
|
|
bool EmergencyIsImpaired();
|
|
|
|
bool EmergencyRecoup();
|
|
|
|
void EmergencyReset();
|
|
|
|
TextBuffer* EmergencyAcquire();
|
|
|
|
void EmergencyRelease(TextBuffer* textbuf);
|
2012-07-22 22:01:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
kthread_mutex_t mutex;
|
|
|
|
kthread_cond_t unusedcond;
|
|
|
|
TextBuffer* textbuf;
|
|
|
|
size_t numused;
|
2012-09-07 18:46:06 +00:00
|
|
|
|
2012-07-22 22:01:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Sortix
|
|
|
|
|
|
|
|
#endif
|