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

Side by Side Diff: third_party/WebKit/Source/core/style/FillLayer.cpp

Issue 1787733003: Consolidate background fill layer opaqueness into one method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A new way to refactor Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 * 19 *
20 */ 20 */
21 21
22 #include "core/style/FillLayer.h" 22 #include "core/style/FillLayer.h"
23 23
24 #include "core/layout/LayoutObject.h"
24 #include "core/style/DataEquivalency.h" 25 #include "core/style/DataEquivalency.h"
25 26
26 namespace blink { 27 namespace blink {
27 28
28 struct SameSizeAsFillLayer { 29 struct SameSizeAsFillLayer {
29 FillLayer* m_next; 30 FillLayer* m_next;
30 31
31 RefPtrWillBePersistent<StyleImage> m_image; 32 RefPtrWillBePersistent<StyleImage> m_image;
32 33
33 Length m_xPosition; 34 Length m_xPosition;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 { 364 {
364 const FillLayer* curr; 365 const FillLayer* curr;
365 for (curr = this; curr; curr = curr->next()) { 366 for (curr = this; curr; curr = curr->next()) {
366 if (curr->m_image && !curr->m_image->isLoaded()) 367 if (curr->m_image && !curr->m_image->isLoaded())
367 return false; 368 return false;
368 } 369 }
369 370
370 return true; 371 return true;
371 } 372 }
372 373
373 bool FillLayer::hasOpaqueImage(const LayoutObject* layoutObject) const 374 bool FillLayer::imageIsOpaqueAndTilesLayer(const LayoutObject& layoutObject) con st
Stephen Chennney 2016/03/16 20:54:16 Put almost all the conditions surround images here
374 { 375 {
375 if (!m_image) 376 // Returns true if we have an image and tiling that will cover the content b elow it when
377 // m_composite == CompositeSourceOver && m_blendMode == WebBlendModeNormal.
378 // Otherwise false.
379 // TODO(schenney) We could relax the repeat mode requirement if we also knew the rect we
380 // had to fill, and the portion of the image we need to use, and know that t he latter
381 // covers the former
382 return m_image
383 && m_image->canRender()
Stephen Chennney 2016/03/16 20:54:16 Forgot to remove these. Will follow up.
384 && m_image->knownToBeOpaque(layoutObject)
385 && !m_image->imageSize(layoutObject, layoutObject.style()->effectiveZoom (), LayoutSize()).isEmpty()
386 && (m_repeatX == RepeatFill || m_repeatX == RoundFill)
387 && (m_repeatY == RepeatFill || m_repeatY == RoundFill);
388
389 }
390
391 bool FillLayer::imageOccludesNextLayers(const LayoutObject& layoutObject) const
Stephen Chennney 2016/03/16 20:54:16 Due to the compositing modes behavior, it's not re
392 {
393 // We can't cover without an image, regardless of other parameters
394 if (!m_image || !m_image->canRender())
376 return false; 395 return false;
377 396
378 // TODO(trchen): Should check blend mode before composite mode. 397 if (imageIsOpaqueAndTilesLayer(layoutObject)) {
379 if (m_composite == CompositeClear || m_composite == CompositeCopy) 398 // Check that the compositing and blend modes maintain the opaqueness
380 return true; 399 return (m_composite == CompositeClear
400 || m_composite == CompositeCopy
401 || m_composite == CompositeSourceOver)
402 && m_blendMode == WebBlendModeNormal;
403 }
381 404
382 if (m_blendMode != WebBlendModeNormal) 405 // The image is not opaque, but these composite modes overwrite the backgrou nd
383 return false; 406 // regardless of the foreground.
384 407 return (m_composite == CompositeClear || m_composite == CompositeCopy);
Stephen Chennney 2016/03/16 20:54:16 This is really the else clause, but we do not put
385 if (m_composite == CompositeSourceOver)
386 return m_image->knownToBeOpaque(*layoutObject);
387
388 return false;
389 }
390
391 bool FillLayer::hasRepeatXY() const
392 {
393 return m_repeatX == RepeatFill && m_repeatY == RepeatFill;
394 } 408 }
395 409
396 static inline bool layerImagesIdentical(const FillLayer& layer1, const FillLayer & layer2) 410 static inline bool layerImagesIdentical(const FillLayer& layer1, const FillLayer & layer2)
397 { 411 {
398 // We just care about pointer equivalency. 412 // We just care about pointer equivalency.
399 return layer1.image() == layer2.image(); 413 return layer1.image() == layer2.image();
400 } 414 }
401 415
402 bool FillLayer::imagesIdentical(const FillLayer* layer1, const FillLayer* layer2 ) 416 bool FillLayer::imagesIdentical(const FillLayer* layer1, const FillLayer* layer2 )
403 { 417 {
404 for (; layer1 && layer2; layer1 = layer1->next(), layer2 = layer2->next()) { 418 for (; layer1 && layer2; layer1 = layer1->next(), layer2 = layer2->next()) {
405 if (!layerImagesIdentical(*layer1, *layer2)) 419 if (!layerImagesIdentical(*layer1, *layer2))
406 return false; 420 return false;
407 } 421 }
408 422
409 return !layer1 && !layer2; 423 return !layer1 && !layer2;
410 } 424 }
411 425
412 } // namespace blink 426 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698