OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef EMBEDDERS_OPENGLUI_ANDROID_ANDROID_RESOURCE_H_ |
| 6 #define EMBEDDERS_OPENGLUI_ANDROID_ANDROID_RESOURCE_H_ |
| 7 |
| 8 #include <android_native_app_glue.h> |
| 9 |
| 10 #include "embedders/openglui/common/log.h" |
| 11 #include "embedders/openglui/common/resource.h" |
| 12 |
| 13 class AndroidResource : public Resource { |
| 14 public: |
| 15 AndroidResource(android_app* application, const char* path) |
| 16 : Resource(path), |
| 17 asset_manager_(application->activity->assetManager), |
| 18 asset_(NULL) { |
| 19 } |
| 20 |
| 21 int32_t descriptor() { |
| 22 if (Open() == 0) { |
| 23 descriptor_ = AAsset_openFileDescriptor(asset_, &start_, &length_); |
| 24 LOGI("%s has start %d, length %d, fd %d", |
| 25 path_, static_cast<int>(start_), static_cast<int>(length_), |
| 26 descriptor_); |
| 27 return descriptor_; |
| 28 } |
| 29 return -1; |
| 30 } |
| 31 |
| 32 off_t length() { |
| 33 if (length_ < 0) { |
| 34 length_ = AAsset_getLength(asset_); |
| 35 } |
| 36 return length_; |
| 37 } |
| 38 |
| 39 int32_t Open() { |
| 40 LOGI("Attempting to open asset %s", path_); |
| 41 asset_ = AAssetManager_open(asset_manager_, path_, AASSET_MODE_UNKNOWN); |
| 42 if (asset_ != NULL) { |
| 43 return 0; |
| 44 } |
| 45 LOGE("Could not open asset %s", path_); |
| 46 return -1; |
| 47 } |
| 48 |
| 49 void Close() { |
| 50 if (asset_ != NULL) { |
| 51 AAsset_close(asset_); |
| 52 asset_ = NULL; |
| 53 } |
| 54 } |
| 55 |
| 56 int32_t Read(void* buffer, size_t count) { |
| 57 size_t actual = AAsset_read(asset_, buffer, count); |
| 58 return (actual == count) ? 0 : -1; |
| 59 } |
| 60 |
| 61 private: |
| 62 AAssetManager* asset_manager_; |
| 63 AAsset* asset_; |
| 64 }; |
| 65 |
| 66 #endif // EMBEDDERS_OPENGLUI_ANDROID_ANDROID_RESOURCE_H_ |
| 67 |
OLD | NEW |