|
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 #include "Graphics/WSGRAPHICMSGBUF.H" |
|
17 #include "DrawSection.h" |
|
18 |
|
19 const TInt KBufferSize = 1000; |
|
20 |
|
21 /** |
|
22 This uid is used to identify a drawsection in the messagebuffer that is used for IPC. |
|
23 */ |
|
24 const TUid KDrawSection = {0x101F63B2}; |
|
25 |
|
26 /** |
|
27 Creates and returns new drawsection. |
|
28 |
|
29 @return A new instance of CDrawSection. |
|
30 */ |
|
31 CDrawSection* CDrawSection::NewL() |
|
32 { |
|
33 return new (ELeave) CDrawSection; |
|
34 } |
|
35 |
|
36 /** |
|
37 Creates and returns new drawsection. |
|
38 |
|
39 @param aDrawRect The drawrect of the drawsection. |
|
40 @param aBoundingRect The boundingrect of the drawcommands of this section. |
|
41 @param aHasBitmapCommand ETrue if the commandbuffer of this drawsection includes a bitmap command of any sort. |
|
42 @return A new instance of CDrawSection. |
|
43 */ |
|
44 CDrawSection* CDrawSection::NewL(const TRect& aDrawRect, const TRect& aBoundingRect, TBool aHasBitmapCommand) |
|
45 { |
|
46 return new (ELeave) CDrawSection(aDrawRect, aBoundingRect, aHasBitmapCommand); |
|
47 } |
|
48 |
|
49 CDrawSection::CDrawSection() |
|
50 { |
|
51 } |
|
52 |
|
53 CDrawSection::CDrawSection(const TRect& aDrawRect, const TRect& aBoundingRect, TBool aHasBitmapCommand) : iDrawRect(aDrawRect), |
|
54 iBoundingRect(aBoundingRect), iHasBitmapCommand(aHasBitmapCommand), iHasBeenExternalized(EFalse) |
|
55 { |
|
56 } |
|
57 |
|
58 CDrawSection::~CDrawSection() |
|
59 { |
|
60 delete iSectionSegBuf; |
|
61 } |
|
62 |
|
63 /** |
|
64 Sets this drawsection's segmented commandbuffer and takes the ownership of the allocated memory. |
|
65 |
|
66 @param aSegbuf This section's segmented commandbuffer. |
|
67 */ |
|
68 void CDrawSection::SetBuffer(CBufBase* aSegBuf) |
|
69 { |
|
70 __ASSERT_DEBUG(aSegBuf, User::Invariant()); |
|
71 iSectionSegBuf = aSegBuf; |
|
72 } |
|
73 |
|
74 /** |
|
75 Returns this drawsection's segmented commandbuffer. |
|
76 |
|
77 @return this drawsection's segmented commandbuffer. |
|
78 */ |
|
79 CBufBase* CDrawSection::Buffer() const |
|
80 { |
|
81 return iSectionSegBuf; |
|
82 } |
|
83 |
|
84 /** |
|
85 Sets if this drawsection has been externalized anytime. This is used for partial IPC updates. |
|
86 |
|
87 @param aHasBeenExternalized ETrue if this drawsection has been externalized, otherwise EFalse. |
|
88 */ |
|
89 void CDrawSection::SetHasBeenExternalized(TBool aHasBeenExternalized) |
|
90 { |
|
91 iHasBeenExternalized = aHasBeenExternalized; |
|
92 } |
|
93 |
|
94 /** |
|
95 Returns ETrue if this drawsection has been externalized, otherwise EFalse. |
|
96 |
|
97 @return ETrue if this drawsection has been externalized, otherwise EFalse. |
|
98 */ |
|
99 TBool CDrawSection::HasBeenExternalized() const |
|
100 { |
|
101 return iHasBeenExternalized; |
|
102 } |
|
103 |
|
104 /** |
|
105 Compares this drawsection to aDrawSection and check if they are identical. |
|
106 |
|
107 @param aDrawSection The drawsection to compare with. |
|
108 @return ETrue if the drawsections are identical, otherwise EFalse. |
|
109 */ |
|
110 TBool CDrawSection::IsIdentical(const CDrawSection& aDrawSection) const |
|
111 { |
|
112 const TRect drawRect = aDrawSection.DrawRect(); |
|
113 CBufBase* segBuf = aDrawSection.Buffer(); |
|
114 if(!iHasBitmapCommand && iDrawRect.iTl == drawRect.iTl && iDrawRect.iBr == drawRect.iBr && segBuf->Size() == iSectionSegBuf->Size()) |
|
115 { |
|
116 const TInt count = iSectionSegBuf->Size(); |
|
117 for(TInt i = 0; i < count; i++) |
|
118 { |
|
119 const TPtr8 comparePtr = segBuf->Ptr(i); |
|
120 if(iSectionSegBuf->Ptr(i).Compare(segBuf->Ptr(i))) //Not identical |
|
121 return EFalse; |
|
122 |
|
123 i += comparePtr.Size(); |
|
124 } |
|
125 return ETrue; |
|
126 } |
|
127 return EFalse; |
|
128 } |
|
129 |
|
130 /** |
|
131 Returns the drawrect of this drawsection. |
|
132 |
|
133 @return The drawrect of this drawsection. |
|
134 */ |
|
135 TRect CDrawSection::DrawRect() const |
|
136 { |
|
137 return iDrawRect; |
|
138 } |
|
139 |
|
140 /** |
|
141 Externalizes this drawsection to a message buffer to send over IPC. |
|
142 |
|
143 @param aMsgBuf The message buffer to add this drawsection to. |
|
144 */ |
|
145 void CDrawSection::ExternalizeL(RWsGraphicMsgBuf& aMsgBuf) |
|
146 { |
|
147 const TInt length = sizeof(TRect)*2 + iSectionSegBuf->Size(); |
|
148 TPtr8 msgPtr(NULL, 0); |
|
149 User::LeaveIfError(aMsgBuf.Append(KDrawSection, length, msgPtr)); |
|
150 |
|
151 // Add drawRect to aMsgBuf |
|
152 const TPckgBuf<TRect> drawRect(iDrawRect); |
|
153 msgPtr.Append(drawRect); |
|
154 |
|
155 // Add boundingRect to aMsgBuf |
|
156 const TPckgBuf<TRect> boundingRect(iBoundingRect); |
|
157 msgPtr.Append(boundingRect); |
|
158 |
|
159 // Add drawcommands to aMsgBuf |
|
160 TInt count = 0; |
|
161 const TInt sectionSegBufSize = iSectionSegBuf->Size(); |
|
162 while(count < sectionSegBufSize) |
|
163 { |
|
164 TPtr8 ptr = iSectionSegBuf->Ptr(count); |
|
165 msgPtr.Append(ptr); |
|
166 count += ptr.Size(); |
|
167 } |
|
168 } |
|
169 |
|
170 /** |
|
171 Loads a drawsection from externalized data. |
|
172 |
|
173 @param aData The parser for the externalized data. |
|
174 @param aIndex The index of the drawsection in CCommandBuffer::iDrawSections to load from the externalized data. |
|
175 */ |
|
176 TInt CDrawSection::LoadL(const TWsGraphicMsgBufParser& aData, TInt aIndex) |
|
177 { |
|
178 if(aData.Uid(aIndex).iUid != KDrawSection.iUid) |
|
179 { |
|
180 return KErrArgument; |
|
181 } |
|
182 |
|
183 const TPtrC8 pckg = aData.Data(aIndex); |
|
184 const TPtrC8 drawRectPtr = pckg.Left(sizeof(TRect)); |
|
185 const TPtrC8 boundingRectPtr = pckg.Mid(sizeof(TRect), sizeof(TRect)); |
|
186 const TPtrC8 segBufPtr = pckg.Mid(sizeof(TRect)*2); |
|
187 |
|
188 Mem::Copy(&iDrawRect, drawRectPtr.Ptr(), sizeof(TRect)); |
|
189 Mem::Copy(&iBoundingRect, boundingRectPtr.Ptr(), sizeof(TRect)); |
|
190 |
|
191 if(iSectionSegBuf) |
|
192 delete iSectionSegBuf; |
|
193 |
|
194 iSectionSegBuf = CBufSeg::NewL(KBufferSize); |
|
195 iSectionSegBuf->InsertL(0, segBufPtr); |
|
196 return KErrNone; |
|
197 } |
|
198 |