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

Side by Side Diff: Source/platform/graphics/GraphicsContext.h

Issue 169283008: Maintain SkPaint in GraphicsContextState. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: A couple more optimizations. Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/graphics/Gradient.cpp ('k') | Source/platform/graphics/GraphicsContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008-2009 Torch Mobile, Inc. 3 * Copyright (C) 2008-2009 Torch Mobile, Inc.
4 * Copyright (C) 2013 Google Inc. All rights reserved. 4 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 21 matching lines...) Expand all
32 #include "platform/TraceEvent.h" 32 #include "platform/TraceEvent.h"
33 #include "platform/fonts/Font.h" 33 #include "platform/fonts/Font.h"
34 #include "platform/geometry/FloatRect.h" 34 #include "platform/geometry/FloatRect.h"
35 #include "platform/graphics/DashArray.h" 35 #include "platform/graphics/DashArray.h"
36 #include "platform/graphics/DrawLooper.h" 36 #include "platform/graphics/DrawLooper.h"
37 #include "platform/graphics/ImageBufferSurface.h" 37 #include "platform/graphics/ImageBufferSurface.h"
38 #include "platform/graphics/ImageOrientation.h" 38 #include "platform/graphics/ImageOrientation.h"
39 #include "platform/graphics/GraphicsContextAnnotation.h" 39 #include "platform/graphics/GraphicsContextAnnotation.h"
40 #include "platform/graphics/GraphicsContextState.h" 40 #include "platform/graphics/GraphicsContextState.h"
41 #include "platform/graphics/skia/OpaqueRegionSkia.h" 41 #include "platform/graphics/skia/OpaqueRegionSkia.h"
42 #include "platform/graphics/skia/SkiaUtils.h"
43 #include "wtf/FastAllocBase.h" 42 #include "wtf/FastAllocBase.h"
44 #include "wtf/Forward.h" 43 #include "wtf/Forward.h"
45 #include "wtf/Noncopyable.h" 44 #include "wtf/Noncopyable.h"
46 #include "wtf/PassOwnPtr.h" 45 #include "wtf/PassOwnPtr.h"
47 46
48 class SkBitmap; 47 class SkBitmap;
49 class SkPaint; 48 class SkPaint;
50 class SkPath; 49 class SkPath;
51 class SkRRect; 50 class SkRRect;
52 struct SkRect; 51 struct SkRect;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 const SkCanvas* canvas() const { return m_canvas; } 86 const SkCanvas* canvas() const { return m_canvas; }
88 bool paintingDisabled() const { return !m_canvas; } 87 bool paintingDisabled() const { return !m_canvas; }
89 88
90 // ---------- State management methods ----------------- 89 // ---------- State management methods -----------------
91 void save(); 90 void save();
92 void restore(); 91 void restore();
93 92
94 void saveLayer(const SkRect* bounds, const SkPaint*, SkCanvas::SaveFlags = S kCanvas::kARGB_ClipLayer_SaveFlag); 93 void saveLayer(const SkRect* bounds, const SkPaint*, SkCanvas::SaveFlags = S kCanvas::kARGB_ClipLayer_SaveFlag);
95 void restoreLayer(); 94 void restoreLayer();
96 95
97 float strokeThickness() const { return m_paintState->m_strokeData.thickness( ); } 96 float strokeThickness() const { return immutableState()->strokeData().thickn ess(); }
98 void setStrokeThickness(float thickness) { mutableState()->m_strokeData.setT hickness(thickness); } 97 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes s(thickness); }
99 98
100 StrokeStyle strokeStyle() const { return m_paintState->m_strokeData.style(); } 99 StrokeStyle strokeStyle() const { return immutableState()->strokeData().styl e(); }
101 void setStrokeStyle(StrokeStyle style) { mutableState()->m_strokeData.setSty le(style); } 100 void setStrokeStyle(StrokeStyle style) { mutableState()->setStrokeStyle(styl e); }
102 101
103 Color strokeColor() const { return m_paintState->m_strokeData.color(); } 102 Color strokeColor() const { return immutableState()->strokeData().color(); }
104 void setStrokeColor(const Color&); 103 void setStrokeColor(const Color& color) { mutableState()->setStrokeColor(col or); }
104 SkColor effectiveStrokeColor() const { return immutableState()->effectiveStr okeColor(); }
105 105
106 Pattern* strokePattern() const { return m_paintState->m_strokeData.pattern() ; } 106 Pattern* strokePattern() const { return immutableState()->strokeData().patte rn(); }
107 void setStrokePattern(PassRefPtr<Pattern>); 107 void setStrokePattern(PassRefPtr<Pattern>);
108 108
109 Gradient* strokeGradient() const { return m_paintState->m_strokeData.gradien t(); } 109 Gradient* strokeGradient() const { return immutableState()->strokeData().gra dient(); }
110 void setStrokeGradient(PassRefPtr<Gradient>); 110 void setStrokeGradient(PassRefPtr<Gradient>);
111 111
112 void setLineCap(LineCap cap) { mutableState()->m_strokeData.setLineCap(cap); } 112 void setLineCap(LineCap cap) { mutableState()->setLineCap(cap); }
113 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState() ->m_strokeData.setLineDash(dashes, dashOffset); } 113 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState() ->setLineDash(dashes, dashOffset); }
114 void setLineJoin(LineJoin join) { mutableState()->m_strokeData.setLineJoin(j oin); } 114 void setLineJoin(LineJoin join) { mutableState()->setLineJoin(join); }
115 void setMiterLimit(float limit) { mutableState()->m_strokeData.setMiterLimit (limit); } 115 void setMiterLimit(float limit) { mutableState()->setMiterLimit(limit); }
116 116
117 WindRule fillRule() const { return m_paintState->m_fillRule; } 117 WindRule fillRule() const { return immutableState()->fillRule(); }
118 void setFillRule(WindRule fillRule) { mutableState()->m_fillRule = fillRule; } 118 void setFillRule(WindRule fillRule) { mutableState()->setFillRule(fillRule); }
119 119
120 Color fillColor() const { return m_paintState->m_fillColor; } 120 Color fillColor() const { return immutableState()->fillColor(); }
121 void setFillColor(const Color&); 121 void setFillColor(const Color& color) { mutableState()->setFillColor(color); }
122 SkColor effectiveFillColor() const { return m_paintState->applyAlpha(m_paint State->m_fillColor.rgb()); } 122 SkColor effectiveFillColor() const { return immutableState()->effectiveFillC olor(); }
123 123
124 void setFillPattern(PassRefPtr<Pattern>); 124 void setFillPattern(PassRefPtr<Pattern>);
125 Pattern* fillPattern() const { return m_paintState->m_fillPattern.get(); } 125 Pattern* fillPattern() const { return immutableState()->fillPattern(); }
126 126
127 void setFillGradient(PassRefPtr<Gradient>); 127 void setFillGradient(PassRefPtr<Gradient>);
128 Gradient* fillGradient() const { return m_paintState->m_fillGradient.get(); } 128 Gradient* fillGradient() const { return immutableState()->fillGradient(); }
129 129
130 SkDrawLooper* drawLooper() const { return m_paintState->m_looper.get(); } 130 SkDrawLooper* drawLooper() const { return immutableState()->drawLooper(); }
131 SkColor effectiveStrokeColor() const { return m_paintState->applyAlpha(m_pai ntState->m_strokeData.color().rgb()); }
132
133 int getNormalizedAlpha() const;
134 131
135 FloatRect getClipBounds() const; 132 FloatRect getClipBounds() const;
136 bool getTransformedClipBounds(FloatRect* bounds) const; 133 bool getTransformedClipBounds(FloatRect* bounds) const;
137 SkMatrix getTotalMatrix() const; 134 SkMatrix getTotalMatrix() const;
138 bool isPrintingDevice() const; 135 bool isPrintingDevice() const;
139 136
140 void setShouldAntialias(bool antialias) { mutableState()->m_shouldAntialias = antialias; } 137 void setShouldAntialias(bool antialias) { mutableState()->setShouldAntialias (antialias); }
141 bool shouldAntialias() const { return m_paintState->m_shouldAntialias; } 138 bool shouldAntialias() const { return immutableState()->shouldAntialias(); }
142 139
143 void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->m_ shouldClampToSourceRect = clampToSourceRect; } 140 void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->se tShouldClampToSourceRect(clampToSourceRect); }
144 bool shouldClampToSourceRect() const { return m_paintState->m_shouldClampToS ourceRect; } 141 bool shouldClampToSourceRect() const { return immutableState()->shouldClampT oSourceRect(); }
145 142
146 void setShouldSmoothFonts(bool smoothFonts) { mutableState()->m_shouldSmooth Fonts = smoothFonts; } 143 void setShouldSmoothFonts(bool smoothFonts) { mutableState()->setShouldSmoot hFonts(smoothFonts); }
147 bool shouldSmoothFonts() const { return m_paintState->m_shouldSmoothFonts; } 144 bool shouldSmoothFonts() const { return immutableState()->shouldSmoothFonts( ); }
148 145
149 // Turn off LCD text for the paint if not supported on this context. 146 // Turn off LCD text for the paint if not supported on this context.
150 void adjustTextRenderMode(SkPaint*); 147 void adjustTextRenderMode(SkPaint*);
151 bool couldUseLCDRenderedText(); 148 bool couldUseLCDRenderedText();
152 149
153 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->m_textD rawingMode = mode; } 150 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setText DrawingMode(mode); }
154 TextDrawingModeFlags textDrawingMode() const { return m_paintState->m_textDr awingMode; } 151 TextDrawingModeFlags textDrawingMode() const { return immutableState()->text DrawingMode(); }
155 152
156 void setAlpha(float alpha) { mutableState()->m_alpha = alpha;} 153 void setAlphaAsFloat(float alpha) { mutableState()->setAlphaAsFloat(alpha);}
154 int getNormalizedAlpha() const
155 {
156 int alpha = immutableState()->alpha();
157 return alpha > 255 ? 255 : alpha;
158 }
157 159
158 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta te()->m_interpolationQuality = quality; } 160 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta te()->setInterpolationQuality(quality); }
159 InterpolationQuality imageInterpolationQuality() const { return m_paintState ->m_interpolationQuality; } 161 InterpolationQuality imageInterpolationQuality() const { return immutableSta te()->interpolationQuality(); }
160 162
161 void setCompositeOperation(CompositeOperator, blink::WebBlendMode = blink::W ebBlendModeNormal); 163 void setCompositeOperation(CompositeOperator, blink::WebBlendMode = blink::W ebBlendModeNormal);
162 CompositeOperator compositeOperation() const { return m_paintState->m_compos iteOperator; } 164 CompositeOperator compositeOperation() const { return immutableState()->comp ositeOperator(); }
163 blink::WebBlendMode blendModeOperation() const { return m_paintState->m_blen dMode; } 165 blink::WebBlendMode blendModeOperation() const { return immutableState()->bl endMode(); }
164 166
165 // Change the way document markers are rendered. 167 // Change the way document markers are rendered.
166 // Any deviceScaleFactor higher than 1.5 is enough to justify setting this f lag. 168 // Any deviceScaleFactor higher than 1.5 is enough to justify setting this f lag.
167 void setUseHighResMarkers(bool isHighRes) { m_useHighResMarker = isHighRes; } 169 void setUseHighResMarkers(bool isHighRes) { m_useHighResMarker = isHighRes; }
168 170
169 // If true we are (most likely) rendering to a web page and the 171 // If true we are (most likely) rendering to a web page and the
170 // canvas has been prepared with an opaque background. If false, 172 // canvas has been prepared with an opaque background. If false,
171 // the canvas may have transparency (as is the case when rendering 173 // the canvas may have transparency (as is the case when rendering
172 // to a canvas object). 174 // to a canvas object).
173 void setCertainlyOpaque(bool isOpaque) { m_isCertainlyOpaque = isOpaque; } 175 void setCertainlyOpaque(bool isOpaque) { m_isCertainlyOpaque = isOpaque; }
(...skipping 27 matching lines...) Expand all
201 SkColorFilter* colorFilter(); 203 SkColorFilter* colorFilter();
202 void setColorFilter(ColorFilter); 204 void setColorFilter(ColorFilter);
203 // ---------- End state management methods ----------------- 205 // ---------- End state management methods -----------------
204 206
205 // Get the contents of the image buffer 207 // Get the contents of the image buffer
206 bool readPixels(SkBitmap*, int, int, SkCanvas::Config8888 = SkCanvas::kNativ e_Premul_Config8888); 208 bool readPixels(SkBitmap*, int, int, SkCanvas::Config8888 = SkCanvas::kNativ e_Premul_Config8888);
207 209
208 // Sets up the paint for the current fill style. 210 // Sets up the paint for the current fill style.
209 void setupPaintForFilling(SkPaint*) const; 211 void setupPaintForFilling(SkPaint*) const;
210 212
211 // Sets up the paint for stroking. Returns a float representing the 213 // Sets up the paint for the current stroke style.
212 // effective width of the pen. If a non-zero length is provided, the 214 void setupPaintForStroking(SkPaint*) const;
213 // number of dashes/dots on a dashed/dotted line will be adjusted to
214 // start and end that length with a dash/dot.
215 float setupPaintForStroking(SkPaint*, int length = 0) const;
216 215
217 // These draw methods will do both stroking and filling. 216 // These draw methods will do both stroking and filling.
218 // FIXME: ...except drawRect(), which fills properly but always strokes 217 // FIXME: ...except drawRect(), which fills properly but always strokes
219 // using a 1-pixel stroke inset from the rect borders (of the correct 218 // using a 1-pixel stroke inset from the rect borders (of the correct
220 // stroke color). 219 // stroke color).
221 void drawRect(const IntRect&); 220 void drawRect(const IntRect&);
222 void drawLine(const IntPoint&, const IntPoint&); 221 void drawLine(const IntPoint&, const IntPoint&);
223 void drawEllipse(const IntRect&); 222 void drawEllipse(const IntRect&);
224 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntia lias = false); 223 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntia lias = false);
225 224
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 303
305 void beginTransparencyLayer(float opacity, const FloatRect* = 0); 304 void beginTransparencyLayer(float opacity, const FloatRect* = 0);
306 void beginLayer(float opacity, CompositeOperator, const FloatRect* = 0, Colo rFilter = ColorFilterNone, ImageFilter* = 0); 305 void beginLayer(float opacity, CompositeOperator, const FloatRect* = 0, Colo rFilter = ColorFilterNone, ImageFilter* = 0);
307 void endLayer(); 306 void endLayer();
308 307
309 // Instead of being dispatched to the active canvas, draw commands following beginRecording() 308 // Instead of being dispatched to the active canvas, draw commands following beginRecording()
310 // are stored in a display list that can be replayed at a later time. 309 // are stored in a display list that can be replayed at a later time.
311 void beginRecording(const FloatRect& bounds); 310 void beginRecording(const FloatRect& bounds);
312 PassRefPtr<DisplayList> endRecording(); 311 PassRefPtr<DisplayList> endRecording();
313 312
313 bool hasShadow() const;
314 void setShadow(const FloatSize& offset, float blur, const Color&, 314 void setShadow(const FloatSize& offset, float blur, const Color&,
315 DrawLooper::ShadowTransformMode = DrawLooper::ShadowRespectsTransforms, 315 DrawLooper::ShadowTransformMode = DrawLooper::ShadowRespectsTransforms,
316 DrawLooper::ShadowAlphaMode = DrawLooper::ShadowRespectsAlpha); 316 DrawLooper::ShadowAlphaMode = DrawLooper::ShadowRespectsAlpha);
317 void clearShadow() { clearDrawLooper(); } 317 void clearShadow() { clearDrawLooper(); }
318 318
319 // It is assumed that this draw looper is used only for shadows 319 // It is assumed that this draw looper is used only for shadows
320 // (i.e. a draw looper is set if and only if there is a shadow). 320 // (i.e. a draw looper is set if and only if there is a shadow).
321 void setDrawLooper(const DrawLooper&); 321 void setDrawLooper(const DrawLooper&);
322 void clearDrawLooper(); 322 void clearDrawLooper();
323 323
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 value = -value; 405 value = -value;
406 isNeg = true; 406 isNeg = true;
407 } 407 }
408 if (value >= max) 408 if (value >= max)
409 value %= max; 409 value %= max;
410 if (isNeg) 410 if (isNeg)
411 value = -value; 411 value = -value;
412 return value; 412 return value;
413 } 413 }
414 414
415 // Sets up the common flags on a paint for antialiasing, effects, etc.
416 // This is implicitly called by setupPaintFill and setupPaintStroke, but
417 // you may wish to call it directly sometimes if you don't want that other
418 // behavior.
419 void setupPaintCommon(SkPaint*) const;
420
421 // Helpers for drawing a focus ring (drawFocusRing) 415 // Helpers for drawing a focus ring (drawFocusRing)
422 void drawOuterPath(const SkPath&, SkPaint&, int); 416 void drawOuterPath(const SkPath&, SkPaint&, int);
423 void drawInnerPath(const SkPath&, SkPaint&, int); 417 void drawInnerPath(const SkPath&, SkPaint&, int);
424 418
425 // SkCanvas wrappers. 419 // SkCanvas wrappers.
426 bool isDrawingToLayer() const { return m_canvas->isDrawingToLayer(); } 420 bool isDrawingToLayer() const { return m_canvas->isDrawingToLayer(); }
427 421
428 void clipPath(const SkPath&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op); 422 void clipPath(const SkPath&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op);
429 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion:: Op = SkRegion::kIntersect_Op); 423 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion:: Op = SkRegion::kIntersect_Op);
430 424
431 bool concat(const SkMatrix&); 425 bool concat(const SkMatrix&);
432 426
433 // common code between setupPaintFor[Filling,Stroking] 427 // common code between setupPaintFor[Filling,Stroking]
434 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const; 428 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const;
435 429
436 // Apply deferred paint state saves 430 // Apply deferred paint state saves
437 void realizePaintSave() 431 void realizePaintSave()
438 { 432 {
439 if (m_paintState->m_saveCount) { 433 if (m_paintState->saveCount()) {
440 --m_paintState->m_saveCount; 434 m_paintState->decrementSaveCount();
441 ++m_paintStateIndex; 435 ++m_paintStateIndex;
442 if (m_paintStateStack.size() == m_paintStateIndex) 436 if (m_paintStateStack.size() == m_paintStateIndex)
443 m_paintStateStack.append(GraphicsContextState::create()); 437 m_paintStateStack.append(GraphicsContextState::create());
444 GraphicsContextState* priorPaintState = m_paintState; 438 GraphicsContextState* priorPaintState = m_paintState;
445 m_paintState = m_paintStateStack[m_paintStateIndex].get(); 439 m_paintState = m_paintStateStack[m_paintStateIndex].get();
446 m_paintState->copy(priorPaintState); 440 m_paintState->copy(priorPaintState);
447 } 441 }
448 } 442 }
449 443
450 // Apply deferred canvas state saves 444 // Apply deferred canvas state saves
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // FIXME: Make this go away: crbug.com/236892 500 // FIXME: Make this go away: crbug.com/236892
507 bool m_updatingControlTints : 1; 501 bool m_updatingControlTints : 1;
508 bool m_accelerated : 1; 502 bool m_accelerated : 1;
509 bool m_isCertainlyOpaque : 1; 503 bool m_isCertainlyOpaque : 1;
510 bool m_printing : 1; 504 bool m_printing : 1;
511 }; 505 };
512 506
513 } // namespace WebCore 507 } // namespace WebCore
514 508
515 #endif // GraphicsContext_h 509 #endif // GraphicsContext_h
OLDNEW
« no previous file with comments | « Source/platform/graphics/Gradient.cpp ('k') | Source/platform/graphics/GraphicsContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698