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

Unified Diff: runtime/embedders/openglui/common/canvas_context.cc

Issue 13042015: Various OpenGLUI changes: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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/common/canvas_context.cc
===================================================================
--- runtime/embedders/openglui/common/canvas_context.cc (revision 20570)
+++ runtime/embedders/openglui/common/canvas_context.cc (working copy)
@@ -7,10 +7,11 @@
#include <ctype.h>
#include <string.h>
#include "core/SkStream.h"
+#include "embedders/openglui/common/image_cache.h"
#include "embedders/openglui/common/support.h"
// TODO(gram): this should be dynamic.
-#define MAX_CONTEXTS 16
+#define MAX_CONTEXTS 256
CanvasContext* contexts[MAX_CONTEXTS] = { 0 };
CanvasContext* Context2D(int handle) {
@@ -40,6 +41,10 @@
height_(heightp),
imageSmoothingEnabled_(true),
state_(NULL) {
+ if (handle >= MAX_CONTEXTS) {
+ LOGE("Max contexts exceeded");
+ exit(-1);
+ }
if (handle == 0) {
canvas_ = graphics->CreateDisplayCanvas();
} else {
@@ -55,68 +60,39 @@
delete canvas_;
}
+void CanvasContext::Save() {
+ state_ = state_->Save();
+}
+
+void CanvasContext::Restore() {
+ CanvasState* popped_state = state_;
+ state_ = state_->Restore();
+ if (state_ == NULL) {
+ LOGE("Popping last state!");
+ state_ = popped_state;
+ }
+ if (state_ != popped_state) {
+ // Only delete if the pop was successful.
+ delete popped_state;
+ }
+}
+
void CanvasContext::DrawImage(const char* src_url,
int sx, int sy,
bool has_src_dimensions, int sw, int sh,
int dx, int dy,
bool has_dst_dimensions, int dw, int dh) {
- SkBitmap bm;
- if (strncmp(src_url, "context2d://", 12) == 0) {
- int handle = atoi(src_url + 12);
- CanvasContext* otherContext = Context2D(handle);
- SkDevice* device = otherContext->canvas_->getDevice();
- bm = device->accessBitmap(false);
- } else {
- const char* filepath;
- if (strncmp(src_url, "file://", 7) == 0) {
- filepath = src_url + 7;
- } else {
- // TODO(gram): We need a way to remap URLs to local file names.
- // For now I am just using the characters after the last '/'.
- // Note also that if we want to support URLs and network fetches,
- // then we introduce more complexity; this can't just be an URL.
- int pos = strlen(src_url);
- while (--pos >= 0 && src_url[pos] != '/');
- filepath = src_url + pos + 1;
- }
- char* path;
- if (filepath[0] == '/') {
- path = const_cast<char*>(filepath);
- } else {
- size_t len1 = strlen(graphics->resource_path());
- size_t len2 = strlen(filepath);
- path = new char[len1 + 1 + len2 + 1];
- strncpy(path, graphics->resource_path(), len1+1);
- strncat(path, "/", 1);
- strncat(path, filepath, len2);
- }
- SkFILEStream stream(path);
- if (stream.isValid()) {
- // We could use DecodeFile and pass the path, but by creating the
- // SkStream here we can produce better error log messages.
- if (!SkImageDecoder::DecodeStream(&stream, &bm)) {
- LOGI("Image decode of %s failed", path);
- return;
- } else {
- LOGI("Decode image %s: width=%d,height=%d",
- path, bm.width(), bm.height());
- }
- } else {
- LOGI("Path %s is invalid", path);
- }
- if (path != filepath) {
- delete[] path;
- }
- }
+ const SkBitmap* bm = ImageCache::GetImage(src_url);
+ if (bm == NULL) return;
if (!has_src_dimensions) {
- sw = bm.width();
- sh = bm.height();
+ sw = bm->width();
+ sh = bm->height();
}
if (!has_dst_dimensions) {
- dw = bm.width();
- dh = bm.height();
+ dw = bm->width();
+ dh = bm->height();
}
- state_->DrawImage(bm, sx, sy, sw, sh, dx, dy, dw, dh);
+ state_->DrawImage(*bm, sx, sy, sw, sh, dx, dy, dw, dh);
isDirty_ = true;
}

Powered by Google App Engine
This is Rietveld 408576698