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

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

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: apllied senorblanco feedback Created 5 years, 6 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) 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 #endif 102 #endif
103 103
104 float strokeThickness() const { return immutableState()->strokeData().thickn ess(); } 104 float strokeThickness() const { return immutableState()->strokeData().thickn ess(); }
105 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes s(thickness); } 105 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes s(thickness); }
106 106
107 StrokeStyle strokeStyle() const { return immutableState()->strokeData().styl e(); } 107 StrokeStyle strokeStyle() const { return immutableState()->strokeData().styl e(); }
108 void setStrokeStyle(StrokeStyle style) { mutableState()->setStrokeStyle(styl e); } 108 void setStrokeStyle(StrokeStyle style) { mutableState()->setStrokeStyle(styl e); }
109 109
110 Color strokeColor() const { return immutableState()->strokeColor(); } 110 Color strokeColor() const { return immutableState()->strokeColor(); }
111 void setStrokeColor(const Color& color) { mutableState()->setStrokeColor(col or); } 111 void setStrokeColor(const Color& color) { mutableState()->setStrokeColor(col or); }
112 SkColor effectiveStrokeColor() const { return immutableState()->effectiveStr okeColor(); }
113 112
114 Pattern* strokePattern() const { return immutableState()->strokePattern(); } 113 Pattern* strokePattern() const { return immutableState()->strokePattern(); }
115 void setStrokePattern(PassRefPtr<Pattern>, float alpha = 1); 114 void setStrokePattern(PassRefPtr<Pattern>, float alpha = 1);
116 115
117 Gradient* strokeGradient() const { return immutableState()->strokeGradient() ; } 116 Gradient* strokeGradient() const { return immutableState()->strokeGradient() ; }
118 void setStrokeGradient(PassRefPtr<Gradient>, float alpha = 1); 117 void setStrokeGradient(PassRefPtr<Gradient>, float alpha = 1);
119 118
120 void setLineCap(LineCap cap) { mutableState()->setLineCap(cap); } 119 void setLineCap(LineCap cap) { mutableState()->setLineCap(cap); }
121 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState() ->setLineDash(dashes, dashOffset); } 120 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState() ->setLineDash(dashes, dashOffset); }
122 void setLineJoin(LineJoin join) { mutableState()->setLineJoin(join); } 121 void setLineJoin(LineJoin join) { mutableState()->setLineJoin(join); }
123 void setMiterLimit(float limit) { mutableState()->setMiterLimit(limit); } 122 void setMiterLimit(float limit) { mutableState()->setMiterLimit(limit); }
124 123
125 void setFillRule(WindRule fillRule) { mutableState()->setFillRule(fillRule); } 124 void setFillRule(WindRule fillRule) { mutableState()->setFillRule(fillRule); }
126 125
127 Color fillColor() const { return immutableState()->fillColor(); } 126 Color fillColor() const { return immutableState()->fillColor(); }
128 void setFillColor(const Color& color) { mutableState()->setFillColor(color); } 127 void setFillColor(const Color& color) { mutableState()->setFillColor(color); }
129 128
130 void setFillPattern(PassRefPtr<Pattern>, float alpha = 1); 129 void setFillPattern(PassRefPtr<Pattern>, float alpha = 1);
131 130
132 void setFillGradient(PassRefPtr<Gradient>, float alpha = 1); 131 void setFillGradient(PassRefPtr<Gradient>, float alpha = 1);
133 132
134 SkDrawLooper* drawLooper() const { return immutableState()->drawLooper(); } 133 SkDrawLooper* drawLooper() const { return immutableState()->drawLooper(); }
135 134
136 SkMatrix getTotalMatrix() const; 135 SkMatrix getTotalMatrix() const;
137 136
138 void setShouldAntialias(bool antialias) { mutableState()->setShouldAntialias (antialias); } 137 void setShouldAntialias(bool antialias) { mutableState()->setShouldAntialias (antialias); }
139 bool shouldAntialias() const { return immutableState()->shouldAntialias(); } 138 bool shouldAntialias() const { return immutableState()->shouldAntialias(); }
140 139
141 // Disable the anti-aliasing optimization for scales/multiple-of-90-degrees
142 // rotations of thin ("hairline") images.
143 // Note: This will only be reliable when the device pixel scale/ratio is
144 // fixed (e.g. when drawing to context backed by an ImageBuffer).
145 void disableAntialiasingOptimizationForHairlineImages() { ASSERT(!isRecordin g()); m_antialiasHairlineImages = true; }
146 bool shouldAntialiasHairlineImages() const { return m_antialiasHairlineImage s; }
147
148 void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->se tShouldClampToSourceRect(clampToSourceRect); }
149 bool shouldClampToSourceRect() const { return immutableState()->shouldClampT oSourceRect(); }
150
151 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setText DrawingMode(mode); } 140 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setText DrawingMode(mode); }
152 TextDrawingModeFlags textDrawingMode() const { return immutableState()->text DrawingMode(); } 141 TextDrawingModeFlags textDrawingMode() const { return immutableState()->text DrawingMode(); }
153 142
154 void setAlphaAsFloat(float alpha) { mutableState()->setAlphaAsFloat(alpha);}
155 int getNormalizedAlpha() const
156 {
157 int alpha = immutableState()->alpha();
158 return alpha > 255 ? 255 : alpha;
159 }
160
161 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta te()->setInterpolationQuality(quality); } 143 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta te()->setInterpolationQuality(quality); }
162 InterpolationQuality imageInterpolationQuality() const { return immutableSta te()->interpolationQuality(); } 144 InterpolationQuality imageInterpolationQuality() const { return immutableSta te()->interpolationQuality(); }
163 145
164 // Do not use these methods: they are deprecated/scheduled for removal.
165 void setCompositeOperation(SkXfermode::Mode);
166 SkXfermode::Mode compositeOperation() const;
167
168 // Specify the device scale factor which may change the way document markers 146 // Specify the device scale factor which may change the way document markers
169 // and fonts are rendered. 147 // and fonts are rendered.
170 void setDeviceScaleFactor(float factor) { m_deviceScaleFactor = factor; } 148 void setDeviceScaleFactor(float factor) { m_deviceScaleFactor = factor; }
171 float deviceScaleFactor() const { return m_deviceScaleFactor; } 149 float deviceScaleFactor() const { return m_deviceScaleFactor; }
172 150
173 // Returns if the context is a printing context instead of a display 151 // Returns if the context is a printing context instead of a display
174 // context. Bitmap shouldn't be resampled when printing to keep the best 152 // context. Bitmap shouldn't be resampled when printing to keep the best
175 // possible quality. 153 // possible quality.
176 bool printing() const { return m_printing; } 154 bool printing() const { return m_printing; }
177 void setPrinting(bool printing) { m_printing = printing; } 155 void setPrinting(bool printing) { m_printing = printing; }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 SkXfermode::Mode = SkXfermode::kSrcOver_Mode, const IntSize& repeatSpaci ng = IntSize()); 197 SkXfermode::Mode = SkXfermode::kSrcOver_Mode, const IntSize& repeatSpaci ng = IntSize());
220 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, 198 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect,
221 const FloatSize& tileScaleFactor, Image::TileRule hRule = Image::Stretch Tile, Image::TileRule vRule = Image::StretchTile, 199 const FloatSize& tileScaleFactor, Image::TileRule hRule = Image::Stretch Tile, Image::TileRule vRule = Image::StretchTile,
222 SkXfermode::Mode = SkXfermode::kSrcOver_Mode); 200 SkXfermode::Mode = SkXfermode::kSrcOver_Mode);
223 201
224 void drawImageBuffer(ImageBuffer*, const FloatRect& destRect, const FloatRec t* srcRect = 0, SkXfermode::Mode = SkXfermode::kSrcOver_Mode); 202 void drawImageBuffer(ImageBuffer*, const FloatRect& destRect, const FloatRec t* srcRect = 0, SkXfermode::Mode = SkXfermode::kSrcOver_Mode);
225 203
226 // These methods write to the canvas. 204 // These methods write to the canvas.
227 // Also drawLine(const IntPoint& point1, const IntPoint& point2) and fillRou ndedRect 205 // Also drawLine(const IntPoint& point1, const IntPoint& point2) and fillRou ndedRect
228 void writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y); 206 void writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y);
229 void drawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkP aint* = 0);
230 void drawOval(const SkRect&, const SkPaint&); 207 void drawOval(const SkRect&, const SkPaint&);
231 void drawPath(const SkPath&, const SkPaint&); 208 void drawPath(const SkPath&, const SkPaint&);
232 void drawRect(const SkRect&, const SkPaint&); 209 void drawRect(const SkRect&, const SkPaint&);
233 210
234 void clip(const IntRect& rect) { clipRect(rect); } 211 void clip(const IntRect& rect) { clipRect(rect); }
235 void clip(const FloatRect& rect) { clipRect(rect); } 212 void clip(const FloatRect& rect) { clipRect(rect); }
236 void clipRoundedRect(const FloatRoundedRect&, SkRegion::Op = SkRegion::kInte rsect_Op); 213 void clipRoundedRect(const FloatRoundedRect&, SkRegion::Op = SkRegion::kInte rsect_Op);
237 void clipOut(const IntRect& rect) { clipRect(rect, NotAntiAliased, SkRegion: :kDifference_Op); } 214 void clipOut(const IntRect& rect) { clipRect(rect, NotAntiAliased, SkRegion: :kDifference_Op); }
238 void clipOut(const FloatRect& rect) { clipRect(rect, NotAntiAliased, SkRegio n::kDifference_Op); } 215 void clipOut(const FloatRect& rect) { clipRect(rect, NotAntiAliased, SkRegio n::kDifference_Op); }
239 void clipOut(const Path&); 216 void clipOut(const Path&);
(...skipping 23 matching lines...) Expand all
263 240
264 // Instead of being dispatched to the active canvas, draw commands following beginRecording() 241 // Instead of being dispatched to the active canvas, draw commands following beginRecording()
265 // are stored in a display list that can be replayed at a later time. Pass i n the bounding 242 // are stored in a display list that can be replayed at a later time. Pass i n the bounding
266 // rectangle for the content in the list. 243 // rectangle for the content in the list.
267 void beginRecording(const FloatRect&, uint32_t = 0); 244 void beginRecording(const FloatRect&, uint32_t = 0);
268 PassRefPtr<const SkPicture> endRecording(); 245 PassRefPtr<const SkPicture> endRecording();
269 246
270 void setShadow(const FloatSize& offset, float blur, const Color&, 247 void setShadow(const FloatSize& offset, float blur, const Color&,
271 DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespec tsTransforms, 248 DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespec tsTransforms,
272 DrawLooperBuilder::ShadowAlphaMode = DrawLooperBuilder::ShadowRespectsAl pha, ShadowMode = DrawShadowAndForeground); 249 DrawLooperBuilder::ShadowAlphaMode = DrawLooperBuilder::ShadowRespectsAl pha, ShadowMode = DrawShadowAndForeground);
273 void clearShadow() { clearDrawLooper(); clearDropShadowImageFilter(); }
274 void setDropShadowImageFilter(PassRefPtr<SkImageFilter>);
275 250
276 // It is assumed that this draw looper is used only for shadows 251 // It is assumed that this draw looper is used only for shadows
277 // (i.e. a draw looper is set if and only if there is a shadow). 252 // (i.e. a draw looper is set if and only if there is a shadow).
278 // The builder passed into this method will be destroyed. 253 // The builder passed into this method will be destroyed.
279 void setDrawLooper(PassOwnPtr<DrawLooperBuilder>); 254 void setDrawLooper(PassOwnPtr<DrawLooperBuilder>);
280 void setDrawLooper(PassRefPtr<SkDrawLooper> looper) { mutableState()->setDra wLooper(looper); }
281 void clearDrawLooper(); 255 void clearDrawLooper();
282 256
283 void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Colo r&); 257 void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Colo r&);
284 void drawFocusRing(const Path&, int width, int offset, const Color&); 258 void drawFocusRing(const Path&, int width, int offset, const Color&);
285 259
286 enum Edge { 260 enum Edge {
287 NoEdge = 0, 261 NoEdge = 0,
288 TopEdge = 1 << 1, 262 TopEdge = 1 << 1,
289 RightEdge = 1 << 2, 263 RightEdge = 1 << 2,
290 BottomEdge = 1 << 3, 264 BottomEdge = 1 << 3,
291 LeftEdge = 1 << 4 265 LeftEdge = 1 << 4
292 }; 266 };
293 typedef unsigned Edges; 267 typedef unsigned Edges;
294 void drawInnerShadow(const FloatRoundedRect&, const Color& shadowColor, cons t IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges clippedEdges = N oEdge); 268 void drawInnerShadow(const FloatRoundedRect&, const Color& shadowColor, cons t IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges clippedEdges = N oEdge);
295 269
270 const SkPaint& fillPaint() const { return immutableState()->fillPaint(); }
271
296 // ---------- Transformation methods ----------------- 272 // ---------- Transformation methods -----------------
297 // Note that the getCTM method returns only the current transform from Blink 's perspective, 273 // Note that the getCTM method returns only the current transform from Blink 's perspective,
298 // which is not the final transform used to place content on screen. It cann ot be relied upon 274 // which is not the final transform used to place content on screen. It cann ot be relied upon
299 // for testing where a point will appear on screen or how large it will be. 275 // for testing where a point will appear on screen or how large it will be.
300 AffineTransform getCTM() const; 276 AffineTransform getCTM() const;
301 void concatCTM(const AffineTransform&); 277 void concatCTM(const AffineTransform&);
302 void setCTM(const AffineTransform&); 278 void setCTM(const AffineTransform&);
303 void setMatrix(const SkMatrix&); 279 void setMatrix(const SkMatrix&);
304 280
305 void scale(float x, float y); 281 void scale(float x, float y);
306 void rotate(float angleInRadians); 282 void rotate(float angleInRadians);
307 void translate(float x, float y); 283 void translate(float x, float y);
308 // ---------- End transformation methods ----------------- 284 // ---------- End transformation methods -----------------
309 285
286 SkFilterQuality computeFilterQuality(Image*, const FloatRect& dest, const Fl oatRect& src) const;
287 bool shouldAntialiasImages() { return shouldAntialias() && !getTotalMatrix() .rectStaysRect();}
Stephen White 2015/05/29 17:26:37 Aside: not new to this code, but this feels like a
288
310 // URL drawing 289 // URL drawing
311 void setURLForRect(const KURL&, const IntRect&); 290 void setURLForRect(const KURL&, const IntRect&);
312 void setURLFragmentForRect(const String& name, const IntRect&); 291 void setURLFragmentForRect(const String& name, const IntRect&);
313 void addURLTargetAtPoint(const String& name, const IntPoint&); 292 void addURLTargetAtPoint(const String& name, const IntPoint&);
314 293
315 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, floa t strokeWidth, StrokeStyle); 294 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, floa t strokeWidth, StrokeStyle);
316 295
317 // This method can potentially push saves onto the canvas. It returns the in itial save count,
318 // and should be balanced with a call to context->canvas()->restoreToCount(i nitialSaveCount).
319 WARN_UNUSED_RETURN int preparePaintForDrawRectToRect(
320 SkPaint*,
321 const SkRect& srcRect,
322 const SkRect& destRect,
323 SkXfermode::Mode,
324 bool isBitmapWithAlpha,
325 bool isLazyDecoded = false,
326 bool isDataComplete = true) const;
327
328 static int focusRingOutsetExtent(int offset, int width) 296 static int focusRingOutsetExtent(int offset, int width)
329 { 297 {
330 return focusRingOutset(offset) + (focusRingWidth(width) + 1) / 2; 298 return focusRingOutset(offset) + (focusRingWidth(width) + 1) / 2;
331 } 299 }
332 300
333 // public decl needed for OwnPtr wrapper. 301 // public decl needed for OwnPtr wrapper.
334 class RecordingState; 302 class RecordingState;
335 303
336 #if ENABLE(ASSERT) 304 #if ENABLE(ASSERT)
337 void setInDrawingRecorder(bool); 305 void setInDrawingRecorder(bool);
(...skipping 27 matching lines...) Expand all
365 static SkPMColor antiColors1(int); 333 static SkPMColor antiColors1(int);
366 static SkPMColor antiColors2(int); 334 static SkPMColor antiColors2(int);
367 static void draw1xMarker(SkBitmap*, int); 335 static void draw1xMarker(SkBitmap*, int);
368 static void draw2xMarker(SkBitmap*, int); 336 static void draw2xMarker(SkBitmap*, int);
369 #endif 337 #endif
370 338
371 void saveLayer(const SkRect* bounds, const SkPaint*); 339 void saveLayer(const SkRect* bounds, const SkPaint*);
372 void restoreLayer(); 340 void restoreLayer();
373 341
374 // Helpers for drawing a focus ring (drawFocusRing) 342 // Helpers for drawing a focus ring (drawFocusRing)
375 float prepareFocusRingPaint(SkPaint&, const Color&, int width) const;
376 void drawFocusRingPath(const SkPath&, const Color&, int width); 343 void drawFocusRingPath(const SkPath&, const Color&, int width);
377 void drawFocusRingRect(const SkRect&, const Color&, int width); 344 void drawFocusRingRect(const SkRect&, const Color&, int width);
378 345
379 // SkCanvas wrappers. 346 // SkCanvas wrappers.
380 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion:: Op = SkRegion::kIntersect_Op); 347 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion:: Op = SkRegion::kIntersect_Op);
381 void concat(const SkMatrix&); 348 void concat(const SkMatrix&);
382 void drawRRect(const SkRRect&, const SkPaint&); 349 void drawRRect(const SkRRect&, const SkPaint&);
383 350
384 void clearDropShadowImageFilter();
385 SkImageFilter* dropShadowImageFilter() const { return immutableState()->drop ShadowImageFilter(); }
386
387 // Apply deferred paint state saves 351 // Apply deferred paint state saves
388 void realizePaintSave() 352 void realizePaintSave()
389 { 353 {
390 if (contextDisabled()) 354 if (contextDisabled())
391 return; 355 return;
392 356
393 if (m_paintState->saveCount()) { 357 if (m_paintState->saveCount()) {
394 m_paintState->decrementSaveCount(); 358 m_paintState->decrementSaveCount();
395 ++m_paintStateIndex; 359 ++m_paintStateIndex;
396 if (m_paintStateStack.size() == m_paintStateIndex) { 360 if (m_paintStateStack.size() == m_paintStateIndex) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 bool m_disableDestructionChecks; 400 bool m_disableDestructionChecks;
437 bool m_inDrawingRecorder; 401 bool m_inDrawingRecorder;
438 #endif 402 #endif
439 403
440 const DisabledMode m_disabledState; 404 const DisabledMode m_disabledState;
441 405
442 float m_deviceScaleFactor; 406 float m_deviceScaleFactor;
443 407
444 unsigned m_accelerated : 1; 408 unsigned m_accelerated : 1;
445 unsigned m_printing : 1; 409 unsigned m_printing : 1;
446 unsigned m_antialiasHairlineImages : 1;
447 }; 410 };
448 411
449 } // namespace blink 412 } // namespace blink
450 413
451 #endif // GraphicsContext_h 414 #endif // GraphicsContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698