|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 */ |
|
19 |
|
20 #include <graphics/surfaceupdateclient.h> |
|
21 #include "surfaceupdate.h" |
|
22 |
|
23 inline void SurfaceUpdateAssert(TInt aCond) {__ASSERT_ALWAYS(aCond, User::Panic(_L("surfaceupdateclient.cpp; assertion failed"), __LINE__));} |
|
24 |
|
25 EXPORT_C RSurfaceUpdateSession::RSurfaceUpdateSession() : |
|
26 RSessionBase(), |
|
27 iStatusAvailable(NULL), iStatusDisplayed(NULL), iStatusDisplayedXTimes(NULL) |
|
28 { |
|
29 } |
|
30 |
|
31 EXPORT_C TInt RSurfaceUpdateSession::Connect(TInt aMessageSlots) |
|
32 { |
|
33 if(Handle()) |
|
34 { |
|
35 return KErrAlreadyExists; |
|
36 } |
|
37 iStatusAvailable = NULL; |
|
38 iStatusDisplayed = NULL; |
|
39 iStatusDisplayedXTimes = NULL; |
|
40 |
|
41 //establish connection to the server |
|
42 #ifndef TEST_SURFACE_UPDATE |
|
43 return CreateSession(KSurfaceUpdateServerName, Version(), aMessageSlots); |
|
44 #else |
|
45 return CreateSession(KTestSurfaceUpdateServerName, Version(), aMessageSlots); |
|
46 #endif |
|
47 } |
|
48 |
|
49 EXPORT_C void RSurfaceUpdateSession::Close() |
|
50 { |
|
51 if(Handle()) |
|
52 { |
|
53 RHandleBase::Close(); |
|
54 } |
|
55 iStatusAvailable = NULL; |
|
56 iStatusDisplayed = NULL; |
|
57 iStatusDisplayedXTimes = NULL; |
|
58 } |
|
59 |
|
60 EXPORT_C TInt RSurfaceUpdateSession::SubmitUpdate(TInt aScreen, const TSurfaceId& aSurfaceId, |
|
61 TInt aBuffer, const TRegion* aDirtyRegion) |
|
62 { |
|
63 SurfaceUpdateAssert(Handle() != KNullHandle); |
|
64 |
|
65 if(aScreen < 0 || aBuffer < 0 || aSurfaceId.IsNull()) |
|
66 { |
|
67 IssueRequestComplete(KErrArgument); |
|
68 return KErrArgument; |
|
69 } |
|
70 if(iStatusAvailable) |
|
71 { |
|
72 SendReceive(EUpdateServNotifyWhenAvailable, *iStatusAvailable); |
|
73 iStatusAvailable= NULL; |
|
74 } |
|
75 |
|
76 if(iStatusDisplayed) |
|
77 { |
|
78 TIpcArgs args(iTimeStamp); |
|
79 SendReceive(EUpdateServNotifyWhenDisplayed, args, *iStatusDisplayed); |
|
80 iStatusDisplayed=NULL; |
|
81 } |
|
82 |
|
83 if(iStatusDisplayedXTimes) |
|
84 { |
|
85 if(iCount <= 0) |
|
86 { |
|
87 User::RequestComplete(iStatusDisplayedXTimes, KErrArgument); |
|
88 } |
|
89 else |
|
90 { |
|
91 TIpcArgs args(iCount); |
|
92 SendReceive(EUpdateServNotifyWhenDisplayedXTimes, |
|
93 args, *iStatusDisplayedXTimes); |
|
94 } |
|
95 iStatusDisplayedXTimes=NULL; |
|
96 } |
|
97 |
|
98 TPckgC<TSurfaceId> pckgSurfaceId(aSurfaceId); |
|
99 TIpcArgs theArgs(aScreen, &pckgSurfaceId, aBuffer); |
|
100 |
|
101 if(aDirtyRegion) |
|
102 { |
|
103 const TInt regionCount = aDirtyRegion->Count(); |
|
104 if(regionCount > 0) |
|
105 { |
|
106 TPtrC8 ptrRect(reinterpret_cast<const TUint8*> (aDirtyRegion->RectangleList()), regionCount * sizeof(TRect)); |
|
107 theArgs.Set(3, &ptrRect); |
|
108 } |
|
109 } |
|
110 |
|
111 //final request for composition |
|
112 return SendReceive(EUpdateServSubmitUpdate, theArgs); |
|
113 } |
|
114 |
|
115 EXPORT_C void RSurfaceUpdateSession::NotifyWhenAvailable(TRequestStatus& aStatus) |
|
116 { |
|
117 SurfaceUpdateAssert(Handle() != KNullHandle); |
|
118 iStatusAvailable = &aStatus; |
|
119 } |
|
120 |
|
121 EXPORT_C void RSurfaceUpdateSession::NotifyWhenDisplayed(TRequestStatus& aStatus, TTimeStamp& aTimeStamp) |
|
122 { |
|
123 SurfaceUpdateAssert(Handle() != KNullHandle); |
|
124 iStatusDisplayed = &aStatus; |
|
125 iTimeStamp = &aTimeStamp; |
|
126 } |
|
127 |
|
128 EXPORT_C void RSurfaceUpdateSession::NotifyWhenDisplayedXTimes(TInt aCount, TRequestStatus &aStatus) |
|
129 { |
|
130 SurfaceUpdateAssert(Handle() != KNullHandle); |
|
131 iStatusDisplayedXTimes = &aStatus; |
|
132 //we will check aCount validity at submission time (in SubmitUpdate) |
|
133 iCount = aCount; |
|
134 } |
|
135 |
|
136 EXPORT_C void RSurfaceUpdateSession::CancelAllUpdateNotifications() |
|
137 { |
|
138 SurfaceUpdateAssert(Handle() != KNullHandle); |
|
139 SendReceive(EUpdateServCancelAllNotifications); |
|
140 //Signal calling client's TRequestStatus object if server didn't do that (SubmitUpdate is not called) |
|
141 //if SubmitUpdate is called, server will take care of signaling status object and following line does nothing |
|
142 IssueRequestComplete(KErrCancel); |
|
143 } |
|
144 |
|
145 TVersion RSurfaceUpdateSession::Version() const |
|
146 { |
|
147 return (TVersion(KSurfaceUpdateServMajorVersionNumber, KSurfaceUpdateServMinorVersionNumber, KSurfaceUpdateServBuildVersionNumber)); |
|
148 } |
|
149 |
|
150 /* |
|
151 Helper function to complete all outstanding requests. |
|
152 |
|
153 param - aErr Error code for completion. |
|
154 */ |
|
155 void RSurfaceUpdateSession::IssueRequestComplete(TInt aErr) |
|
156 { |
|
157 if(iStatusAvailable) |
|
158 { |
|
159 User::RequestComplete(iStatusAvailable, aErr); |
|
160 iStatusAvailable= NULL; |
|
161 } |
|
162 |
|
163 if(iStatusDisplayed) |
|
164 { |
|
165 User::RequestComplete(iStatusDisplayed, aErr); |
|
166 iStatusDisplayed=NULL; |
|
167 } |
|
168 |
|
169 if(iStatusDisplayedXTimes) |
|
170 { |
|
171 User::RequestComplete(iStatusDisplayedXTimes, aErr); |
|
172 iStatusDisplayedXTimes=NULL; |
|
173 } |
|
174 } |