Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: runtime/embedders/openglui/android/android_resource.h

Issue 11883013: Refactored OpenGL embedder that works on Android, Mac or Linux. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/embedders/openglui/android/android_resource.h
===================================================================
--- runtime/embedders/openglui/android/android_resource.h (revision 0)
+++ runtime/embedders/openglui/android/android_resource.h (revision 0)
@@ -0,0 +1,67 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef EMBEDDERS_OPENGLUI_ANDROID_ANDROID_RESOURCE_H_
+#define EMBEDDERS_OPENGLUI_ANDROID_ANDROID_RESOURCE_H_
+
+#include <android_native_app_glue.h>
+
+#include "embedders/openglui/common/log.h"
+#include "embedders/openglui/common/resource.h"
+
+class AndroidResource : public Resource {
+ public:
+ AndroidResource(android_app* application, const char* path)
+ : Resource(path),
+ asset_manager_(application->activity->assetManager),
+ asset_(NULL) {
+ }
+
+ int32_t descriptor() {
+ if (Open() == 0) {
+ descriptor_ = AAsset_openFileDescriptor(asset_, &start_, &length_);
+ LOGI("%s has start %d, length %d, fd %d",
+ path_, static_cast<int>(start_), static_cast<int>(length_),
+ descriptor_);
+ return descriptor_;
+ }
+ return -1;
+ }
+
+ off_t length() {
+ if (length_ < 0) {
+ length_ = AAsset_getLength(asset_);
+ }
+ return length_;
+ }
+
+ int32_t Open() {
+ LOGI("Attempting to open asset %s", path_);
+ asset_ = AAssetManager_open(asset_manager_, path_, AASSET_MODE_UNKNOWN);
+ if (asset_ != NULL) {
+ return 0;
+ }
+ LOGE("Could not open asset %s", path_);
+ return -1;
+ }
+
+ void Close() {
+ if (asset_ != NULL) {
+ AAsset_close(asset_);
+ asset_ = NULL;
+ }
+ }
+
+ int32_t Read(void* buffer, size_t count) {
+ size_t actual = AAsset_read(asset_, buffer, count);
+ return (actual == count) ? 0 : -1;
+ }
+
+ private:
+ AAssetManager* asset_manager_;
+ AAsset* asset_;
+};
+
+#endif // EMBEDDERS_OPENGLUI_ANDROID_ANDROID_RESOURCE_H_
+
« no previous file with comments | « runtime/embedders/openglui/android/android_log.h ('k') | runtime/embedders/openglui/android/android_sound_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698