| 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_COMMON_IMAGE_CACHE_H_ |
| 6 #define EMBEDDERS_OPENGLUI_COMMON_IMAGE_CACHE_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include "embedders/openglui/common/log.h" |
| 11 #include "embedders/openglui/common/opengl.h" |
| 12 #include "embedders/openglui/common/support.h" |
| 13 |
| 14 class ImageCache { |
| 15 public: |
| 16 static void Init(const char *resource_path) { |
| 17 if (instance_ == NULL) { |
| 18 instance_ = new ImageCache(resource_path); |
| 19 } |
| 20 } |
| 21 |
| 22 inline static const SkBitmap* GetImage(const char* src_url) { |
| 23 if (instance_ == NULL) { |
| 24 fprintf(stderr, "GetImage called with no instance_\n"); |
| 25 return NULL; |
| 26 } |
| 27 return instance_->GetImage_(src_url); |
| 28 } |
| 29 |
| 30 inline static int GetWidth(const char* src_url) { |
| 31 if (instance_ == NULL) { |
| 32 fprintf(stderr, "GetWidth called with no instance_\n"); |
| 33 return NULL; |
| 34 } |
| 35 return instance_->GetWidth_(src_url); |
| 36 } |
| 37 |
| 38 inline static int GetHeight(const char* src_url) { |
| 39 if (instance_ == NULL) { |
| 40 fprintf(stderr, "GetHeight called with no instance_\n"); |
| 41 return NULL; |
| 42 } |
| 43 return instance_->GetHeight_(src_url); |
| 44 } |
| 45 |
| 46 private: |
| 47 explicit ImageCache(const char* resource_path); |
| 48 SkBitmap* Load(const char* src_url); |
| 49 const SkBitmap* GetImage_(const char* src_url); |
| 50 int GetWidth_(const char* src_url); |
| 51 int GetHeight_(const char* src_url); |
| 52 |
| 53 std::map<std::string, SkBitmap*> images; |
| 54 const char* resource_path_; |
| 55 static ImageCache* instance_; |
| 56 }; |
| 57 |
| 58 #endif // EMBEDDERS_OPENGLUI_COMMON_IMAGE_CACHE_H_ |
| OLD | NEW |