| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 void setAccelerated(bool accelerated) { m_accelerated = accelerated; } | 180 void setAccelerated(bool accelerated) { m_accelerated = accelerated; } |
| 181 | 181 |
| 182 float deviceScaleFactor() const { return m_deviceScaleFactor; } | 182 float deviceScaleFactor() const { return m_deviceScaleFactor; } |
| 183 void setDeviceScaleFactor(float scale) { m_deviceScaleFactor = scale; } | 183 void setDeviceScaleFactor(float scale) { m_deviceScaleFactor = scale; } |
| 184 | 184 |
| 185 void setTrackOpaqueRegion(bool track) { m_trackOpaqueRegion = track; } | 185 void setTrackOpaqueRegion(bool track) { m_trackOpaqueRegion = track; } |
| 186 | 186 |
| 187 // This will be an empty region unless tracking is enabled. | 187 // This will be an empty region unless tracking is enabled. |
| 188 const OpaqueRegionSkia& opaqueRegion() const { return m_opaqueRegion; } | 188 const OpaqueRegionSkia& opaqueRegion() const { return m_opaqueRegion; } |
| 189 | 189 |
| 190 void setTrackTextRegion(bool track) { m_trackTextRegion = track; } |
| 191 // This will be an empty region unless tracking is enabled. |
| 192 const SkRect& textRegion() const { return m_textRegion; } |
| 193 |
| 190 // After drawing directly to the context's canvas, use this function to noti
fy the context so | 194 // After drawing directly to the context's canvas, use this function to noti
fy the context so |
| 191 // it can track the opaque region. | 195 // it can track the opaque region. |
| 192 // FIXME: this is still needed only because ImageSkia::paintSkBitmap() may n
eed to notify for a | 196 // FIXME: this is still needed only because ImageSkia::paintSkBitmap() may n
eed to notify for a |
| 193 // smaller rect than the one drawn to, due to its clipping logic. | 197 // smaller rect than the one drawn to, due to its clipping logic. |
| 194 void didDrawRect(const SkRect&, const SkPaint&, const SkBitmap* = 0); | 198 void didDrawRect(const SkRect&, const SkPaint&, const SkBitmap* = 0); |
| 195 | 199 |
| 196 // Turn off LCD text for the paint if not supported on this context. | 200 // Turn off LCD text for the paint if not supported on this context. |
| 197 void adjustTextRenderMode(SkPaint*); | 201 void adjustTextRenderMode(SkPaint*); |
| 198 bool couldUseLCDRenderedText(); | 202 bool couldUseLCDRenderedText(); |
| 199 | 203 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 bool translate(SkScalar dx, SkScalar dy); | 236 bool translate(SkScalar dx, SkScalar dy); |
| 233 | 237 |
| 234 void drawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint* = 0); | 238 void drawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint* = 0); |
| 235 void drawBitmapRect(const SkBitmap&, const SkIRect*, const SkRect&, const Sk
Paint* = 0); | 239 void drawBitmapRect(const SkBitmap&, const SkIRect*, const SkRect&, const Sk
Paint* = 0); |
| 236 void drawOval(const SkRect&, const SkPaint&); | 240 void drawOval(const SkRect&, const SkPaint&); |
| 237 void drawPath(const SkPath&, const SkPaint&); | 241 void drawPath(const SkPath&, const SkPaint&); |
| 238 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint pts[], cons
t SkPaint&); | 242 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint pts[], cons
t SkPaint&); |
| 239 void drawRect(const SkRect&, const SkPaint&); | 243 void drawRect(const SkRect&, const SkPaint&); |
| 240 void drawIRect(const SkIRect&, const SkPaint&); | 244 void drawIRect(const SkIRect&, const SkPaint&); |
| 241 void drawRRect(const SkRRect&, const SkPaint&); | 245 void drawRRect(const SkRRect&, const SkPaint&); |
| 242 void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], c
onst SkPaint&); | 246 void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], c
onst SkRect& textRect, const SkPaint&); |
| 243 void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[]
, SkScalar constY, | 247 void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[]
, SkScalar constY, |
| 244 const SkPaint&); | 248 const SkRect& textRect, const SkPaint&); |
| 245 void drawTextOnPath(const void* text, size_t byteLength, const SkPath&, | 249 void drawTextOnPath(const void* text, size_t byteLength, const SkPath&, cons
t SkRect& textRect, |
| 246 const SkMatrix*, const SkPaint&); | 250 const SkMatrix*, const SkPaint&); |
| 247 | 251 |
| 248 private: | 252 private: |
| 249 // Used when restoring and the state has an image clip. Only shows the pixel
s in | 253 // Used when restoring and the state has an image clip. Only shows the pixel
s in |
| 250 // m_canvas that are also in imageBuffer. | 254 // m_canvas that are also in imageBuffer. |
| 251 // The clipping rectangle is given in absolute coordinates. | 255 // The clipping rectangle is given in absolute coordinates. |
| 252 void applyClipFromImage(const SkRect&, const SkBitmap&); | 256 void applyClipFromImage(const SkRect&, const SkBitmap&); |
| 253 | 257 |
| 254 // common code between setupPaintFor[Filling,Stroking] | 258 // common code between setupPaintFor[Filling,Stroking] |
| 255 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const; | 259 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const; |
| 256 | 260 |
| 257 void realizeSave(SkCanvas::SaveFlags); | 261 void realizeSave(SkCanvas::SaveFlags); |
| 258 | 262 |
| 263 void didDrawTextInRect(const SkRect& textRect); |
| 264 |
| 259 struct DeferredSaveState; | 265 struct DeferredSaveState; |
| 260 | 266 |
| 261 // NULL indicates painting is disabled. Never delete this object. | 267 // NULL indicates painting is disabled. Never delete this object. |
| 262 SkCanvas* m_canvas; | 268 SkCanvas* m_canvas; |
| 263 const GraphicsContext* m_gc; | 269 const GraphicsContext* m_gc; |
| 264 | 270 |
| 265 // States stack. Enables local drawing state change with save()/restore() | 271 // States stack. Enables local drawing state change with save()/restore() |
| 266 // calls. | 272 // calls. |
| 267 Vector<PlatformContextSkiaState> m_stateStack; | 273 Vector<PlatformContextSkiaState> m_stateStack; |
| 268 // Pointer to the current drawing state. This is a cached value of | 274 // Pointer to the current drawing state. This is a cached value of |
| 269 // mStateStack.back(). | 275 // mStateStack.back(). |
| 270 PlatformContextSkiaState* m_state; | 276 PlatformContextSkiaState* m_state; |
| 271 | 277 |
| 272 Vector<DeferredSaveState> m_saveStateStack; | 278 Vector<DeferredSaveState> m_saveStateStack; |
| 273 | 279 |
| 274 // Currently pending save flags. | 280 // Currently pending save flags. |
| 275 // FIXME: While defined as a bitmask of SkCanvas::SaveFlags, this is mostly
used as a bool. | 281 // FIXME: While defined as a bitmask of SkCanvas::SaveFlags, this is mostly
used as a bool. |
| 276 // It will come in handy when adding granular save() support (clip vs
. matrix vs. paint). | 282 // It will come in handy when adding granular save() support (clip vs
. matrix vs. paint). |
| 277 unsigned m_deferredSaveFlags; | 283 unsigned m_deferredSaveFlags; |
| 278 | 284 |
| 279 // Tracks the region painted opaque via the GraphicsContext. | 285 // Tracks the region painted opaque via the GraphicsContext. |
| 280 OpaqueRegionSkia m_opaqueRegion; | 286 OpaqueRegionSkia m_opaqueRegion; |
| 281 bool m_trackOpaqueRegion; | 287 bool m_trackOpaqueRegion; |
| 282 | 288 |
| 289 // Tracks the region where text is painted via GraphicsContext. |
| 290 bool m_trackTextRegion; |
| 291 SkRect m_textRegion; |
| 292 |
| 283 bool m_printing; | 293 bool m_printing; |
| 284 bool m_accelerated; | 294 bool m_accelerated; |
| 285 bool m_drawingToImageBuffer; | 295 bool m_drawingToImageBuffer; |
| 286 float m_deviceScaleFactor; | 296 float m_deviceScaleFactor; |
| 287 }; | 297 }; |
| 288 | 298 |
| 289 inline void PlatformContextSkia::realizeSave(SkCanvas::SaveFlags flags) | 299 inline void PlatformContextSkia::realizeSave(SkCanvas::SaveFlags flags) |
| 290 { | 300 { |
| 291 if (m_deferredSaveFlags & flags) { | 301 if (m_deferredSaveFlags & flags) { |
| 292 m_canvas->save((SkCanvas::SaveFlags)m_deferredSaveFlags); | 302 m_canvas->save((SkCanvas::SaveFlags)m_deferredSaveFlags); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 477 } |
| 468 | 478 |
| 469 inline void PlatformContextSkia::drawRRect(const SkRRect& rect, const SkPaint& p
aint) | 479 inline void PlatformContextSkia::drawRRect(const SkRRect& rect, const SkPaint& p
aint) |
| 470 { | 480 { |
| 471 m_canvas->drawRRect(rect, paint); | 481 m_canvas->drawRRect(rect, paint); |
| 472 | 482 |
| 473 if (m_trackOpaqueRegion) | 483 if (m_trackOpaqueRegion) |
| 474 m_opaqueRegion.didDrawBounded(this, rect.getBounds(), paint); | 484 m_opaqueRegion.didDrawBounded(this, rect.getBounds(), paint); |
| 475 } | 485 } |
| 476 | 486 |
| 477 inline void PlatformContextSkia::drawPosText(const void* text, size_t byteLength
, | 487 inline void PlatformContextSkia::drawPosText(const void* text, |
| 478 const SkPoint pos[], const SkPaint& paint) | 488 size_t byteLength, |
| 489 const SkPoint pos[], |
| 490 const SkRect& textRect, |
| 491 const SkPaint& paint) |
| 479 { | 492 { |
| 480 m_canvas->drawPosText(text, byteLength, pos, paint); | 493 m_canvas->drawPosText(text, byteLength, pos, paint); |
| 494 didDrawTextInRect(textRect); |
| 481 | 495 |
| 482 // FIXME: compute bounds for positioned text. | 496 // FIXME: compute bounds for positioned text. |
| 483 if (m_trackOpaqueRegion) | 497 if (m_trackOpaqueRegion) |
| 484 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr
oke); | 498 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr
oke); |
| 485 } | 499 } |
| 486 | 500 |
| 487 inline void PlatformContextSkia::drawPosTextH(const void* text, size_t byteLengt
h, | 501 inline void PlatformContextSkia::drawPosTextH(const void* text, |
| 488 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) | 502 size_t byteLength, |
| 503 const SkScalar xpos[], |
| 504 SkScalar constY, |
| 505 const SkRect& textRect, |
| 506 const SkPaint& paint) |
| 489 { | 507 { |
| 490 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); | 508 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); |
| 509 didDrawTextInRect(textRect); |
| 491 | 510 |
| 492 // FIXME: compute bounds for positioned text. | 511 // FIXME: compute bounds for positioned text. |
| 493 if (m_trackOpaqueRegion) | 512 if (m_trackOpaqueRegion) |
| 494 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr
oke); | 513 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr
oke); |
| 495 } | 514 } |
| 496 | 515 |
| 497 inline void PlatformContextSkia::drawTextOnPath(const void* text, size_t byteLen
gth, | 516 inline void PlatformContextSkia::drawTextOnPath(const void* text, |
| 498 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) | 517 size_t byteLength, |
| 518 const SkPath& path, |
| 519 const SkRect& textRect, |
| 520 const SkMatrix* matrix, |
| 521 const SkPaint& paint) |
| 499 { | 522 { |
| 500 m_canvas->drawTextOnPath(text, byteLength, path, matrix, paint); | 523 m_canvas->drawTextOnPath(text, byteLength, path, matrix, paint); |
| 524 didDrawTextInRect(textRect); |
| 501 | 525 |
| 502 // FIXME: compute bounds for positioned text. | 526 // FIXME: compute bounds for positioned text. |
| 503 if (m_trackOpaqueRegion) | 527 if (m_trackOpaqueRegion) |
| 504 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr
oke); | 528 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr
oke); |
| 505 } | 529 } |
| 506 | 530 |
| 507 } | 531 } |
| 508 #endif // PlatformContextSkia_h | 532 #endif // PlatformContextSkia_h |
| OLD | NEW |