1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Resource wrapper for AAssetManager.
22 *//*--------------------------------------------------------------------*/
23
24 #include "tcuAndroidAssets.hpp"
25
26 namespace tcu
27 {
28 namespace Android
29 {
30
AssetArchive(AAssetManager * assetMgr)31 AssetArchive::AssetArchive (AAssetManager* assetMgr)
32 : m_assetMgr(assetMgr)
33 {
34 }
35
~AssetArchive(void)36 AssetArchive::~AssetArchive (void)
37 {
38 }
39
getResource(const char * name) const40 Resource* AssetArchive::getResource (const char* name) const
41 {
42 return new AssetResource(m_assetMgr, name);
43 }
44
AssetResource(AAssetManager * assetMgr,const char * name)45 AssetResource::AssetResource (AAssetManager* assetMgr, const char* name)
46 : Resource (name)
47 , m_asset (DE_NULL)
48 {
49 m_asset = AAssetManager_open(assetMgr, name, AASSET_MODE_RANDOM);
50 TCU_CHECK(m_asset);
51 }
52
~AssetResource(void)53 AssetResource::~AssetResource (void)
54 {
55 AAsset_close(m_asset);
56 }
57
read(deUint8 * dst,int numBytes)58 void AssetResource::read (deUint8* dst, int numBytes)
59 {
60 TCU_CHECK(AAsset_read(m_asset, dst, numBytes) == numBytes);
61 }
62
getPosition(void) const63 int AssetResource::getPosition (void) const
64 {
65 return (int)AAsset_getLength(m_asset) - (int)AAsset_getRemainingLength(m_asset);
66 }
67
setPosition(int position)68 void AssetResource::setPosition (int position)
69 {
70 TCU_CHECK(AAsset_seek(m_asset, position, SEEK_SET) == position);
71 }
72
isFinished(void) const73 bool AssetResource::isFinished (void) const
74 {
75 return AAsset_getRemainingLength(m_asset) <= 0;
76 }
77
getSize(void) const78 int AssetResource::getSize (void) const
79 {
80 return (int)AAsset_getLength(m_asset);
81 }
82
83 } // Android
84 } // tcu
85