First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include <graphics/surfaceupdateclient.h>
22 #include "surfaceupdate.h"
24 inline void SurfaceUpdateAssert(TInt aCond) {__ASSERT_ALWAYS(aCond, User::Panic(_L("surfaceupdateclient.cpp; assertion failed"), __LINE__));}
26 EXPORT_C RSurfaceUpdateSession::RSurfaceUpdateSession() :
28 iStatusAvailable(NULL), iStatusDisplayed(NULL), iStatusDisplayedXTimes(NULL), iTimeStamp(NULL), iCount(0)
32 EXPORT_C TInt RSurfaceUpdateSession::Connect(TInt aMessageSlots)
36 return KErrAlreadyExists;
38 iStatusAvailable = NULL;
39 iStatusDisplayed = NULL;
40 iStatusDisplayedXTimes = NULL;
42 //establish connection to the server
43 #ifndef TEST_SURFACE_UPDATE
44 return CreateSession(KSurfaceUpdateServerName, Version(), aMessageSlots);
46 return CreateSession(KTestSurfaceUpdateServerName, Version(), aMessageSlots);
50 EXPORT_C void RSurfaceUpdateSession::Close()
56 iStatusAvailable = NULL;
57 iStatusDisplayed = NULL;
58 iStatusDisplayedXTimes = NULL;
61 EXPORT_C TInt RSurfaceUpdateSession::SubmitUpdate(TInt aScreen, const TSurfaceId& aSurfaceId,
62 TInt aBuffer, const TRegion* aDirtyRegion)
64 SurfaceUpdateAssert(Handle() != KNullHandle);
67 if (aScreen != KAllScreens)
68 RDebug::Printf("You should use KAllScreens as the argument for the screen: (other values OK for test)");
71 if(aScreen < 0 || aBuffer < 0 || aSurfaceId.IsNull())
73 IssueRequestComplete(KErrArgument);
78 SendReceive(EUpdateServNotifyWhenAvailable, *iStatusAvailable);
79 iStatusAvailable= NULL;
84 TIpcArgs args(iTimeStamp);
85 SendReceive(EUpdateServNotifyWhenDisplayed, args, *iStatusDisplayed);
86 iStatusDisplayed=NULL;
89 if(iStatusDisplayedXTimes)
93 User::RequestComplete(iStatusDisplayedXTimes, KErrArgument);
97 TIpcArgs args(iCount);
98 SendReceive(EUpdateServNotifyWhenDisplayedXTimes,
99 args, *iStatusDisplayedXTimes);
101 iStatusDisplayedXTimes=NULL;
104 TPckgC<TSurfaceId> pckgSurfaceId(aSurfaceId);
105 TIpcArgs theArgs(aScreen, &pckgSurfaceId, aBuffer);
109 const TInt regionCount = aDirtyRegion->Count();
112 TPtrC8 ptrRect(reinterpret_cast<const TUint8*> (aDirtyRegion->RectangleList()), regionCount * sizeof(TRect));
113 theArgs.Set(3, &ptrRect);
117 //final request for composition
118 return SendReceive(EUpdateServSubmitUpdate, theArgs);
121 EXPORT_C void RSurfaceUpdateSession::NotifyWhenAvailable(TRequestStatus& aStatus)
123 SurfaceUpdateAssert(Handle() != KNullHandle);
124 iStatusAvailable = &aStatus;
127 EXPORT_C void RSurfaceUpdateSession::NotifyWhenDisplayed(TRequestStatus& aStatus, TTimeStamp& aTimeStamp)
129 SurfaceUpdateAssert(Handle() != KNullHandle);
130 iStatusDisplayed = &aStatus;
131 iTimeStamp = &aTimeStamp;
134 EXPORT_C void RSurfaceUpdateSession::NotifyWhenDisplayedXTimes(TInt aCount, TRequestStatus &aStatus)
136 SurfaceUpdateAssert(Handle() != KNullHandle);
137 iStatusDisplayedXTimes = &aStatus;
138 //we will check aCount validity at submission time (in SubmitUpdate)
142 EXPORT_C void RSurfaceUpdateSession::CancelAllUpdateNotifications()
144 SurfaceUpdateAssert(Handle() != KNullHandle);
145 SendReceive(EUpdateServCancelAllNotifications);
146 //Signal calling client's TRequestStatus object if server didn't do that (SubmitUpdate is not called)
147 //if SubmitUpdate is called, server will take care of signaling status object and following line does nothing
148 IssueRequestComplete(KErrCancel);
151 TVersion RSurfaceUpdateSession::Version() const
153 return (TVersion(KSurfaceUpdateServMajorVersionNumber, KSurfaceUpdateServMinorVersionNumber, KSurfaceUpdateServBuildVersionNumber));
157 Helper function to complete all outstanding requests.
159 param - aErr Error code for completion.
161 void RSurfaceUpdateSession::IssueRequestComplete(TInt aErr)
165 User::RequestComplete(iStatusAvailable, aErr);
166 iStatusAvailable= NULL;
171 User::RequestComplete(iStatusDisplayed, aErr);
172 iStatusDisplayed=NULL;
175 if(iStatusDisplayedXTimes)
177 User::RequestComplete(iStatusDisplayedXTimes, aErr);
178 iStatusDisplayedXTimes=NULL;