1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Resource wrapper for AAssetManager.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuAndroidAssets.hpp"
31 AssetArchive::AssetArchive (AAssetManager* assetMgr)
32 : m_assetMgr(assetMgr)
36 AssetArchive::~AssetArchive (void)
40 Resource* AssetArchive::getResource (const char* name) const
42 return new AssetResource(m_assetMgr, name);
45 AssetResource::AssetResource (AAssetManager* assetMgr, const char* name)
49 m_asset = AAssetManager_open(assetMgr, name, AASSET_MODE_RANDOM);
52 throw ResourceError("Failed to open asset resource", name, __FILE__, __LINE__);
55 AssetResource::~AssetResource (void)
57 AAsset_close(m_asset);
60 void AssetResource::read (deUint8* dst, int numBytes)
62 TCU_CHECK(AAsset_read(m_asset, dst, numBytes) == numBytes);
65 int AssetResource::getPosition (void) const
67 return (int)AAsset_getLength(m_asset) - (int)AAsset_getRemainingLength(m_asset);
70 void AssetResource::setPosition (int position)
72 TCU_CHECK(AAsset_seek(m_asset, position, SEEK_SET) == position);
75 bool AssetResource::isFinished (void) const
77 return AAsset_getRemainingLength(m_asset) <= 0;
80 int AssetResource::getSize (void) const
82 return (int)AAsset_getLength(m_asset);