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

Side by Side Diff: Source/core/platform/graphics/skia/PlatformContextSkia.h

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase with TOT Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 void setAccelerated(bool accelerated) { m_accelerated = accelerated; } 179 void setAccelerated(bool accelerated) { m_accelerated = accelerated; }
180 180
181 float deviceScaleFactor() const { return m_deviceScaleFactor; } 181 float deviceScaleFactor() const { return m_deviceScaleFactor; }
182 void setDeviceScaleFactor(float scale) { m_deviceScaleFactor = scale; } 182 void setDeviceScaleFactor(float scale) { m_deviceScaleFactor = scale; }
183 183
184 void setTrackOpaqueRegion(bool track) { m_trackOpaqueRegion = track; } 184 void setTrackOpaqueRegion(bool track) { m_trackOpaqueRegion = track; }
185 185
186 // This will be an empty region unless tracking is enabled. 186 // This will be an empty region unless tracking is enabled.
187 const OpaqueRegionSkia& opaqueRegion() const { return m_opaqueRegion; } 187 const OpaqueRegionSkia& opaqueRegion() const { return m_opaqueRegion; }
188 188
189 void setTrackTextRegion(bool track) { m_trackTextRegion = track; }
190 // This will be an empty region unless tracking is enabled.
191 const SkRect& textRegion() const { return m_textRegion; }
192
189 // After drawing directly to the context's canvas, use this function to noti fy the context so 193 // After drawing directly to the context's canvas, use this function to noti fy the context so
190 // it can track the opaque region. 194 // it can track the opaque region.
191 // FIXME: this is still needed only because ImageSkia::paintSkBitmap() may n eed to notify for a 195 // FIXME: this is still needed only because ImageSkia::paintSkBitmap() may n eed to notify for a
192 // smaller rect than the one drawn to, due to its clipping logic. 196 // smaller rect than the one drawn to, due to its clipping logic.
193 void didDrawRect(const SkRect&, const SkPaint&, const SkBitmap* = 0); 197 void didDrawRect(const SkRect&, const SkPaint&, const SkBitmap* = 0);
194 198
195 // Turn off LCD text for the paint if not supported on this context. 199 // Turn off LCD text for the paint if not supported on this context.
196 void adjustTextRenderMode(SkPaint*); 200 void adjustTextRenderMode(SkPaint*);
197 bool couldUseLCDRenderedText(); 201 bool couldUseLCDRenderedText();
198 202
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 bool translate(SkScalar dx, SkScalar dy); 235 bool translate(SkScalar dx, SkScalar dy);
232 236
233 void drawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint* = 0); 237 void drawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint* = 0);
234 void drawBitmapRect(const SkBitmap&, const SkIRect*, const SkRect&, const Sk Paint* = 0); 238 void drawBitmapRect(const SkBitmap&, const SkIRect*, const SkRect&, const Sk Paint* = 0);
235 void drawOval(const SkRect&, const SkPaint&); 239 void drawOval(const SkRect&, const SkPaint&);
236 void drawPath(const SkPath&, const SkPaint&); 240 void drawPath(const SkPath&, const SkPaint&);
237 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint pts[], cons t SkPaint&); 241 void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint pts[], cons t SkPaint&);
238 void drawRect(const SkRect&, const SkPaint&); 242 void drawRect(const SkRect&, const SkPaint&);
239 void drawIRect(const SkIRect&, const SkPaint&); 243 void drawIRect(const SkIRect&, const SkPaint&);
240 void drawRRect(const SkRRect&, const SkPaint&); 244 void drawRRect(const SkRRect&, const SkPaint&);
241 void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], c onst SkPaint&); 245 void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], c onst SkRect& textRect, const SkPaint&);
242 void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[] , SkScalar constY, 246 void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[] , SkScalar constY,
243 const SkPaint&); 247 const SkRect& textRect, const SkPaint&);
244 void drawTextOnPath(const void* text, size_t byteLength, const SkPath&, 248 void drawTextOnPath(const void* text, size_t byteLength, const SkPath&, cons t SkRect& textRect,
245 const SkMatrix*, const SkPaint&); 249 const SkMatrix*, const SkPaint&);
246 250
247 private: 251 private:
248 // Used when restoring and the state has an image clip. Only shows the pixel s in 252 // Used when restoring and the state has an image clip. Only shows the pixel s in
249 // m_canvas that are also in imageBuffer. 253 // m_canvas that are also in imageBuffer.
250 // The clipping rectangle is given in absolute coordinates. 254 // The clipping rectangle is given in absolute coordinates.
251 void applyClipFromImage(const SkRect&, const SkBitmap&); 255 void applyClipFromImage(const SkRect&, const SkBitmap&);
252 256
253 // common code between setupPaintFor[Filling,Stroking] 257 // common code between setupPaintFor[Filling,Stroking]
254 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const; 258 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const;
255 259
256 void realizeSave(SkCanvas::SaveFlags); 260 void realizeSave(SkCanvas::SaveFlags);
257 261
262 void trackTextRegion(const SkRect& textRect);
263
258 // Defines drawing style. 264 // Defines drawing style.
259 struct State; 265 struct State;
260 266
261 struct DeferredSaveState; 267 struct DeferredSaveState;
262 268
263 // NULL indicates painting is disabled. Never delete this object. 269 // NULL indicates painting is disabled. Never delete this object.
264 SkCanvas* m_canvas; 270 SkCanvas* m_canvas;
265 const GraphicsContext* m_gc; 271 const GraphicsContext* m_gc;
266 272
267 // States stack. Enables local drawing state change with save()/restore() 273 // States stack. Enables local drawing state change with save()/restore()
268 // calls. 274 // calls.
269 WTF::Vector<State> m_stateStack; 275 WTF::Vector<State> m_stateStack;
270 // Pointer to the current drawing state. This is a cached value of 276 // Pointer to the current drawing state. This is a cached value of
271 // mStateStack.back(). 277 // mStateStack.back().
272 State* m_state; 278 State* m_state;
273 279
274 WTF::Vector<DeferredSaveState> m_saveStateStack; 280 WTF::Vector<DeferredSaveState> m_saveStateStack;
275 281
276 // Currently pending save flags. 282 // Currently pending save flags.
277 // FIXME: While defined as a bitmask of SkCanvas::SaveFlags, this is mostly used as a bool. 283 // FIXME: While defined as a bitmask of SkCanvas::SaveFlags, this is mostly used as a bool.
278 // It will come in handy when adding granular save() support (clip vs . matrix vs. paint). 284 // It will come in handy when adding granular save() support (clip vs . matrix vs. paint).
279 unsigned m_deferredSaveFlags; 285 unsigned m_deferredSaveFlags;
280 286
281 // Tracks the region painted opaque via the GraphicsContext. 287 // Tracks the region painted opaque via the GraphicsContext.
282 OpaqueRegionSkia m_opaqueRegion; 288 OpaqueRegionSkia m_opaqueRegion;
283 bool m_trackOpaqueRegion; 289 bool m_trackOpaqueRegion;
284 290
291 // Tracks the region where text is painted via GraphicsContext.
292 bool m_trackTextRegion;
293 SkRect m_textRegion;
294
285 bool m_printing; 295 bool m_printing;
286 bool m_accelerated; 296 bool m_accelerated;
287 bool m_drawingToImageBuffer; 297 bool m_drawingToImageBuffer;
288 float m_deviceScaleFactor; 298 float m_deviceScaleFactor;
289 }; 299 };
290 300
291 inline void PlatformContextSkia::realizeSave(SkCanvas::SaveFlags flags) 301 inline void PlatformContextSkia::realizeSave(SkCanvas::SaveFlags flags)
292 { 302 {
293 if (m_deferredSaveFlags & flags) { 303 if (m_deferredSaveFlags & flags) {
294 m_canvas->save((SkCanvas::SaveFlags)m_deferredSaveFlags); 304 m_canvas->save((SkCanvas::SaveFlags)m_deferredSaveFlags);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 479 }
470 480
471 inline void PlatformContextSkia::drawRRect(const SkRRect& rect, const SkPaint& p aint) 481 inline void PlatformContextSkia::drawRRect(const SkRRect& rect, const SkPaint& p aint)
472 { 482 {
473 m_canvas->drawRRect(rect, paint); 483 m_canvas->drawRRect(rect, paint);
474 484
475 if (m_trackOpaqueRegion) 485 if (m_trackOpaqueRegion)
476 m_opaqueRegion.didDrawBounded(this, rect.getBounds(), paint); 486 m_opaqueRegion.didDrawBounded(this, rect.getBounds(), paint);
477 } 487 }
478 488
479 inline void PlatformContextSkia::drawPosText(const void* text, size_t byteLength , 489 inline void PlatformContextSkia::drawPosText(const void* text,
480 const SkPoint pos[], const SkPaint& paint) 490 size_t byteLength,
491 const SkPoint pos[],
492 const SkRect& textRect,
493 const SkPaint& paint)
481 { 494 {
482 m_canvas->drawPosText(text, byteLength, pos, paint); 495 m_canvas->drawPosText(text, byteLength, pos, paint);
496 trackTextRegion(textRect);
eseidel 2013/04/18 21:04:38 Do we ever stop tracking? Should this be didDrawT
alokp 2013/04/18 22:22:37 I like didDrawTextInRect. Changed.
483 497
484 // FIXME: compute bounds for positioned text. 498 // FIXME: compute bounds for positioned text.
485 if (m_trackOpaqueRegion) 499 if (m_trackOpaqueRegion)
486 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke); 500 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke);
487 } 501 }
488 502
489 inline void PlatformContextSkia::drawPosTextH(const void* text, size_t byteLengt h, 503 inline void PlatformContextSkia::drawPosTextH(const void* text,
490 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) 504 size_t byteLength,
505 const SkScalar xpos[],
506 SkScalar constY,
507 const SkRect& textRect,
508 const SkPaint& paint)
491 { 509 {
492 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); 510 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint);
511 trackTextRegion(textRect);
493 512
494 // FIXME: compute bounds for positioned text. 513 // FIXME: compute bounds for positioned text.
495 if (m_trackOpaqueRegion) 514 if (m_trackOpaqueRegion)
496 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke); 515 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke);
497 } 516 }
498 517
499 inline void PlatformContextSkia::drawTextOnPath(const void* text, size_t byteLen gth, 518 inline void PlatformContextSkia::drawTextOnPath(const void* text,
500 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) 519 size_t byteLength,
520 const SkPath& path,
521 const SkRect& textRect,
522 const SkMatrix* matrix,
523 const SkPaint& paint)
501 { 524 {
502 m_canvas->drawTextOnPath(text, byteLength, path, matrix, paint); 525 m_canvas->drawTextOnPath(text, byteLength, path, matrix, paint);
526 trackTextRegion(textRect);
eseidel 2013/04/18 21:04:38 It's not clear to me that "textRect" is the right
alokp 2013/04/18 22:22:37 It does not clip right now. The plan is to use for
503 527
504 // FIXME: compute bounds for positioned text. 528 // FIXME: compute bounds for positioned text.
505 if (m_trackOpaqueRegion) 529 if (m_trackOpaqueRegion)
506 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke); 530 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke);
507 } 531 }
508 532
509 } 533 }
510 #endif // PlatformContextSkia_h 534 #endif // PlatformContextSkia_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698