2004-08-11 11:30:25 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// graphics-related interaction with running apps
|
|
|
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "client_state.h"
|
2004-09-13 05:27:28 +00:00
|
|
|
#include "client_msgs.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
|
|
|
|
void ACTIVE_TASK::request_graphics_mode(int mode) {
|
2004-09-13 05:27:28 +00:00
|
|
|
if (!app_client_shm.shm) return;
|
|
|
|
graphics_request_queue.msg_queue_send(
|
|
|
|
xml_graphics_modes[mode],
|
|
|
|
app_client_shm.shm->graphics_request
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-09-13 05:27:28 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
void ACTIVE_TASK::check_graphics_mode_ack() {
|
|
|
|
int mode;
|
|
|
|
char buf[MSG_CHANNEL_SIZE];
|
2004-08-24 21:44:54 +00:00
|
|
|
|
|
|
|
if (!app_client_shm.shm) return;
|
2004-08-11 11:30:25 +00:00
|
|
|
if (app_client_shm.shm->graphics_reply.get_msg(buf)) {
|
|
|
|
mode = app_client_shm.decode_graphics_msg(buf);
|
2004-09-13 05:27:28 +00:00
|
|
|
//msg_printf(NULL, MSG_INFO, "got graphics ack %s for %s", buf, result->name);
|
2004-08-11 11:30:25 +00:00
|
|
|
if (mode != MODE_REREAD_PREFS) {
|
|
|
|
graphics_mode_acked = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return an app (if any) with given requested mode
|
|
|
|
//
|
2004-09-13 05:27:28 +00:00
|
|
|
ACTIVE_TASK* ACTIVE_TASK_SET::get_ss_app() {
|
2004-08-11 11:30:25 +00:00
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-09-13 05:27:28 +00:00
|
|
|
if (atp->is_ss_app) {
|
2004-08-11 11:30:25 +00:00
|
|
|
return atp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// remember graphics state of apps.
|
|
|
|
// Called when entering screensaver mode,
|
|
|
|
// so that we can return to same state later
|
|
|
|
//
|
2004-08-11 11:30:25 +00:00
|
|
|
void ACTIVE_TASK_SET::save_app_modes() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-09-13 05:27:28 +00:00
|
|
|
|
|
|
|
// nothing should be in fullscreen mode.
|
|
|
|
//
|
|
|
|
if (atp->graphics_mode_acked == MODE_FULLSCREEN) {
|
|
|
|
atp->graphics_mode_acked = MODE_HIDE_GRAPHICS;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
atp->graphics_mode_before_ss = atp->graphics_mode_acked;
|
|
|
|
//msg_printf(NULL, MSG_INFO, "saved mode %d", atp->graphics_mode_acked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK_SET::hide_apps() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
|
|
|
atp->request_graphics_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return apps to the mode they were in before screensaving started
|
|
|
|
//
|
|
|
|
void ACTIVE_TASK_SET::restore_apps() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-09-13 05:27:28 +00:00
|
|
|
if (atp->graphics_mode_before_ss == MODE_WINDOW) {
|
|
|
|
atp->request_graphics_mode(MODE_WINDOW);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK_SET::graphics_poll() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-08-23 22:44:53 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2004-09-13 05:27:28 +00:00
|
|
|
atp->graphics_request_queue.msg_queue_poll(
|
|
|
|
atp->app_client_shm.shm->graphics_request
|
|
|
|
);
|
2004-08-11 11:30:25 +00:00
|
|
|
atp->check_graphics_mode_ack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ACTIVE_TASK::supports_graphics() {
|
|
|
|
return (graphics_mode_acked != MODE_UNSUPPORTED);
|
|
|
|
}
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// Return the next graphics-capable running app.
|
2004-08-11 11:30:25 +00:00
|
|
|
// Always try to choose a new project.
|
|
|
|
// Preferences goes to apps with pre-ss mode WINDOW,
|
|
|
|
// then apps with pre-ss mode HIDE
|
|
|
|
//
|
|
|
|
ACTIVE_TASK* CLIENT_STATE::get_next_graphics_capable_app() {
|
|
|
|
static int project_index=0;
|
|
|
|
unsigned int i, j;
|
2004-09-13 05:27:28 +00:00
|
|
|
ACTIVE_TASK *atp, *best_atp;
|
2004-08-11 11:30:25 +00:00
|
|
|
PROJECT *p;
|
|
|
|
|
|
|
|
// loop through all projects starting with the one at project_index
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); ++i) {
|
|
|
|
project_index %= projects.size();
|
|
|
|
p = projects[project_index++];
|
|
|
|
|
2004-09-13 05:27:28 +00:00
|
|
|
best_atp = NULL;
|
|
|
|
for (j=0; j<active_tasks.active_tasks.size(); j++) {
|
2004-08-11 11:30:25 +00:00
|
|
|
atp = active_tasks.active_tasks[j];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
if (atp->result->project != p) continue;
|
2004-09-13 05:27:28 +00:00
|
|
|
if (!best_atp && atp->graphics_mode_before_ss == MODE_WINDOW) {
|
|
|
|
best_atp = atp;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
if (!best_atp && atp->graphics_mode_before_ss == MODE_HIDE_GRAPHICS) {
|
|
|
|
best_atp = atp;
|
|
|
|
}
|
|
|
|
if (!best_atp && atp->graphics_mode_acked != MODE_UNSUPPORTED) {
|
|
|
|
best_atp = atp;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
if (best_atp) {
|
|
|
|
//msg_printf(NULL, MSG_INFO, "chose SS: %s", best_atp->result->name);
|
|
|
|
return atp;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
//msg_printf(NULL, MSG_INFO, "no SS to choose");
|
2004-08-11 11:30:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|