VBoxDisplay.cpp revision 9fc58edfe4464fca24d4a064b9d3fe2ed173a71a
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/* $Id$ */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** @file
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * VBoxDisplayService, Haiku Guest Additions, implementation.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/*
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Copyright (C) 2012 Oracle Corporation
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * available from http://www.virtualbox.org. This file is free software;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * you can redistribute it and/or modify it under the terms of the GNU
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * General Public License (GPL) as published by the Free Software
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/*
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * This code is based on:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * VirtualBox Guest Additions for Haiku.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Copyright (c) 2011 Mike Smith <mike@scgtrp.net>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Fran�ois Revol <revol@free.fr>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Permission is hereby granted, free of charge, to any person
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * obtaining a copy of this software and associated documentation
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * files (the "Software"), to deal in the Software without
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * restriction, including without limitation the rights to use,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * copy, modify, merge, publish, distribute, sublicense, and/or sell
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * copies of the Software, and to permit persons to whom the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Software is furnished to do so, subject to the following
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * conditions:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * The above copyright notice and this permission notice shall be
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * included in all copies or substantial portions of the Software.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * OTHER DEALINGS IN THE SOFTWARE.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <stdio.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <stdlib.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <new>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <DataIO.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <Message.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <TranslationUtils.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <TranslatorFormats.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <TranslatorRoster.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <String.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include "VBoxGuestApplication.h"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include "VBoxDisplay.h"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <VBoxGuestInternal.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include "../VBoxVideo/common/VBoxVideo_common.h"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <iprt/mem.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <VBox/log.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#ifdef DEBUG_ramshankar
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# undef Log
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# define Log(x) printf x
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# undef LogRel
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# define LogRel(x) printf x
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# undef LogRelFlowFunc
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# define LogRelFlowFunc(x) printf x
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#endif
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncVBoxDisplayService::VBoxDisplayService()
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync : BHandler("VBoxDisplayService"),
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fClientId(-1),
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fServiceThreadID(-1),
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fExiting(false),
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fScreen(B_MAIN_SCREEN_ID)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync}
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncVBoxDisplayService::~VBoxDisplayService()
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync}
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncvoid VBoxDisplayService::Start()
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync status_t err;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync err = fServiceThreadID = spawn_thread(_ServiceThreadNub, "VBoxDisplayService", B_NORMAL_PRIORITY, this);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if (err >= B_OK)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync resume_thread(fServiceThreadID);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync LogRel(("VBoxDisplayService: Error starting service thread: %s\n", strerror(err)));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync}
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncvoid VBoxDisplayService::MessageReceived(BMessage *message)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if (message->what == B_QUIT_REQUESTED)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fExiting = true;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync BHandler::MessageReceived(message);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync}
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncstatus_t VBoxDisplayService::_ServiceThreadNub(void *_this)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync VBoxDisplayService *service = (VBoxDisplayService *)_this;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return service->_ServiceThread();
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync}
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncstatus_t VBoxDisplayService::_ServiceThread()
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync LogFlow(("VBoxDisplayService::_ServiceThread"));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync VbglR3SetGuestCaps(VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (;;)
{
uint32_t events;
int rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 5000, &events);
if (rc == -6) // timed out?
continue;
if (RT_SUCCESS(rc))
{
uint32_t cx, cy, cBits, iDisplay;
int rc2 = VbglR3GetDisplayChangeRequest(&cx, &cy, &cBits, &iDisplay, NULL, NULL, NULL, NULL, true);
LogFlow(("rc2=%d screen %d size changed (%d, %d, %d)\n", rc2, iDisplay, cx, cy, cBits));
if (RT_SUCCESS(rc2))
{
display_mode mode;
fScreen.GetMode(&mode);
if (cBits == 0)
cBits = get_depth_for_color_space(mode.space);
mode.timing.h_display = cx;
mode.timing.v_display = cy;
mode.space = get_color_space_for_depth(cBits);
mode.virtual_width = cx;
mode.virtual_height = cy;
/*= {
{0, cx, 0, 0, cBits * cx / 8, cy, 0, 0, cBits * cy / 8, 0},
get_color_space_for_depth(cBits),
cx, cy, 0, 0, 0
};*/
fScreen.SetMode(&mode, false);
}
}
else
fExiting = true;
LogFlow(("processed host event rc = %d\n", rc));
if (fExiting)
break;
}
return 0;
}