| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 #include "embedders/openglui/common/image_cache.h" | 5 #include "embedders/openglui/common/image_cache.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include "core/SkStream.h" | 9 #include "core/SkStream.h" |
| 10 #include "embedders/openglui/common/canvas_context.h" | 10 #include "embedders/openglui/common/canvas_context.h" |
| 11 | 11 |
| 12 ImageCache* ImageCache::instance_ = NULL; | 12 ImageCache* ImageCache::instance_ = NULL; |
| 13 | 13 |
| 14 extern CanvasContext* Context2D(int handle); | 14 extern CanvasContext* Context2D(int handle); |
| 15 | 15 |
| 16 ImageCache::ImageCache(const char* resource_path) | 16 ImageCache::ImageCache(const char* resource_path) |
| 17 : images(), resource_path_(resource_path) { | 17 : images(), resource_path_(resource_path) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 const SkBitmap* ImageCache::GetImage_(const char* src_url) { | 20 const SkBitmap* ImageCache::GetImage_(const char* src_url) { |
| 21 fprintf(stderr, "ImageCache::GetImage(%s)\n", src_url); | |
| 22 if (strncmp(src_url, "context2d://", 12) == 0) { | 21 if (strncmp(src_url, "context2d://", 12) == 0) { |
| 23 int handle = atoi(src_url + 12); | 22 int handle = atoi(src_url + 12); |
| 24 CanvasContext* otherContext = Context2D(handle); | 23 CanvasContext* otherContext = Context2D(handle); |
| 25 return otherContext->GetBitmap(); | 24 return otherContext->GetBitmap(); |
| 26 } else if (images.find(src_url) == images.end()) { | 25 } else if (images.find(src_url) == images.end()) { |
| 27 SkBitmap* bm = Load(src_url); | 26 SkBitmap* bm = Load(src_url); |
| 28 if (bm != NULL) { | 27 if (bm != NULL) { |
| 29 images[src_url] = bm; | 28 images[src_url] = bm; |
| 30 } | 29 } |
| 31 return bm; | 30 return bm; |
| 32 } else { | 31 } else { |
| 33 return images[src_url]; | 32 return images[src_url]; |
| 34 } | 33 } |
| 35 } | 34 } |
| 36 | 35 |
| 37 int ImageCache::GetWidth_(const char* src_url) { | 36 int ImageCache::GetWidth_(const char* src_url) { |
| 38 fprintf(stderr, "ImageCache::GetWidth(%s)\n", src_url); | |
| 39 const SkBitmap* image = GetImage(src_url); | 37 const SkBitmap* image = GetImage(src_url); |
| 40 if (image == NULL) return 0; | 38 if (image == NULL) return 0; |
| 41 return image->width(); | 39 return image->width(); |
| 42 } | 40 } |
| 43 | 41 |
| 44 int ImageCache::GetHeight_(const char* src_url) { | 42 int ImageCache::GetHeight_(const char* src_url) { |
| 45 fprintf(stderr, "ImageCache::GetHeight(%s)\n", src_url); | |
| 46 const SkBitmap* image = GetImage(src_url); | 43 const SkBitmap* image = GetImage(src_url); |
| 47 if (image == NULL) return 0; | 44 if (image == NULL) return 0; |
| 48 return image->height(); | 45 return image->height(); |
| 49 } | 46 } |
| 50 | 47 |
| 51 SkBitmap* ImageCache::Load(const char* src_url) { | 48 SkBitmap* ImageCache::Load(const char* src_url) { |
| 52 fprintf(stderr, "ImageCache::Load(%s)\n", src_url); | |
| 53 SkBitmap *bm = NULL; | 49 SkBitmap *bm = NULL; |
| 54 const char* filepath; | 50 const char* filepath; |
| 55 if (strncmp(src_url, "file://", 7) == 0) { | 51 if (strncmp(src_url, "file://", 7) == 0) { |
| 56 filepath = src_url + 7; | 52 filepath = src_url + 7; |
| 57 } else { | 53 } else { |
| 58 // TODO(gram): We need a way to remap URLs to local file names. | 54 // TODO(gram): We need a way to remap URLs to local file names. |
| 59 // For now I am just using the characters after the last '/'. | 55 // For now I am just using the characters after the last '/'. |
| 60 // Note also that if we want to support URLs and network fetches, | 56 // Note also that if we want to support URLs and network fetches, |
| 61 // then we introduce more complexity; this can't just be an URL. | 57 // then we introduce more complexity; this can't just be an URL. |
| 62 int pos = strlen(src_url); | 58 int pos = strlen(src_url); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 90 } else { | 86 } else { |
| 91 LOGI("Path %s is invalid", path); | 87 LOGI("Path %s is invalid", path); |
| 92 } | 88 } |
| 93 | 89 |
| 94 if (path != filepath) { | 90 if (path != filepath) { |
| 95 delete[] path; | 91 delete[] path; |
| 96 } | 92 } |
| 97 return bm; | 93 return bm; |
| 98 } | 94 } |
| 99 | 95 |
| OLD | NEW |