|
1 // Copyright (c) 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 // Graphics Resource - kernel resource implementation |
|
15 // |
|
16 |
|
17 #include <kernel/kern_priv.h> |
|
18 #include "sgextensionimpl.h" |
|
19 |
|
20 DSgResourceImpl::DSgResourceImpl(DSgExtensionImpl& aExtensionImpl, TUint64 aId, TUint32 aAttribs, |
|
21 const TDesC8& aMetaData, DChunk* aDataChunk, TInt aDataSize) |
|
22 : iExtensionImpl(aExtensionImpl), iRefCount(1), iId(aId), iAttributes(aAttribs), |
|
23 iMetaDataSize(aMetaData.Size()), iDataChunk(aDataChunk), iDataSize(aDataSize) |
|
24 { |
|
25 memcpy(this + 1, aMetaData.Ptr(), aMetaData.Size()); |
|
26 } |
|
27 |
|
28 DSgResourceImpl::~DSgResourceImpl() |
|
29 { |
|
30 if (iDataChunk) |
|
31 { |
|
32 Kern::ChunkClose(iDataChunk); |
|
33 } |
|
34 } |
|
35 |
|
36 TInt DSgResourceImpl::Open() |
|
37 { |
|
38 return NKern::SafeInc(iRefCount) > 0 ? KErrNone : KErrNotFound; |
|
39 } |
|
40 |
|
41 void DSgResourceImpl::Close() |
|
42 { |
|
43 if (NKern::SafeDec(iRefCount) == 1) |
|
44 { |
|
45 iExtensionImpl.DeleteResource(this); |
|
46 } |
|
47 } |
|
48 |
|
49 TUint64 DSgResourceImpl::Id() const |
|
50 { |
|
51 return iId; |
|
52 } |
|
53 |
|
54 TUint32 DSgResourceImpl::Attributes() const |
|
55 { |
|
56 return iAttributes; |
|
57 } |
|
58 |
|
59 TInt DSgResourceImpl::GetMetaData(TDes8& aMetaData) const |
|
60 { |
|
61 if (aMetaData.MaxSize() < iMetaDataSize) |
|
62 { |
|
63 return KErrOverflow; |
|
64 } |
|
65 if (iMetaDataSize == 0) |
|
66 { |
|
67 aMetaData.Zero(); |
|
68 } |
|
69 else |
|
70 { |
|
71 aMetaData.Copy(TPtrC8(reinterpret_cast<const TUint8*>(this + 1), iMetaDataSize)); |
|
72 } |
|
73 return KErrNone; |
|
74 } |
|
75 |
|
76 DChunk* DSgResourceImpl::DataChunk() const |
|
77 { |
|
78 return iDataChunk; |
|
79 } |
|
80 |
|
81 TInt DSgResourceImpl::DataSize() const |
|
82 { |
|
83 return iDataSize; |
|
84 } |