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 26namespace tcu 27{ 28namespace Android 29{ 30 31AssetArchive::AssetArchive (AAssetManager* assetMgr) 32 : m_assetMgr(assetMgr) 33{ 34} 35 36AssetArchive::~AssetArchive (void) 37{ 38} 39 40Resource* AssetArchive::getResource (const char* name) const 41{ 42 return new AssetResource(m_assetMgr, name); 43} 44 45AssetResource::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 53AssetResource::~AssetResource (void) 54{ 55 AAsset_close(m_asset); 56} 57 58void AssetResource::read (deUint8* dst, int numBytes) 59{ 60 TCU_CHECK(AAsset_read(m_asset, dst, numBytes) == numBytes); 61} 62 63int AssetResource::getPosition (void) const 64{ 65 return (int)AAsset_getLength(m_asset) - (int)AAsset_getRemainingLength(m_asset); 66} 67 68void AssetResource::setPosition (int position) 69{ 70 TCU_CHECK(AAsset_seek(m_asset, position, SEEK_SET) == position); 71} 72 73bool AssetResource::isFinished (void) const 74{ 75 return AAsset_getRemainingLength(m_asset) <= 0; 76} 77 78int AssetResource::getSize (void) const 79{ 80 return (int)AAsset_getLength(m_asset); 81} 82 83} // Android 84} // tcu 85