| 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 #ifndef EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_ | 5 #ifndef EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_ |
| 6 #define EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_ | 6 #define EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_ |
| 7 | 7 |
| 8 #include "embedders/openglui/common/canvas_state.h" | 8 #include "embedders/openglui/common/canvas_state.h" |
| 9 #include "embedders/openglui/common/graphics_handler.h" | 9 #include "embedders/openglui/common/graphics_handler.h" |
| 10 #include "embedders/openglui/common/log.h" | 10 #include "embedders/openglui/common/log.h" |
| 11 #include "embedders/openglui/common/opengl.h" | 11 #include "embedders/openglui/common/opengl.h" |
| 12 #include "embedders/openglui/common/support.h" | 12 #include "embedders/openglui/common/support.h" |
| 13 | 13 |
| 14 typedef struct ImageData { | 14 typedef struct ImageData { |
| 15 int width; | 15 int width; |
| 16 int height; | 16 int height; |
| 17 GLubyte* pixels; | 17 GLubyte* pixels; |
| 18 | 18 |
| 19 ImageData(int wp, int hp, GLubyte* pp) | 19 ImageData(int wp, int hp, GLubyte* pp) |
| 20 : width(wp), height(hp), pixels(pp) { | 20 : width(wp), height(hp), pixels(pp) { |
| 21 } | 21 } |
| 22 ImageData() | 22 ImageData() |
| 23 : width(0), height(0), pixels(NULL) { | 23 : width(0), height(0), pixels(NULL) { |
| 24 } | 24 } |
| 25 } ImageData; | 25 } ImageData; |
| 26 | 26 |
| 27 class CanvasContext { | 27 class CanvasContext { |
| 28 protected: | 28 protected: |
| 29 SkCanvas* canvas_; | 29 SkCanvas* canvas_; |
| 30 | |
| 31 int16_t width_, height_; | 30 int16_t width_, height_; |
| 32 | |
| 33 bool imageSmoothingEnabled_; | 31 bool imageSmoothingEnabled_; |
| 34 | 32 bool isDirty_; |
| 35 CanvasState* state_; | 33 CanvasState* state_; |
| 36 | 34 |
| 37 static inline float Radians2Degrees(float angle) { | 35 static inline float Radians2Degrees(float angle) { |
| 38 return 180.0 * angle / M_PI; | 36 return 180.0 * angle / M_PI; |
| 39 } | 37 } |
| 40 | 38 |
| 41 inline void NotImplemented(const char* method) { | 39 inline void NotImplemented(const char* method) { |
| 42 LOGE("Method CanvasContext::%s is not yet implemented", method); | 40 LOGE("Method CanvasContext::%s is not yet implemented", method); |
| 43 } | 41 } |
| 44 | 42 |
| 45 public: | 43 public: |
| 46 CanvasContext(int handle, int16_t width, int16_t height); | 44 CanvasContext(int handle, int16_t width, int16_t height); |
| 47 virtual ~CanvasContext(); | 45 virtual ~CanvasContext(); |
| 48 | 46 |
| 47 inline bool isDirty() { |
| 48 return isDirty_; |
| 49 } |
| 50 |
| 51 inline void clearDirty() { |
| 52 isDirty_ = false; |
| 53 } |
| 54 |
| 49 inline void setGlobalAlpha(float alpha) { | 55 inline void setGlobalAlpha(float alpha) { |
| 50 state_->setGlobalAlpha(alpha); | 56 state_->setGlobalAlpha(alpha); |
| 51 } | 57 } |
| 52 | 58 |
| 53 inline void setFillColor(const char* color) { | 59 inline void setFillColor(const char* color) { |
| 54 state_->setFillColor(color); | 60 state_->setFillColor(color); |
| 55 } | 61 } |
| 56 | 62 |
| 57 inline void setStrokeColor(const char* color) { | 63 inline void setStrokeColor(const char* color) { |
| 58 state_->setStrokeColor(color); | 64 state_->setStrokeColor(color); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 void PutImageData(ImageData* imageData, float dx, float dy) { | 164 void PutImageData(ImageData* imageData, float dx, float dy) { |
| 159 NotImplemented("PutImageData"); | 165 NotImplemented("PutImageData"); |
| 160 } | 166 } |
| 161 | 167 |
| 162 void DrawImage(const char* src_url, | 168 void DrawImage(const char* src_url, |
| 163 int sx, int sy, bool has_src_dimensions, int sw, int sh, | 169 int sx, int sy, bool has_src_dimensions, int sw, int sh, |
| 164 int dx, int dy, bool has_dst_dimensions, int dw, int dh); | 170 int dx, int dy, bool has_dst_dimensions, int dw, int dh); |
| 165 | 171 |
| 166 inline void Clear() { | 172 inline void Clear() { |
| 167 canvas_->drawColor(0xFFFFFFFF); | 173 canvas_->drawColor(0xFFFFFFFF); |
| 174 isDirty_ = true; |
| 168 } | 175 } |
| 169 | 176 |
| 170 void ClearRect(float left, float top, float width, float height); | 177 void ClearRect(float left, float top, float width, float height); |
| 171 | 178 |
| 172 inline void FillRect(float left, float top, float width, float height) { | 179 inline void FillRect(float left, float top, float width, float height) { |
| 173 // Does not affect the path. | 180 // Does not affect the path. |
| 174 state_->FillRect(left, top, width, height); | 181 state_->FillRect(left, top, width, height); |
| 182 isDirty_ = true; |
| 175 } | 183 } |
| 176 | 184 |
| 177 inline void StrokeRect(float left, float top, float width, float height) { | 185 inline void StrokeRect(float left, float top, float width, float height) { |
| 178 // Does not affect the path. | 186 // Does not affect the path. |
| 179 state_->StrokeRect(left, top, width, height); | 187 state_->StrokeRect(left, top, width, height); |
| 188 isDirty_ = true; |
| 180 } | 189 } |
| 181 | 190 |
| 182 inline void BeginPath() { | 191 inline void BeginPath() { |
| 183 state_->BeginPath(); | 192 state_->BeginPath(); |
| 184 } | 193 } |
| 185 | 194 |
| 186 inline void Fill() { | 195 inline void Fill() { |
| 187 state_->Fill(); | 196 state_->Fill(); |
| 197 isDirty_ = true; |
| 188 } | 198 } |
| 189 | 199 |
| 190 inline void Stroke() { | 200 inline void Stroke() { |
| 191 state_->Stroke(); | 201 state_->Stroke(); |
| 202 isDirty_ = true; |
| 192 } | 203 } |
| 193 | 204 |
| 194 inline void ClosePath() { | 205 inline void ClosePath() { |
| 195 state_->ClosePath(); | 206 state_->ClosePath(); |
| 196 } | 207 } |
| 197 | 208 |
| 198 inline void MoveTo(float x, float y) { | 209 inline void MoveTo(float x, float y) { |
| 199 state_->MoveTo(x, y); | 210 state_->MoveTo(x, y); |
| 200 } | 211 } |
| 201 | 212 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 return state_->setTextBaseline(baseline); | 273 return state_->setTextBaseline(baseline); |
| 263 } | 274 } |
| 264 | 275 |
| 265 inline const char* setDirection(const char* direction) { | 276 inline const char* setDirection(const char* direction) { |
| 266 return state_->setTextDirection(direction); | 277 return state_->setTextDirection(direction); |
| 267 } | 278 } |
| 268 | 279 |
| 269 inline void FillText(const char* text, float x, float y, | 280 inline void FillText(const char* text, float x, float y, |
| 270 float maxWidth = -1) { | 281 float maxWidth = -1) { |
| 271 state_->FillText(text, x, y, maxWidth); | 282 state_->FillText(text, x, y, maxWidth); |
| 283 isDirty_ = true; |
| 272 } | 284 } |
| 273 | 285 |
| 274 inline void StrokeText(const char* text, float x, float y, | 286 inline void StrokeText(const char* text, float x, float y, |
| 275 float maxWidth = -1) { | 287 float maxWidth = -1) { |
| 276 state_->StrokeText(text, x, y, maxWidth); | 288 state_->StrokeText(text, x, y, maxWidth); |
| 289 isDirty_ = true; |
| 277 } | 290 } |
| 278 | 291 |
| 279 inline float MeasureText(const char *text) { | 292 inline float MeasureText(const char *text) { |
| 280 return state_->MeasureText(text); | 293 return state_->MeasureText(text); |
| 281 } | 294 } |
| 282 | 295 |
| 283 inline void Clip() { | 296 inline void Clip() { |
| 284 state_->Clip(); | 297 state_->Clip(); |
| 285 } | 298 } |
| 286 | 299 |
| 287 inline void ResetClip() { | 300 inline void ResetClip() { |
| 288 // TODO(gram): Check this. Is it affected by the transform? | 301 // TODO(gram): Check this. Is it affected by the transform? |
| 289 canvas_->clipRect(SkRect::MakeLTRB(0, 0, width_, height_), | 302 canvas_->clipRect(SkRect::MakeLTRB(0, 0, width_, height_), |
| 290 SkRegion::kReplace_Op); | 303 SkRegion::kReplace_Op); |
| 291 } | 304 } |
| 292 | 305 |
| 293 virtual void Flush() { | 306 virtual void Flush() { |
| 294 canvas_->flush(); | 307 canvas_->flush(); |
| 295 } | 308 } |
| 296 }; | 309 }; |
| 297 | 310 |
| 298 CanvasContext* Context2D(int handle); | 311 CanvasContext* Context2D(int handle); |
| 312 void FreeContexts(); |
| 299 | 313 |
| 300 #endif // EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_ | 314 #endif // EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_ |
| 301 | 315 |
| OLD | NEW |