forked from leavengood/Haiku-Browser
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRenderAppManager.cpp
More file actions
206 lines (172 loc) · 5.14 KB
/
RenderAppManager.cpp
File metadata and controls
206 lines (172 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright 2009, Maxime Simon, simon.maxime@gmail.com
// All rights reserved.
//
// Distributed under the terms of the MIT License.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "RenderAppManager.h"
#include "AppSignatures.h"
#include "Constants.h"
#include "Tranquility.h"
#include <Bitmap.h>
#include <Messenger.h>
#include <OS.h>
#include <Roster.h>
#include <String.h>
#include <syslog.h>
RenderAppManager::RenderAppManager()
: BHandler(),
fProxyViewManager(new ProxyViewManager())
{
}
RenderAppManager::~RenderAppManager()
{
}
void
RenderAppManager::MessageReceived(BMessage *message)
{
switch (message->what) {
case kMsgForward:
case kMsgUpdate:
{
int32 proxyID;
message->FindInt32("proxyID", &proxyID);
team_id renderTeam = fMapProxyToRender[proxyID];
BMessenger(kRenderAppSignature, renderTeam).SendMessage(message);
break;
}
case kMsgBitmapData:
{
int32 proxyID;
message->FindInt32("proxyID", &proxyID);
ProxyView *proxyView = fProxyViewManager->GetProxyFromID(proxyID);
syslog(LOG_DEBUG, "RenderAppManager: received kMsgBitmapData message");
BBitmap *bitmap = dynamic_cast<BBitmap*>(BBitmap::Instantiate(message));
if (bitmap != NULL && proxyView != NULL) {
if (proxyView->Window()->Lock()) {
proxyView->SetViewBitmap(bitmap);
proxyView->Window()->Unlock();
}
delete bitmap;
} else {
syslog(LOG_DEBUG, "RenderAppManager: bitmap from message is not valid!");
}
// Code to create the bitmap from raw data and a bytes per row (bpr) value
/*int32 length = 0;
const void *data;
if (message->FindData("data", B_RAW_TYPE, &data, &length) == B_OK) {
int32 bpr;
if (message->FindInt32("bpr", &bpr) == B_OK) {
syslog(LOG_DEBUG, "Tranquility: got bpr from kMsgBitmapData message");
BBitmap bitmap(fBrowserWindow->Bounds(), B_RGB32);
bitmap.ImportBits(data, length, bpr, 0, B_RGB32);
fBrowserWindow->SetViewBitmap(&bitmap);
}
}*/
break;
}
case kMsgRequestRenderApp:
{
void *ptr;
message->FindPointer("proxyView", &ptr);
ProxyView *proxyView = static_cast<ProxyView *>(ptr);
int32 proxyID = fProxyViewManager->AddProxyView(proxyView);
RenderBoyRequest(proxyID);
break;
}
case kMsgLeaveRenderApp:
{
int32 proxyID;
message->FindInt32("proxyID", &proxyID);
LeaveRenderBoy(proxyID);
fProxyViewManager->RemoveProxyView(proxyID);
break;
}
case B_SOME_APP_QUIT:
{
BString sig;
if (message->FindString("be:signature", &sig) == B_OK) {
if (sig.Compare(kRenderAppSignature) == 0) {
team_id renderTeam;
message->FindInt32("be:team", &renderTeam);
std::set<int32> proxyList = fMapRenderToProxy[renderTeam];
std::set<int32>::iterator id;
for (id = proxyList.begin(); id != proxyList.end(); id++) {
fProxyViewManager->GetProxyFromID(*id)->DrawSadTab("The render process has quit!");
fMapProxyToRender.erase(*id);
}
fMapRenderToProxy.erase(renderTeam);
}
}
break;
}
default:
BHandler::MessageReceived(message);
break;
}
}
void
RenderAppManager::Quit()
{
MapIntVecInt::iterator it;
team_id renderTeam;
for (it = fMapRenderToProxy.begin(); it != fMapRenderToProxy.end(); it++) {
renderTeam = it->first;
BMessenger(kRenderAppSignature, renderTeam).SendMessage(B_QUIT_REQUESTED);
}
}
status_t
RenderAppManager::StartRenderBoy(BMessage startMsg, team_id *renderTeam)
{
status_t error;
error = be_roster->Launch(kRenderAppSignature, &startMsg, renderTeam);
return error;
}
void
RenderAppManager::StopRenderBoy(team_id renderTeam)
{
MapIntInt::iterator it = fMapProxyToRender.begin();
while (it != fMapProxyToRender.end()) {
if (it->second == renderTeam)
fMapProxyToRender.erase(it);
else
it++;
}
BMessenger(kRenderAppSignature, renderTeam).SendMessage(B_QUIT_REQUESTED);
}
void
RenderAppManager::RenderBoyRequest(int32 proxyID)
{
team_id renderTeam;
ProxyView *proxyView = fProxyViewManager->GetProxyFromID(proxyID);
if (true) {
// For the moment each time a ProxyView needs a RenderBoy,
// a RenderBoy is started. This isn't the expected behaviour.
BMessage startMsg(kMsgStartRenderApp);
startMsg.AddRect("renderFrame", proxyView->Window()->Bounds());
startMsg.AddInt32("teamID", my_app->Team());
startMsg.AddInt32("proxyID", proxyID);
if (StartRenderBoy(startMsg, &renderTeam) != B_OK) {
syslog(LOG_DEBUG, "RenderAppManager: There was an error trying to launch the render process!");
proxyView->DrawSadTab("Error trying to launch the render process!");
}
}
fMapProxyToRender[proxyID] = renderTeam;
fMapRenderToProxy[renderTeam].insert(proxyID);
}
void
RenderAppManager::LeaveRenderBoy(int32 proxyID)
{
team_id renderTeam = fMapProxyToRender[proxyID];
BMessage leaveMsg(kMsgLeaveRenderApp);
leaveMsg.AddInt32("proxyID", proxyID);
BMessenger(kRenderAppSignature, renderTeam).SendMessage(&leaveMsg);
fMapProxyToRender.erase(proxyID);
fMapRenderToProxy[renderTeam].erase(proxyID);
if (fMapRenderToProxy[renderTeam].empty()) {
StopRenderBoy(renderTeam);
fMapRenderToProxy.erase(renderTeam);
}
}