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

Unified Diff: runtime/embedders/openglui/emulator/emulator_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/emulator/emulator_resource.h
===================================================================
--- runtime/embedders/openglui/emulator/emulator_resource.h (revision 0)
+++ runtime/embedders/openglui/emulator/emulator_resource.h (revision 0)
@@ -0,0 +1,63 @@
+// Copyright (c) 2013, 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_EMULATOR_EMULATOR_RESOURCE_H_
+#define EMBEDDERS_OPENGLUI_EMULATOR_EMULATOR_RESOURCE_H_
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "embedders/openglui/common/log.h"
+#include "embedders/openglui/common/resource.h"
+
+class EmulatorResource : public Resource {
+ public:
+ explicit EmulatorResource(const char* path)
+ : base(path),
+ fd_(-1) {
+ }
+
+ int32_t descriptor() {
+ if (fd_ < 0) {
+ Open();
+ }
+ return fd_;
+ }
+
+ off_t length() {
+ if (length_ < 0) {
+ length_ = lseek(fd), 0, SEEK_END);
+ lseek(fd), 0, SEEK_START);
+ }
+ return length_;
+ }
+
+ int32_t Open() {
+ fd_ = open(path_, 0);
+ if (fd_ >= 0) {
+ return 0;
+ }
+ LOGE("Could not open asset %s", path_);
+ return -1;
+ }
+
+ void Close() {
+ if (fd_ >= 0) {
+ close(fd_);
+ fd_ = -1;
+ }
+ }
+
+ int32_t Read(void* buffer, size_t count) {
+ size_t actual = read(asset_, buffer, count);
+ return (actual == count) ? 0 : -1;
+ }
+
+ private:
+ int fd_;
+};
+
+#endif // EMBEDDERS_OPENGLUI_EMULATOR_EMULATOR_RESOURCE_H_
+
« no previous file with comments | « runtime/embedders/openglui/emulator/emulator_graphics_handler.cc ('k') | runtime/embedders/openglui/openglui_embedder.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698