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

Side by Side Diff: Source/core/paint/BoxPainter.cpp

Issue 868743002: Use SkXfermode::Mode in code related to Image. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase to ToT Created 5 years, 11 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
« no previous file with comments | « Source/core/paint/BoxPainter.h ('k') | Source/core/paint/ImagePainter.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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/paint/BoxPainter.h" 6 #include "core/paint/BoxPainter.h"
7 7
8 #include "core/HTMLNames.h" 8 #include "core/HTMLNames.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/html/HTMLFrameOwnerElement.h" 10 #include "core/html/HTMLFrameOwnerElement.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 void BoxPainter::paintRootBoxFillLayers(const PaintInfo& paintInfo) 137 void BoxPainter::paintRootBoxFillLayers(const PaintInfo& paintInfo)
138 { 138 {
139 if (paintInfo.skipRootBackground()) 139 if (paintInfo.skipRootBackground())
140 return; 140 return;
141 141
142 RenderObject* rootBackgroundRenderer = m_renderBox.rendererForRootBackground (); 142 RenderObject* rootBackgroundRenderer = m_renderBox.rendererForRootBackground ();
143 143
144 const FillLayer& bgLayer = rootBackgroundRenderer->style()->backgroundLayers (); 144 const FillLayer& bgLayer = rootBackgroundRenderer->style()->backgroundLayers ();
145 Color bgColor = rootBackgroundRenderer->resolveColor(CSSPropertyBackgroundCo lor); 145 Color bgColor = rootBackgroundRenderer->resolveColor(CSSPropertyBackgroundCo lor);
146 146
147 paintFillLayers(paintInfo, bgColor, bgLayer, m_renderBox.view()->backgroundR ect(&m_renderBox), BackgroundBleedNone, CompositeSourceOver, rootBackgroundRende rer); 147 paintFillLayers(paintInfo, bgColor, bgLayer, m_renderBox.view()->backgroundR ect(&m_renderBox), BackgroundBleedNone, SkXfermode::kSrcOver_Mode, rootBackgroun dRenderer);
148 } 148 }
149 149
150 void BoxPainter::paintFillLayers(const PaintInfo& paintInfo, const Color& c, con st FillLayer& fillLayer, const LayoutRect& rect, 150 void BoxPainter::paintFillLayers(const PaintInfo& paintInfo, const Color& c, con st FillLayer& fillLayer, const LayoutRect& rect,
151 BackgroundBleedAvoidance bleedAvoidance, CompositeOperator op, RenderObject* backgroundObject) 151 BackgroundBleedAvoidance bleedAvoidance, SkXfermode::Mode op, RenderObject* backgroundObject)
152 { 152 {
153 Vector<const FillLayer*, 8> layers; 153 Vector<const FillLayer*, 8> layers;
154 const FillLayer* curLayer = &fillLayer; 154 const FillLayer* curLayer = &fillLayer;
155 bool shouldDrawBackgroundInSeparateBuffer = false; 155 bool shouldDrawBackgroundInSeparateBuffer = false;
156 bool isBottomLayerOccluded = false; 156 bool isBottomLayerOccluded = false;
157 while (curLayer) { 157 while (curLayer) {
158 layers.append(curLayer); 158 layers.append(curLayer);
159 // Stop traversal when an opaque layer is encountered. 159 // Stop traversal when an opaque layer is encountered.
160 // FIXME : It would be possible for the following occlusion culling test to be more aggressive 160 // FIXME : It would be possible for the following occlusion culling test to be more aggressive
161 // on layers with no repeat by testing whether the image covers the layo ut rect. 161 // on layers with no repeat by testing whether the image covers the layo ut rect.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 Vector<const FillLayer*>::const_reverse_iterator topLayer = layers.rend(); 201 Vector<const FillLayer*>::const_reverse_iterator topLayer = layers.rend();
202 for (Vector<const FillLayer*>::const_reverse_iterator it = layers.rbegin(); it != topLayer; ++it) 202 for (Vector<const FillLayer*>::const_reverse_iterator it = layers.rbegin(); it != topLayer; ++it)
203 paintFillLayer(paintInfo, c, **it, rect, bleedAvoidance, op, backgroundO bject, skipBaseColor); 203 paintFillLayer(paintInfo, c, **it, rect, bleedAvoidance, op, backgroundO bject, skipBaseColor);
204 204
205 if (shouldDrawBackgroundInSeparateBuffer) 205 if (shouldDrawBackgroundInSeparateBuffer)
206 context->endLayer(); 206 context->endLayer();
207 } 207 }
208 208
209 void BoxPainter::paintFillLayer(const PaintInfo& paintInfo, const Color& c, cons t FillLayer& fillLayer, const LayoutRect& rect, 209 void BoxPainter::paintFillLayer(const PaintInfo& paintInfo, const Color& c, cons t FillLayer& fillLayer, const LayoutRect& rect,
210 BackgroundBleedAvoidance bleedAvoidance, CompositeOperator op, RenderObject* backgroundObject, bool skipBaseColor) 210 BackgroundBleedAvoidance bleedAvoidance, SkXfermode::Mode op, RenderObject* backgroundObject, bool skipBaseColor)
211 { 211 {
212 BoxPainter::paintFillLayerExtended(m_renderBox, paintInfo, c, fillLayer, rec t, bleedAvoidance, 0, LayoutSize(), op, backgroundObject, skipBaseColor); 212 BoxPainter::paintFillLayerExtended(m_renderBox, paintInfo, c, fillLayer, rec t, bleedAvoidance, 0, LayoutSize(), op, backgroundObject, skipBaseColor);
213 } 213 }
214 214
215 void BoxPainter::applyBoxShadowForBackground(GraphicsContext* context, RenderObj ect& obj) 215 void BoxPainter::applyBoxShadowForBackground(GraphicsContext* context, RenderObj ect& obj)
216 { 216 {
217 const ShadowList* shadowList = obj.style()->boxShadow(); 217 const ShadowList* shadowList = obj.style()->boxShadow();
218 ASSERT(shadowList); 218 ASSERT(shadowList);
219 for (size_t i = shadowList->shadows().size(); i--; ) { 219 for (size_t i = shadowList->shadows().size(); i--; ) {
220 const ShadowData& boxShadow = shadowList->shadows()[i]; 220 const ShadowData& boxShadow = shadowList->shadows()[i];
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 FloatRect bottomCorner(clipRect.rect().x(), rect.y().toFloat(), rect .maxX() - clipRect.rect().x(), clipRect.rect().maxY() - rect.y().toFloat()); 290 FloatRect bottomCorner(clipRect.rect().x(), rect.y().toFloat(), rect .maxX() - clipRect.rect().x(), clipRect.rect().maxY() - rect.y().toFloat());
291 FloatRoundedRect::Radii bottomCornerRadii; 291 FloatRoundedRect::Radii bottomCornerRadii;
292 bottomCornerRadii.setBottomLeft(clipRect.radii().bottomLeft()); 292 bottomCornerRadii.setBottomLeft(clipRect.radii().bottomLeft());
293 context->clipRoundedRect(FloatRoundedRect(bottomCorner, bottomCorner Radii)); 293 context->clipRoundedRect(FloatRoundedRect(bottomCorner, bottomCorner Radii));
294 } 294 }
295 } 295 }
296 } 296 }
297 297
298 void BoxPainter::paintFillLayerExtended(RenderBoxModelObject& obj, const PaintIn fo& paintInfo, const Color& color, const FillLayer& bgLayer, const LayoutRect& r ect, 298 void BoxPainter::paintFillLayerExtended(RenderBoxModelObject& obj, const PaintIn fo& paintInfo, const Color& color, const FillLayer& bgLayer, const LayoutRect& r ect,
299 BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox* box, const LayoutSiz e& boxSize, CompositeOperator op, RenderObject* backgroundObject, bool skipBaseC olor) 299 BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox* box, const LayoutSiz e& boxSize, SkXfermode::Mode op, RenderObject* backgroundObject, bool skipBaseCo lor)
300 { 300 {
301 GraphicsContext* context = paintInfo.context; 301 GraphicsContext* context = paintInfo.context;
302 if (rect.isEmpty()) 302 if (rect.isEmpty())
303 return; 303 return;
304 304
305 bool includeLeftEdge = box ? box->includeLogicalLeftEdge() : true; 305 bool includeLeftEdge = box ? box->includeLogicalLeftEdge() : true;
306 bool includeRightEdge = box ? box->includeLogicalRightEdge() : true; 306 bool includeRightEdge = box ? box->includeLogicalRightEdge() : true;
307 307
308 bool hasRoundedBorder = obj.style()->hasBorderRadius() && (includeLeftEdge | | includeRightEdge); 308 bool hasRoundedBorder = obj.style()->hasBorderRadius() && (includeLeftEdge | | includeRightEdge);
309 bool clippedWithLocalScrolling = obj.hasOverflowClip() && bgLayer.attachment () == LocalBackgroundAttachment; 309 bool clippedWithLocalScrolling = obj.hasOverflowClip() && bgLayer.attachment () == LocalBackgroundAttachment;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 context->fillRect(backgroundRect, bgColor, context->compositeOpe rationDeprecated()); 467 context->fillRect(backgroundRect, bgColor, context->compositeOpe rationDeprecated());
468 } 468 }
469 } 469 }
470 } 470 }
471 471
472 // no progressive loading of the background image 472 // no progressive loading of the background image
473 if (shouldPaintBackgroundImage) { 473 if (shouldPaintBackgroundImage) {
474 BackgroundImageGeometry geometry; 474 BackgroundImageGeometry geometry;
475 calculateBackgroundImageGeometry(obj, paintInfo.paintContainer(), bgLaye r, scrolledPaintRect, geometry, backgroundObject); 475 calculateBackgroundImageGeometry(obj, paintInfo.paintContainer(), bgLaye r, scrolledPaintRect, geometry, backgroundObject);
476 if (!geometry.destRect().isEmpty()) { 476 if (!geometry.destRect().isEmpty()) {
477 CompositeOperator compositeOp = op == CompositeSourceOver ? bgLayer. composite() : op; 477 SkXfermode::Mode bgOp = WebCoreCompositeToSkiaComposite(bgLayer.comp osite(), bgLayer.blendMode());
478 // if op != SkXfermode::kSrcOver_Mode, a mask is being painted.
479 SkXfermode::Mode compositeOp = op == SkXfermode::kSrcOver_Mode ? bgO p : op;
478 RenderObject* clientForBackgroundImage = backgroundObject ? backgrou ndObject : &obj; 480 RenderObject* clientForBackgroundImage = backgroundObject ? backgrou ndObject : &obj;
479 RefPtr<Image> image = bgImage->image(clientForBackgroundImage, geome try.tileSize()); 481 RefPtr<Image> image = bgImage->image(clientForBackgroundImage, geome try.tileSize());
480 InterpolationQuality interpolationQuality = chooseInterpolationQuali ty(obj, context, image.get(), &bgLayer, LayoutSize(geometry.tileSize())); 482 InterpolationQuality interpolationQuality = chooseInterpolationQuali ty(obj, context, image.get(), &bgLayer, LayoutSize(geometry.tileSize()));
481 if (bgLayer.maskSourceType() == MaskLuminance) 483 if (bgLayer.maskSourceType() == MaskLuminance)
482 context->setColorFilter(ColorFilterLuminanceToAlpha); 484 context->setColorFilter(ColorFilterLuminanceToAlpha);
483 InterpolationQuality previousInterpolationQuality = context->imageIn terpolationQuality(); 485 InterpolationQuality previousInterpolationQuality = context->imageIn terpolationQuality();
484 context->setImageInterpolationQuality(interpolationQuality); 486 context->setImageInterpolationQuality(interpolationQuality);
485 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintI mage", "data", InspectorPaintImageEvent::data(obj, *bgImage)); 487 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintI mage", "data", InspectorPaintImageEvent::data(obj, *bgImage));
486 context->drawTiledImage(image.get(), geometry.destRect(), geometry.p hase(), geometry.tileSize(), 488 context->drawTiledImage(image.get(), geometry.destRect(), geometry.p hase(), geometry.tileSize(),
487 compositeOp, bgLayer.blendMode(), geometry.spaceSize()); 489 compositeOp, geometry.spaceSize());
488 context->setImageInterpolationQuality(previousInterpolationQuality); 490 context->setImageInterpolationQuality(previousInterpolationQuality);
489 } 491 }
490 } 492 }
491 493
492 if (bgLayer.clip() == TextFillBox) { 494 if (bgLayer.clip() == TextFillBox) {
493 // Create the text mask layer. 495 // Create the text mask layer.
494 context->setCompositeOperation(SkXfermode::kDstIn_Mode); 496 context->setCompositeOperation(SkXfermode::kDstIn_Mode);
495 context->beginTransparencyLayer(1); 497 context->beginTransparencyLayer(1);
496 498
497 // FIXME: Workaround for https://code.google.com/p/skia/issues/detail?id =1291. 499 // FIXME: Workaround for https://code.google.com/p/skia/issues/detail?id =1291.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if (maskBoxImage) 546 if (maskBoxImage)
545 allMaskImagesLoaded &= maskBoxImage->isLoaded(); 547 allMaskImagesLoaded &= maskBoxImage->isLoaded();
546 548
547 allMaskImagesLoaded &= maskLayers.imagesAreLoaded(); 549 allMaskImagesLoaded &= maskLayers.imagesAreLoaded();
548 550
549 paintInfo.context->setCompositeOperation(SkXfermode::kDstIn_Mode); 551 paintInfo.context->setCompositeOperation(SkXfermode::kDstIn_Mode);
550 paintInfo.context->beginTransparencyLayer(1); 552 paintInfo.context->beginTransparencyLayer(1);
551 } 553 }
552 554
553 if (allMaskImagesLoaded) { 555 if (allMaskImagesLoaded) {
554 paintFillLayers(paintInfo, Color::transparent, m_renderBox.style()->mask Layers(), paintRect, BackgroundBleedNone, CompositeSourceOver); 556 paintFillLayers(paintInfo, Color::transparent, m_renderBox.style()->mask Layers(), paintRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode);
555 paintNinePieceImage(m_renderBox, paintInfo.context, paintRect, m_renderB ox.style(), m_renderBox.style()->maskBoxImage(), CompositeSourceOver); 557 paintNinePieceImage(m_renderBox, paintInfo.context, paintRect, m_renderB ox.style(), m_renderBox.style()->maskBoxImage(), SkXfermode::kSrcOver_Mode);
556 } 558 }
557 559
558 if (pushTransparencyLayer) { 560 if (pushTransparencyLayer) {
559 paintInfo.context->endLayer(); 561 paintInfo.context->endLayer();
560 paintInfo.context->setCompositeOperation(previousCompositeOperation); 562 paintInfo.context->setCompositeOperation(previousCompositeOperation);
561 } 563 }
562 } 564 }
563 565
564 void BoxPainter::paintClippingMask(const PaintInfo& paintInfo, const LayoutPoint & paintOffset) 566 void BoxPainter::paintClippingMask(const PaintInfo& paintInfo, const LayoutPoint & paintOffset)
565 { 567 {
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 909
908 static LayoutUnit computeBorderImageSide(const BorderImageLength& borderSlice, L ayoutUnit borderSide, LayoutUnit imageSide, LayoutUnit boxExtent) 910 static LayoutUnit computeBorderImageSide(const BorderImageLength& borderSlice, L ayoutUnit borderSide, LayoutUnit imageSide, LayoutUnit boxExtent)
909 { 911 {
910 if (borderSlice.isNumber()) 912 if (borderSlice.isNumber())
911 return borderSlice.number() * borderSide; 913 return borderSlice.number() * borderSide;
912 if (borderSlice.length().isAuto()) 914 if (borderSlice.length().isAuto())
913 return imageSide; 915 return imageSide;
914 return valueForLength(borderSlice.length(), boxExtent); 916 return valueForLength(borderSlice.length(), boxExtent);
915 } 917 }
916 918
917 bool BoxPainter::paintNinePieceImage(RenderBoxModelObject& obj, GraphicsContext* graphicsContext, const LayoutRect& rect, const RenderStyle* style, const NinePi eceImage& ninePieceImage, CompositeOperator op) 919 bool BoxPainter::paintNinePieceImage(RenderBoxModelObject& obj, GraphicsContext* graphicsContext, const LayoutRect& rect, const RenderStyle* style, const NinePi eceImage& ninePieceImage, SkXfermode::Mode op)
918 { 920 {
919 StyleImage* styleImage = ninePieceImage.image(); 921 StyleImage* styleImage = ninePieceImage.image();
920 if (!styleImage) 922 if (!styleImage)
921 return false; 923 return false;
922 924
923 if (!styleImage->isLoaded()) 925 if (!styleImage->isLoaded())
924 return true; // Never paint a nine-piece image incrementally, but don't paint the fallback borders either. 926 return true; // Never paint a nine-piece image incrementally, but don't paint the fallback borders either.
925 927
926 if (!styleImage->canRender(obj, style->effectiveZoom())) 928 if (!styleImage->canRender(obj, style->effectiveZoom()))
927 return false; 929 return false;
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 2213
2212 FloatPoint secondQuad[4]; 2214 FloatPoint secondQuad[4];
2213 secondQuad[0] = quad[0]; 2215 secondQuad[0] = quad[0];
2214 secondQuad[1] = FloatPoint(quad[0].x() - r1 * cx, quad[0].y() - r1 * cy); 2216 secondQuad[1] = FloatPoint(quad[0].x() - r1 * cx, quad[0].y() - r1 * cy);
2215 secondQuad[2] = quad[2]; 2217 secondQuad[2] = quad[2];
2216 secondQuad[3] = quad[3]; 2218 secondQuad[3] = quad[3];
2217 graphicsContext->clipPolygon(4, secondQuad, !secondEdgeMatches); 2219 graphicsContext->clipPolygon(4, secondQuad, !secondEdgeMatches);
2218 } 2220 }
2219 2221
2220 } // namespace blink 2222 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/BoxPainter.h ('k') | Source/core/paint/ImagePainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698