OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "platform/graphics/ImageBuffer.h" | 35 #include "platform/graphics/ImageBuffer.h" |
36 #include "platform/weborigin/KURL.h" | 36 #include "platform/weborigin/KURL.h" |
37 #include "third_party/skia/include/core/SkAnnotation.h" | 37 #include "third_party/skia/include/core/SkAnnotation.h" |
38 #include "third_party/skia/include/core/SkColorFilter.h" | 38 #include "third_party/skia/include/core/SkColorFilter.h" |
39 #include "third_party/skia/include/core/SkData.h" | 39 #include "third_party/skia/include/core/SkData.h" |
40 #include "third_party/skia/include/core/SkPicture.h" | 40 #include "third_party/skia/include/core/SkPicture.h" |
41 #include "third_party/skia/include/core/SkPictureRecorder.h" | 41 #include "third_party/skia/include/core/SkPictureRecorder.h" |
42 #include "third_party/skia/include/core/SkRRect.h" | 42 #include "third_party/skia/include/core/SkRRect.h" |
43 #include "third_party/skia/include/core/SkRefCnt.h" | 43 #include "third_party/skia/include/core/SkRefCnt.h" |
44 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 44 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
45 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | |
46 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 45 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
47 #include "third_party/skia/include/effects/SkPictureImageFilter.h" | 46 #include "third_party/skia/include/effects/SkPictureImageFilter.h" |
48 #include "third_party/skia/include/utils/SkNullCanvas.h" | 47 #include "third_party/skia/include/utils/SkNullCanvas.h" |
49 #include "wtf/Assertions.h" | 48 #include "wtf/Assertions.h" |
50 #include "wtf/MathExtras.h" | 49 #include "wtf/MathExtras.h" |
51 | 50 |
52 namespace blink { | 51 namespace blink { |
53 | 52 |
54 class GraphicsContext::RecordingState { | 53 class GraphicsContext::RecordingState { |
55 WTF_MAKE_FAST_ALLOCATED(GraphicsContext::RecordingState); | 54 WTF_MAKE_FAST_ALLOCATED(GraphicsContext::RecordingState); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 , m_paintStateIndex(0) | 96 , m_paintStateIndex(0) |
98 #if ENABLE(ASSERT) | 97 #if ENABLE(ASSERT) |
99 , m_layerCount(0) | 98 , m_layerCount(0) |
100 , m_disableDestructionChecks(false) | 99 , m_disableDestructionChecks(false) |
101 , m_inDrawingRecorder(false) | 100 , m_inDrawingRecorder(false) |
102 #endif | 101 #endif |
103 , m_disabledState(disableContextOrPainting) | 102 , m_disabledState(disableContextOrPainting) |
104 , m_deviceScaleFactor(1.0f) | 103 , m_deviceScaleFactor(1.0f) |
105 , m_accelerated(false) | 104 , m_accelerated(false) |
106 , m_printing(false) | 105 , m_printing(false) |
107 , m_antialiasHairlineImages(false) | |
108 { | 106 { |
109 // FIXME: Do some tests to determine how many states are typically used, and
allocate | 107 // FIXME: Do some tests to determine how many states are typically used, and
allocate |
110 // several here. | 108 // several here. |
111 m_paintStateStack.append(GraphicsContextState::create()); | 109 m_paintStateStack.append(GraphicsContextState::create()); |
112 m_paintState = m_paintStateStack.last().get(); | 110 m_paintState = m_paintStateStack.last().get(); |
113 | 111 |
114 if (contextDisabled()) { | 112 if (contextDisabled()) { |
115 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull
Canvas()))); | 113 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull
Canvas()))); |
116 m_canvas = nullCanvas.get(); | 114 m_canvas = nullCanvas.get(); |
117 } | 115 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 if (contextDisabled()) | 270 if (contextDisabled()) |
273 return; | 271 return; |
274 | 272 |
275 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); | 273 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); |
276 if (!color.alpha()) { | 274 if (!color.alpha()) { |
277 if (shadowMode == DrawShadowOnly) { | 275 if (shadowMode == DrawShadowOnly) { |
278 // shadow only, but there is no shadow: use an empty draw looper to
disable rendering of the source primitive | 276 // shadow only, but there is no shadow: use an empty draw looper to
disable rendering of the source primitive |
279 setDrawLooper(drawLooperBuilder.release()); | 277 setDrawLooper(drawLooperBuilder.release()); |
280 return; | 278 return; |
281 } | 279 } |
282 clearShadow(); | 280 clearDrawLooper(); |
283 return; | 281 return; |
284 } | 282 } |
285 | 283 |
286 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado
wAlphaMode); | 284 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado
wAlphaMode); |
287 if (shadowMode == DrawShadowAndForeground) { | 285 if (shadowMode == DrawShadowAndForeground) { |
288 drawLooperBuilder->addUnmodifiedContent(); | 286 drawLooperBuilder->addUnmodifiedContent(); |
289 } | 287 } |
290 setDrawLooper(drawLooperBuilder.release()); | 288 setDrawLooper(drawLooperBuilder.release()); |
291 | |
292 if (shadowTransformMode == DrawLooperBuilder::ShadowIgnoresTransforms | |
293 && shadowAlphaMode == DrawLooperBuilder::ShadowRespectsAlpha) { | |
294 // This image filter will be used in place of the drawLooper created abo
ve but only for drawing non-opaque bitmaps; | |
295 // see preparePaintForDrawRectToRect(). | |
296 SkColor skColor = color.rgb(); | |
297 // These constants are from RadiusToSigma() from DrawLooperBuilder.cpp. | |
298 const SkScalar sigma = 0.288675f * blur + 0.5f; | |
299 SkDropShadowImageFilter::ShadowMode dropShadowMode = shadowMode == DrawS
hadowAndForeground ? SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMod
e : SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode; | |
300 RefPtr<SkImageFilter> filter = adoptRef(SkDropShadowImageFilter::Create(
offset.width(), offset.height(), sigma, sigma, skColor, dropShadowMode)); | |
301 setDropShadowImageFilter(filter); | |
302 } | |
303 } | 289 } |
304 | 290 |
305 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil
der) | 291 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil
der) |
306 { | 292 { |
307 if (contextDisabled()) | 293 if (contextDisabled()) |
308 return; | 294 return; |
309 | 295 |
310 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); | 296 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); |
311 } | 297 } |
312 | 298 |
313 void GraphicsContext::clearDrawLooper() | 299 void GraphicsContext::clearDrawLooper() |
314 { | 300 { |
315 if (contextDisabled()) | 301 if (contextDisabled()) |
316 return; | 302 return; |
317 | 303 |
318 mutableState()->clearDrawLooper(); | 304 mutableState()->clearDrawLooper(); |
319 } | 305 } |
320 | 306 |
321 void GraphicsContext::setDropShadowImageFilter(PassRefPtr<SkImageFilter> imageFi
lter) | |
322 { | |
323 if (contextDisabled()) | |
324 return; | |
325 | |
326 mutableState()->setDropShadowImageFilter(imageFilter); | |
327 } | |
328 | |
329 void GraphicsContext::clearDropShadowImageFilter() | |
330 { | |
331 if (contextDisabled()) | |
332 return; | |
333 | |
334 mutableState()->clearDropShadowImageFilter(); | |
335 } | |
336 | |
337 SkMatrix GraphicsContext::getTotalMatrix() const | 307 SkMatrix GraphicsContext::getTotalMatrix() const |
338 { | 308 { |
339 // FIXME: this is a hack to avoid changing all call sites of getTotalMatrix(
) to not use this method. | 309 // FIXME: this is a hack to avoid changing all call sites of getTotalMatrix(
) to not use this method. |
340 // The code needs to be cleand up after Slimming Paint is launched. | 310 // The code needs to be cleand up after Slimming Paint is launched. |
341 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 311 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
342 return SkMatrix::I(); | 312 return SkMatrix::I(); |
343 | 313 |
344 if (contextDisabled() || !m_canvas) | 314 if (contextDisabled() || !m_canvas) |
345 return SkMatrix::I(); | 315 return SkMatrix::I(); |
346 | 316 |
347 ASSERT(m_canvas); | 317 ASSERT(m_canvas); |
348 | 318 |
349 if (!isRecording()) | 319 if (!isRecording()) |
350 return m_canvas->getTotalMatrix(); | 320 return m_canvas->getTotalMatrix(); |
351 | 321 |
352 SkMatrix totalMatrix = m_recordingStateStack.last()->matrix(); | 322 SkMatrix totalMatrix = m_recordingStateStack.last()->matrix(); |
353 totalMatrix.preConcat(m_canvas->getTotalMatrix()); | 323 totalMatrix.preConcat(m_canvas->getTotalMatrix()); |
354 | 324 |
355 return totalMatrix; | 325 return totalMatrix; |
356 } | 326 } |
357 | 327 |
358 void GraphicsContext::setCompositeOperation(SkXfermode::Mode xferMode) | |
359 { | |
360 if (contextDisabled()) | |
361 return; | |
362 mutableState()->setCompositeOperation(xferMode); | |
363 } | |
364 | |
365 SkXfermode::Mode GraphicsContext::compositeOperation() const | |
366 { | |
367 return immutableState()->compositeOperation(); | |
368 } | |
369 | |
370 SkColorFilter* GraphicsContext::colorFilter() const | 328 SkColorFilter* GraphicsContext::colorFilter() const |
371 { | 329 { |
372 return immutableState()->colorFilter(); | 330 return immutableState()->colorFilter(); |
373 } | 331 } |
374 | 332 |
375 void GraphicsContext::setColorFilter(ColorFilter colorFilter) | 333 void GraphicsContext::setColorFilter(ColorFilter colorFilter) |
376 { | 334 { |
377 GraphicsContextState* stateToSet = mutableState(); | 335 GraphicsContextState* stateToSet = mutableState(); |
378 | 336 |
379 // We only support one active color filter at the moment. If (when) this bec
omes a problem, | 337 // We only support one active color filter at the moment. If (when) this bec
omes a problem, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 SkPaint layerPaint; | 371 SkPaint layerPaint; |
414 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); | 372 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); |
415 layerPaint.setXfermodeMode(xfermode); | 373 layerPaint.setXfermodeMode(xfermode); |
416 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g
et()); | 374 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g
et()); |
417 layerPaint.setImageFilter(imageFilter); | 375 layerPaint.setImageFilter(imageFilter); |
418 | 376 |
419 if (bounds) { | 377 if (bounds) { |
420 SkRect skBounds = WebCoreFloatRectToSKRect(*bounds); | 378 SkRect skBounds = WebCoreFloatRectToSKRect(*bounds); |
421 saveLayer(&skBounds, &layerPaint); | 379 saveLayer(&skBounds, &layerPaint); |
422 } else { | 380 } else { |
423 saveLayer(0, &layerPaint); | 381 saveLayer(nullptr, &layerPaint); |
424 } | 382 } |
425 | 383 |
426 #if ENABLE(ASSERT) | 384 #if ENABLE(ASSERT) |
427 ++m_layerCount; | 385 ++m_layerCount; |
428 #endif | 386 #endif |
429 } | 387 } |
430 | 388 |
431 void GraphicsContext::endLayer() | 389 void GraphicsContext::endLayer() |
432 { | 390 { |
433 if (contextDisabled()) | 391 if (contextDisabled()) |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); | 837 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); |
880 SkRect r; | 838 SkRect r; |
881 r.fLeft = WebCoreFloatToSkScalar(pt.x()); | 839 r.fLeft = WebCoreFloatToSkScalar(pt.x()); |
882 // Avoid anti-aliasing lines. Currently, these are always horizontal. | 840 // Avoid anti-aliasing lines. Currently, these are always horizontal. |
883 // Round to nearest pixel to match text and other content. | 841 // Round to nearest pixel to match text and other content. |
884 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f)); | 842 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f)); |
885 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width); | 843 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width); |
886 r.fBottom = r.fTop + SkIntToScalar(thickness); | 844 r.fBottom = r.fTop + SkIntToScalar(thickness); |
887 paint = immutableState()->fillPaint(); | 845 paint = immutableState()->fillPaint(); |
888 // Text lines are drawn using the stroke color. | 846 // Text lines are drawn using the stroke color. |
889 paint.setColor(effectiveStrokeColor()); | 847 paint.setColor(strokeColor().rgb()); |
890 drawRect(r, paint); | 848 drawRect(r, paint); |
891 return; | 849 return; |
892 } | 850 } |
893 case DottedStroke: | 851 case DottedStroke: |
894 case DashedStroke: { | 852 case DashedStroke: { |
895 int y = floorf(pt.y() + std::max<float>(strokeThickness() / 2.0f, 0.5f))
; | 853 int y = floorf(pt.y() + std::max<float>(strokeThickness() / 2.0f, 0.5f))
; |
896 drawLine(IntPoint(pt.x(), y), IntPoint(pt.x() + width, y)); | 854 drawLine(IntPoint(pt.x(), y), IntPoint(pt.x() + width, y)); |
897 return; | 855 return; |
898 } | 856 } |
899 } | 857 } |
(...skipping 13 matching lines...) Expand all Loading... |
913 | 871 |
914 SkRect skRect = rect; | 872 SkRect skRect = rect; |
915 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000
00; | 873 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000
00; |
916 if (fillcolorNotTransparent) | 874 if (fillcolorNotTransparent) |
917 drawRect(skRect, immutableState()->fillPaint()); | 875 drawRect(skRect, immutableState()->fillPaint()); |
918 | 876 |
919 if (immutableState()->strokeData().style() != NoStroke | 877 if (immutableState()->strokeData().style() != NoStroke |
920 && immutableState()->strokeColor().alpha()) { | 878 && immutableState()->strokeColor().alpha()) { |
921 // Stroke a width: 1 inset border | 879 // Stroke a width: 1 inset border |
922 SkPaint paint(immutableState()->fillPaint()); | 880 SkPaint paint(immutableState()->fillPaint()); |
923 paint.setColor(effectiveStrokeColor()); | 881 paint.setColor(strokeColor().rgb()); |
924 paint.setStyle(SkPaint::kStroke_Style); | 882 paint.setStyle(SkPaint::kStroke_Style); |
925 paint.setStrokeWidth(1); | 883 paint.setStrokeWidth(1); |
926 | 884 |
927 skRect.inset(0.5f, 0.5f); | 885 skRect.inset(0.5f, 0.5f); |
928 drawRect(skRect, paint); | 886 drawRect(skRect, paint); |
929 } | 887 } |
930 } | 888 } |
931 | 889 |
932 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point, const SkPaint& paint) | 890 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point, const SkPaint& paint) |
933 { | 891 { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 { | 962 { |
1005 if (!image) | 963 if (!image) |
1006 return; | 964 return; |
1007 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size
())), op, shouldRespectImageOrientation); | 965 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size
())), op, shouldRespectImageOrientation); |
1008 } | 966 } |
1009 | 967 |
1010 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
Rect& src, SkXfermode::Mode op, RespectImageOrientationEnum shouldRespectImageOr
ientation) | 968 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
Rect& src, SkXfermode::Mode op, RespectImageOrientationEnum shouldRespectImageOr
ientation) |
1011 { | 969 { |
1012 if (contextDisabled() || !image) | 970 if (contextDisabled() || !image) |
1013 return; | 971 return; |
1014 image->draw(this, dest, src, op, shouldRespectImageOrientation); | 972 |
| 973 SkPaint imagePaint = immutableState()->fillPaint(); |
| 974 imagePaint.setXfermodeMode(op); |
| 975 imagePaint.setColor(SK_ColorBLACK); |
| 976 GraphicsContextImageFilterQualityHelper filterHelper(this); |
| 977 image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation,
&filterHelper); |
| 978 } |
| 979 |
| 980 SkFilterQuality GraphicsContextImageFilterQualityHelper::computeFilterQuality(Im
age* image, const FloatRect& dest, const FloatRect& src) const |
| 981 { |
| 982 InterpolationQuality resampling; |
| 983 if (m_context->printing()) { |
| 984 resampling = InterpolationNone; |
| 985 } else if (image->isLazyDecodedBitmap()) { |
| 986 resampling = InterpolationHigh; |
| 987 } else { |
| 988 // Take into account scale applied to the canvas when computing sampling
mode (e.g. CSS scale or page scale). |
| 989 // FIXME: In slimming paint, we create GCs on the fly when entering a ne
w DisplayItemList |
| 990 // scope, so relying on getTotalMatrix here is not sound. |
| 991 SkRect destRectTarget = dest; |
| 992 SkMatrix totalMatrix = m_context->getTotalMatrix(); |
| 993 if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPersp
ective_Mask))) |
| 994 totalMatrix.mapRect(&destRectTarget, dest); |
| 995 |
| 996 resampling = computeInterpolationQuality(totalMatrix, |
| 997 SkScalarToFloat(src.width()), SkScalarToFloat(src.height()), |
| 998 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar
get.height()), |
| 999 image->isImmutableBitmap()); |
| 1000 } |
| 1001 |
| 1002 if (resampling == InterpolationNone) { |
| 1003 // FIXME: This is to not break tests (it results in the filter bitmap fl
ag |
| 1004 // being set to true). We need to decide if we respect InterpolationNone |
| 1005 // being returned from computeInterpolationQuality. |
| 1006 resampling = InterpolationLow; |
| 1007 } |
| 1008 return static_cast<SkFilterQuality>(limitInterpolationQuality(m_context, res
ampling)); |
| 1009 } |
| 1010 |
| 1011 bool GraphicsContextImageFilterQualityHelper::shouldDrawAntiAliased(const FloatR
ect& /*destRect*/) const |
| 1012 { |
| 1013 if (!m_context->shouldAntialias()) |
| 1014 return false; |
| 1015 // Disable anti-aliasing if we're not rotated or skewed. |
| 1016 // TODO(junov): crbug.com/492187 This code will disable antialiasing |
| 1017 // regardless of whether content is pixel aligned. Is this correct? |
| 1018 // For now, just preserving legacy behavior. |
| 1019 return !m_context->getTotalMatrix().rectStaysRect(); |
1015 } | 1020 } |
1016 | 1021 |
1017 void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, cons
t IntPoint& srcPoint, const IntSize& tileSize, SkXfermode::Mode op, const IntSiz
e& repeatSpacing) | 1022 void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, cons
t IntPoint& srcPoint, const IntSize& tileSize, SkXfermode::Mode op, const IntSiz
e& repeatSpacing) |
1018 { | 1023 { |
1019 if (contextDisabled() || !image) | 1024 if (contextDisabled() || !image) |
1020 return; | 1025 return; |
1021 image->drawTiled(this, destRect, srcPoint, tileSize, op, repeatSpacing); | 1026 image->drawTiled(this, destRect, srcPoint, tileSize, op, repeatSpacing); |
1022 } | 1027 } |
1023 | 1028 |
1024 void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const In
tRect& srcRect, | 1029 void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const In
tRect& srcRect, |
(...skipping 22 matching lines...) Expand all Loading... |
1047 | 1052 |
1048 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s
ize_t rowBytes, int x, int y) | 1053 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s
ize_t rowBytes, int x, int y) |
1049 { | 1054 { |
1050 if (contextDisabled()) | 1055 if (contextDisabled()) |
1051 return; | 1056 return; |
1052 ASSERT(m_canvas); | 1057 ASSERT(m_canvas); |
1053 | 1058 |
1054 m_canvas->writePixels(info, pixels, rowBytes, x, y); | 1059 m_canvas->writePixels(info, pixels, rowBytes, x, y); |
1055 } | 1060 } |
1056 | 1061 |
1057 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | |
1058 const SkRect& dst, const SkPaint* paint) | |
1059 { | |
1060 // Textures are bound to the blink main-thread GrContext, which can not be | |
1061 // used on the compositor raster thread. | |
1062 // FIXME: Mailbox support would make this possible in the GPU-raster case. | |
1063 // If we're printing it is safe to access the texture because we are always | |
1064 // on main thread, even if the other conditions are not met. | |
1065 ASSERT(!isRecording() || !bitmap.getTexture() || printing()); | |
1066 if (contextDisabled()) | |
1067 return; | |
1068 | |
1069 SkCanvas::DrawBitmapRectFlags flags = | |
1070 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap
RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | |
1071 | |
1072 ASSERT(m_canvas); | |
1073 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); | |
1074 } | |
1075 | |
1076 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) | 1062 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) |
1077 { | 1063 { |
1078 if (contextDisabled()) | 1064 if (contextDisabled()) |
1079 return; | 1065 return; |
1080 ASSERT(m_canvas); | 1066 ASSERT(m_canvas); |
1081 | 1067 |
1082 m_canvas->drawOval(oval, paint); | 1068 m_canvas->drawOval(oval, paint); |
1083 } | 1069 } |
1084 | 1070 |
1085 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) | 1071 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 return; | 1118 return; |
1133 | 1119 |
1134 drawRect(rect, immutableState()->fillPaint()); | 1120 drawRect(rect, immutableState()->fillPaint()); |
1135 } | 1121 } |
1136 | 1122 |
1137 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer
mode::Mode xferMode) | 1123 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer
mode::Mode xferMode) |
1138 { | 1124 { |
1139 if (contextDisabled()) | 1125 if (contextDisabled()) |
1140 return; | 1126 return; |
1141 | 1127 |
1142 if (color == fillColor() && xferMode == compositeOperation()) { | |
1143 drawRect(rect, immutableState()->fillPaint()); | |
1144 return; | |
1145 } | |
1146 | |
1147 SkPaint paint = immutableState()->fillPaint(); | 1128 SkPaint paint = immutableState()->fillPaint(); |
1148 paint.setColor(color.rgb()); | 1129 paint.setColor(color.rgb()); |
1149 paint.setXfermodeMode(xferMode); | 1130 paint.setXfermodeMode(xferMode); |
1150 | 1131 |
1151 drawRect(rect, paint); | 1132 drawRect(rect, paint); |
1152 } | 1133 } |
1153 | 1134 |
1154 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rrect, const Color
& color) | 1135 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rrect, const Color
& color) |
1155 { | 1136 { |
1156 if (contextDisabled()) | 1137 if (contextDisabled()) |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 { | 1622 { |
1642 static const SkPMColor colors[] = { | 1623 static const SkPMColor colors[] = { |
1643 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1624 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
1644 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1625 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
1645 }; | 1626 }; |
1646 | 1627 |
1647 return colors[index]; | 1628 return colors[index]; |
1648 } | 1629 } |
1649 #endif | 1630 #endif |
1650 | 1631 |
1651 int GraphicsContext::preparePaintForDrawRectToRect( | |
1652 SkPaint* paint, | |
1653 const SkRect& srcRect, | |
1654 const SkRect& destRect, | |
1655 SkXfermode::Mode compositeOp, | |
1656 bool isBitmapWithAlpha, | |
1657 bool isLazyDecoded, | |
1658 bool isDataComplete) const | |
1659 { | |
1660 int initialSaveCount = m_canvas->getSaveCount(); | |
1661 | |
1662 paint->setColorFilter(this->colorFilter()); | |
1663 paint->setAlpha(this->getNormalizedAlpha()); | |
1664 bool usingImageFilter = false; | |
1665 if (dropShadowImageFilter() && isBitmapWithAlpha) { | |
1666 SkMatrix ctm = getTotalMatrix(); | |
1667 SkMatrix invCtm; | |
1668 if (ctm.invert(&invCtm)) { | |
1669 usingImageFilter = true; | |
1670 // The image filter is meant to ignore tranforms with respect to | |
1671 // the shadow parameters. The matrix tweaks below ensures that the i
mage | |
1672 // filter is applied in post-transform space. We use concat() instea
d of | |
1673 // setMatrix() in case this goes into a recording canvas which may n
eed to | |
1674 // respect a parent transform at playback time. | |
1675 m_canvas->save(); | |
1676 m_canvas->concat(invCtm); | |
1677 SkRect bounds = destRect; | |
1678 ctm.mapRect(&bounds); | |
1679 SkRect filteredBounds; | |
1680 dropShadowImageFilter()->computeFastBounds(bounds, &filteredBounds); | |
1681 SkPaint layerPaint; | |
1682 layerPaint.setXfermodeMode(compositeOp); | |
1683 layerPaint.setImageFilter(dropShadowImageFilter()); | |
1684 m_canvas->saveLayer(&filteredBounds, &layerPaint); | |
1685 m_canvas->concat(ctm); | |
1686 } | |
1687 } | |
1688 | |
1689 if (!usingImageFilter) { | |
1690 paint->setXfermodeMode(compositeOp); | |
1691 paint->setLooper(this->drawLooper()); | |
1692 } | |
1693 | |
1694 paint->setAntiAlias(shouldDrawAntiAliased(this, destRect)); | |
1695 | |
1696 InterpolationQuality resampling; | |
1697 if (this->isAccelerated()) { | |
1698 resampling = InterpolationLow; | |
1699 } else if (this->printing()) { | |
1700 resampling = InterpolationNone; | |
1701 } else if (isLazyDecoded) { | |
1702 resampling = InterpolationHigh; | |
1703 } else { | |
1704 // Take into account scale applied to the canvas when computing sampling
mode (e.g. CSS scale or page scale). | |
1705 SkRect destRectTarget = destRect; | |
1706 SkMatrix totalMatrix = this->getTotalMatrix(); | |
1707 if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPersp
ective_Mask))) | |
1708 totalMatrix.mapRect(&destRectTarget, destRect); | |
1709 | |
1710 resampling = computeInterpolationQuality(totalMatrix, | |
1711 SkScalarToFloat(srcRect.width()), SkScalarToFloat(srcRect.height()), | |
1712 SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTar
get.height()), | |
1713 isDataComplete); | |
1714 } | |
1715 | |
1716 if (resampling == InterpolationNone) { | |
1717 // FIXME: This is to not break tests (it results in the filter bitmap fl
ag | |
1718 // being set to true). We need to decide if we respect InterpolationNone | |
1719 // being returned from computeInterpolationQuality. | |
1720 resampling = InterpolationLow; | |
1721 } | |
1722 resampling = limitInterpolationQuality(this, resampling); | |
1723 paint->setFilterQuality(static_cast<SkFilterQuality>(resampling)); | |
1724 | |
1725 return initialSaveCount; | |
1726 } | |
1727 | |
1728 } // namespace blink | 1632 } // namespace blink |
OLD | NEW |