|
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 <graphics/wsscreendevice.h> |
|
18 #include <s32mem.h> |
|
19 |
|
20 #include <tstaskmonitorglobals.h> |
|
21 |
|
22 #include "tsscreenshotplugin.h" |
|
23 #include "tsscreenshotmsg.h" |
|
24 |
|
25 const TInt KInvalidGroupId(~0); |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CTsScreenshotPlugin* CTsScreenshotPlugin::NewL() |
|
31 { |
|
32 //no second step construction is required here |
|
33 //window server will initialize plugin later |
|
34 return new(ELeave)CTsScreenshotPlugin(); |
|
35 } |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 void CTsScreenshotPlugin::ConstructL(MWsGraphicDrawerEnvironment& env, |
|
41 const TGraphicDrawerId& id, |
|
42 MWsClient& owner, |
|
43 const TDesC8& /*data*/ ) |
|
44 { |
|
45 BaseConstructL(env, id, owner); |
|
46 env.RegisterEventHandler(this, |
|
47 this, |
|
48 TWservCrEvent::EWindowGroupChanged | |
|
49 TWservCrEvent::EDeviceOrientationChanged); |
|
50 mWindowGroupId = KInvalidGroupId; |
|
51 } |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CTsScreenshotPlugin::~CTsScreenshotPlugin() |
|
57 { |
|
58 Env().UnregisterEventHandler(this); |
|
59 mCache.ResetAndDestroy(); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CTsScreenshotPlugin::DoDraw(MWsGc&, const TRect&, const TDesC8&) const |
|
67 { |
|
68 //plugin is not a real drawer |
|
69 //no implementation required |
|
70 } |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 void CTsScreenshotPlugin::HandleMessage(const TDesC8& msg) |
|
76 { |
|
77 TRAP_IGNORE(HandleMessageL(msg)); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CTsScreenshotPlugin::HandleMessageL(const TDesC8& msg) |
|
85 { |
|
86 RDesReadStream msgStream(msg); |
|
87 CleanupClosePushL(msgStream); |
|
88 TInt function = msgStream.ReadInt32L(); |
|
89 if (RegisterScreenshotMessage == function) { |
|
90 CTsScreenshotMsg *screenshotMsg = CTsScreenshotMsg::NewLC(msgStream); |
|
91 for(TInt iter(0); iter < mCache.Count(); ++iter) { |
|
92 if (mCache[iter]->Handle() == screenshotMsg->screenshot().Handle()) { |
|
93 //bitmap is not needed no more |
|
94 delete mCache[iter]; |
|
95 mCache.Remove(iter); |
|
96 break; |
|
97 } |
|
98 } |
|
99 CleanupStack::PopAndDestroy(screenshotMsg); |
|
100 } |
|
101 CleanupStack::PopAndDestroy(&msgStream); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CTsScreenshotPlugin::DoHandleEvent(const TWservCrEvent& event) |
|
109 { |
|
110 switch (event.Type()) { |
|
111 case TWservCrEvent::EWindowGroupChanged: |
|
112 if (KInvalidGroupId != mWindowGroupId) { |
|
113 TakeScreenshot(mWindowGroupId); |
|
114 } |
|
115 mWindowGroupId = event.WindowGroupIdentifier(); |
|
116 break; |
|
117 case TWservCrEvent::EDeviceOrientationChanged: |
|
118 TakeScreenshot(mWindowGroupId); |
|
119 break; |
|
120 } |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CTsScreenshotPlugin::TakeScreenshot(TInt id) |
|
128 { |
|
129 TRAP_IGNORE(TakeScreenshotL(id);) |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CTsScreenshotPlugin::TakeScreenshotL(TInt id) |
|
137 { |
|
138 if(0 >= Env().ScreenCount()) { |
|
139 User::Leave(KErrCorrupt); |
|
140 } |
|
141 const TInt screenId(0); //use local variable in case of changing screen selection policy |
|
142 const MWsScreenConfig* const screenConfig = |
|
143 Env().Screen(screenId)->ObjectInterface<MWsScreenConfig>(); |
|
144 const MWsScreenDevice* const screenDevice = |
|
145 static_cast<MWsScreenDevice*>(Env().Screen(screenId)->ResolveObjectInterface(MWsScreenDevice::EWsObjectInterfaceId)); |
|
146 |
|
147 User::LeaveIfNull(screenConfig); |
|
148 User::LeaveIfNull(screenDevice); |
|
149 |
|
150 //prepare destination bitmap |
|
151 CFbsBitmap *bitmap = new (ELeave) CFbsBitmap(); |
|
152 CleanupStack::PushL(bitmap); |
|
153 |
|
154 |
|
155 User::LeaveIfError(bitmap->Create(screenConfig->SizeInPixels(), |
|
156 screenConfig->DisplayMode())); |
|
157 |
|
158 screenDevice->CopyScreenToBitmapL(bitmap, |
|
159 screenConfig->SizeInPixels()); |
|
160 |
|
161 |
|
162 //prepare and send message |
|
163 RBuf8 message; |
|
164 CleanupClosePushL(message); |
|
165 message.CreateL(CTsScreenshotMsg::size() + sizeof(TInt)); |
|
166 RDesWriteStream stream(message); |
|
167 CleanupClosePushL(stream); |
|
168 stream.WriteInt32L(RegisterScreenshotMessage); |
|
169 CTsScreenshotMsg * screenshotMsg = CTsScreenshotMsg::NewLC(id, *bitmap, Low); |
|
170 stream << (*screenshotMsg); |
|
171 CleanupStack::PopAndDestroy(screenshotMsg); |
|
172 CleanupStack::PopAndDestroy(&stream); |
|
173 User::LeaveIfError(SendMessage(message)); |
|
174 CleanupStack::PopAndDestroy(&message); |
|
175 mCache.AppendL(bitmap); |
|
176 CleanupStack::Pop(bitmap); |
|
177 } |
|
178 |