| 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 #include "embedders/openglui/common/canvas_context.h" |
| 6 |
| 7 #include <ctype.h> |
| 8 #include <string.h> |
| 9 |
| 10 #include "embedders/openglui/common/support.h" |
| 11 |
| 12 CanvasContext::CanvasContext(int16_t widthp, int16_t heightp) |
| 13 : canvas_(NULL), |
| 14 width_(widthp), |
| 15 height_(heightp), |
| 16 imageSmoothingEnabled_(true), |
| 17 state_(NULL) { |
| 18 } |
| 19 |
| 20 CanvasContext::~CanvasContext() { |
| 21 delete state_; |
| 22 delete canvas_; |
| 23 } |
| 24 |
| 25 void CanvasContext::Create() { |
| 26 canvas_ = graphics->CreateCanvas(); |
| 27 state_ = new CanvasState(canvas_); |
| 28 } |
| 29 |
| 30 void CanvasContext::DrawImage(const char* src_url, |
| 31 int sx, int sy, |
| 32 bool has_src_dimensions, int sw, int sh, |
| 33 int dx, int dy, |
| 34 bool has_dst_dimensions, int dw, int dh) { |
| 35 SkBitmap bm; |
| 36 // TODO(gram): We need a way to remap URLs to local file names. |
| 37 // For now I am just using the characters after the last '/'. |
| 38 // Note also that if we want to support URLs and network fetches, |
| 39 // then we introduce more complexity; this can't just be an URL. |
| 40 int pos = strlen(src_url); |
| 41 while (--pos >= 0 && src_url[pos] != '/'); |
| 42 const char *path = src_url + pos + 1; |
| 43 if (!SkImageDecoder::DecodeFile(path, &bm)) { |
| 44 LOGI("Image decode of %s failed", path); |
| 45 } else { |
| 46 LOGI("Decode image: width=%d,height=%d", bm.width(), bm.height()); |
| 47 if (!has_src_dimensions) { |
| 48 sw = bm.width(); |
| 49 sh = bm.height(); |
| 50 } |
| 51 if (!has_dst_dimensions) { |
| 52 dw = bm.width(); |
| 53 dh = bm.height(); |
| 54 } |
| 55 state_->DrawImage(bm, sx, sy, sw, sh, dx, dy, dw, dh); |
| 56 } |
| 57 } |
| 58 |
| 59 void CanvasContext::ClearRect(float left, float top, |
| 60 float width, float height) { |
| 61 SkPaint paint; |
| 62 paint.setStyle(SkPaint::kFill_Style); |
| 63 paint.setColor(0xFFFFFFFF); |
| 64 canvas_->drawRectCoords(left, top, left + width, top + height, paint); |
| 65 } |
| 66 |
| OLD | NEW |