96
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "tsscreenshotplugin.h"
|
|
18 |
#include "tstaskmonitorglobals.h"
|
|
19 |
#include <graphics/wsscreendevice.h>
|
|
20 |
#include <s32mem.h>
|
|
21 |
|
|
22 |
const TInt KMsgSize(5);
|
|
23 |
const TInt KInvalidGroupId(~0);
|
|
24 |
// -----------------------------------------------------------------------------
|
|
25 |
//
|
|
26 |
// -----------------------------------------------------------------------------
|
|
27 |
//
|
|
28 |
CTsScreenshotPlugin* CTsScreenshotPlugin::NewL()
|
|
29 |
{
|
|
30 |
//no second step construction is required here
|
|
31 |
//window server will initialize plugin later
|
|
32 |
return new(ELeave)CTsScreenshotPlugin();
|
|
33 |
}
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
void CTsScreenshotPlugin::ConstructL(MWsGraphicDrawerEnvironment& env,
|
|
39 |
const TGraphicDrawerId& id,
|
|
40 |
MWsClient& owner,
|
|
41 |
const TDesC8& /*data*/ )
|
|
42 |
{
|
|
43 |
BaseConstructL(env, id, owner);
|
|
44 |
env.RegisterEventHandler(this,
|
|
45 |
this,
|
|
46 |
TWservCrEvent::EWindowGroupChanged |
|
|
47 |
TWservCrEvent::EDeviceOrientationChanged);
|
|
48 |
mWindowGroupId = KInvalidGroupId;
|
|
49 |
}
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
CTsScreenshotPlugin::~CTsScreenshotPlugin()
|
|
55 |
{
|
|
56 |
Env().UnregisterEventHandler(this);
|
|
57 |
mCache.ResetAndDestroy();
|
|
58 |
}
|
|
59 |
|
|
60 |
// -----------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
void CTsScreenshotPlugin::DoDraw(MWsGc&, const TRect&, const TDesC8&) const
|
|
65 |
{
|
|
66 |
//plugin is not a real drawer
|
|
67 |
//no implementation required
|
|
68 |
}
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
void CTsScreenshotPlugin::HandleMessage(const TDesC8& msg)
|
|
74 |
{
|
|
75 |
TRAP_IGNORE(HandleMessageL(msg));
|
|
76 |
}
|
|
77 |
|
|
78 |
// -----------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
// -----------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
void CTsScreenshotPlugin::HandleMessageL(const TDesC8& msg)
|
|
83 |
{
|
|
84 |
TInt parsedMsg[KMsgSize];
|
|
85 |
RDesReadStream msgStream(msg);
|
|
86 |
for (TInt iter(0); iter < KMsgSize; ++iter) {
|
|
87 |
parsedMsg[iter] = msgStream.ReadInt32L();
|
|
88 |
}
|
|
89 |
|
|
90 |
if (RegisterScreenshotMessage == parsedMsg[0]) { //Screenshot registeration ACK
|
|
91 |
for(TInt iter(0); iter < mCache.Count(); ++iter) {
|
|
92 |
if (mCache[iter]->Handle() == parsedMsg[ScreenshotHandle + 1]) {
|
|
93 |
//bitmap is not needed no more
|
|
94 |
delete mCache[iter];
|
|
95 |
mCache.Remove(iter);
|
|
96 |
break;
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
// -----------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
// -----------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
void CTsScreenshotPlugin::DoHandleEvent(const TWservCrEvent& event)
|
|
107 |
{
|
|
108 |
switch (event.Type()) {
|
|
109 |
case TWservCrEvent::EWindowGroupChanged:
|
|
110 |
if (KInvalidGroupId != mWindowGroupId) {
|
|
111 |
TakeScreenshot(mWindowGroupId);
|
|
112 |
}
|
|
113 |
mWindowGroupId = event.WindowGroupIdentifier();
|
|
114 |
break;
|
|
115 |
case TWservCrEvent::EDeviceOrientationChanged:
|
|
116 |
TakeScreenshot(mWindowGroupId);
|
|
117 |
break;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
// -----------------------------------------------------------------------------
|
|
122 |
//
|
|
123 |
// -----------------------------------------------------------------------------
|
|
124 |
//
|
|
125 |
void CTsScreenshotPlugin::TakeScreenshot(TInt id)
|
|
126 |
{
|
|
127 |
TRAP_IGNORE(TakeScreenshotL(id);)
|
|
128 |
}
|
|
129 |
|
|
130 |
// -----------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
// -----------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
void CTsScreenshotPlugin::TakeScreenshotL(TInt id)
|
|
135 |
{
|
|
136 |
if(0 >= Env().ScreenCount()) {
|
|
137 |
User::Leave(KErrCorrupt);
|
|
138 |
}
|
|
139 |
const TInt screenId(0); //use local variable in case of changing screen selection policy
|
|
140 |
const MWsScreenConfig* const screenConfig =
|
|
141 |
Env().Screen(screenId)->ObjectInterface<MWsScreenConfig>();
|
|
142 |
const MWsScreenDevice* const screenDevice =
|
|
143 |
static_cast<MWsScreenDevice*>(Env().Screen(screenId)->ResolveObjectInterface(MWsScreenDevice::EWsObjectInterfaceId));
|
|
144 |
|
|
145 |
User::LeaveIfNull(screenConfig);
|
|
146 |
User::LeaveIfNull(screenDevice);
|
|
147 |
|
|
148 |
//prepare destination bitmap
|
|
149 |
CFbsBitmap *bitmap = new (ELeave) CFbsBitmap();
|
|
150 |
CleanupStack::PushL(bitmap);
|
|
151 |
|
|
152 |
|
|
153 |
User::LeaveIfError(bitmap->Create(screenConfig->SizeInPixels(),
|
|
154 |
screenConfig->DisplayMode()));
|
|
155 |
|
|
156 |
screenDevice->CopyScreenToBitmapL(bitmap,
|
|
157 |
screenConfig->SizeInPixels());
|
|
158 |
|
|
159 |
|
|
160 |
//prepare and send message
|
|
161 |
TInt msg[KMsgSize] = {RegisterScreenshotMessage};
|
|
162 |
|
|
163 |
msg[WindowsGroup + 1] = id;
|
|
164 |
msg[ScreenshotHandle + 1] = bitmap->Handle();
|
|
165 |
msg[Priority + 1] = Low;
|
|
166 |
msg[AdditionalParameters + 1] = 0; //unused
|
|
167 |
|
|
168 |
const TPckgC<TInt[sizeof(msg) / sizeof(TInt)]> buf(msg);
|
|
169 |
|
|
170 |
User::LeaveIfError(SendMessage(buf));
|
|
171 |
|
|
172 |
mCache.AppendL(bitmap);
|
|
173 |
CleanupStack::Pop(bitmap);
|
|
174 |
|
|
175 |
}
|
|
176 |
|