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

Side by Side Diff: runtime/embedders/openglui/common/sample.h

Issue 13042015: Various OpenGLUI changes: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_ 5 #ifndef EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_
6 #define EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_ 6 #define EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_
7 7
8 #include "embedders/openglui/common/resource.h" 8 #include "embedders/openglui/common/resource.h"
9 9
10 extern Resource* MakePlatformResource(const char *path);
11
10 class Sample { 12 class Sample {
11 public: 13 public:
12 explicit Sample(const char* path) 14 explicit Sample(const char* path)
13 : resource_(path), 15 : buffer_(NULL),
14 buffer_(NULL),
15 length_(0) { 16 length_(0) {
17 resource_ = MakePlatformResource(path);
16 } 18 }
17 19
18 ~Sample() { 20 ~Sample() {
19 Unload(); 21 Unload();
22 delete resource_;
20 } 23 }
21 24
22 const char* path() { 25 const char* path() {
23 return resource_.path(); 26 return resource_->path();
24 } 27 }
25 28
26 uint8_t* buffer() { 29 uint8_t* buffer() {
27 return buffer_; 30 return buffer_;
28 } 31 }
29 32
30 off_t length() { 33 off_t length() {
31 return length_; 34 return length_;
32 } 35 }
33 36
34 int32_t Load() { 37 int32_t Load() {
35 int32_t rtn = -1; 38 int32_t rtn = -1;
36 if (resource_.Open() == 0) { 39 if (resource_->Open() == 0) {
37 buffer_ = new uint8_t[length_ = resource_.length()]; 40 buffer_ = new uint8_t[length_ = resource_->length()];
38 rtn = resource_.Read(buffer_, length_); 41 rtn = resource_->Read(buffer_, length_);
39 resource_.Close(); 42 resource_->Close();
40 } 43 }
41 return rtn; 44 return rtn;
42 } 45 }
43 46
44 void Unload() { 47 void Unload() {
45 if (buffer_ != NULL) { 48 if (buffer_ != NULL) {
46 delete[] buffer_; 49 delete[] buffer_;
47 buffer_ = NULL; 50 buffer_ = NULL;
48 } 51 }
49 length_ = 0; 52 length_ = 0;
50 } 53 }
51 54
52 private: 55 private:
53 friend class SoundService; 56 friend class SoundService;
54 Resource resource_; 57 Resource* resource_;
55 uint8_t* buffer_; 58 uint8_t* buffer_;
56 off_t length_; 59 off_t length_;
57 }; 60 };
58 61
59 #endif // EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_ 62 #endif // EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_
60 63
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698