| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "core/css/CSSCrossfadeValue.h" | 27 #include "core/css/CSSCrossfadeValue.h" |
| 28 | 28 |
| 29 #include "core/css/CSSImageValue.h" | 29 #include "core/css/CSSImageValue.h" |
| 30 #include "core/layout/LayoutObject.h" | 30 #include "core/layout/LayoutObject.h" |
| 31 #include "core/style/StyleFetchedImage.h" | 31 #include "core/style/StyleFetchedImage.h" |
| 32 #include "platform/graphics/CrossfadeGeneratedImage.h" | 32 #include "platform/graphics/CrossfadeGeneratedImage.h" |
| 33 #include "wtf/text/StringBuilder.h" | 33 #include "wtf/text/StringBuilder.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 static bool subimageIsPending(CSSValue* value) | 37 static bool subimageIsPending(CSSStyleImageMap& imageMap, CSSValue* value) |
| 38 { | 38 { |
| 39 if (value->isImageValue()) | 39 if (value->isImageValue()) |
| 40 return toCSSImageValue(value)->cachedOrPendingImage()->isPendingImage(); | 40 return toCSSImageValue(value)->cachedOrPendingImage(imageMap)->isPending
Image(); |
| 41 | 41 |
| 42 if (value->isImageGeneratorValue()) | 42 if (value->isImageGeneratorValue()) |
| 43 return toCSSImageGeneratorValue(value)->isPending(); | 43 return toCSSImageGeneratorValue(value)->isPending(imageMap); |
| 44 | 44 |
| 45 ASSERT_NOT_REACHED(); | 45 ASSERT_NOT_REACHED(); |
| 46 | 46 |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 static bool subimageKnownToBeOpaque(CSSValue* value, const LayoutObject* layoutO
bject) | 50 static bool subimageKnownToBeOpaque(CSSValue* value, const LayoutObject* layoutO
bject) |
| 51 { | 51 { |
| 52 if (value->isImageValue()) | 52 if (value->isImageValue()) |
| 53 return toCSSImageValue(value)->knownToBeOpaque(layoutObject); | 53 return toCSSImageValue(value)->knownToBeOpaque(layoutObject); |
| 54 | 54 |
| 55 if (value->isImageGeneratorValue()) | 55 if (value->isImageGeneratorValue()) |
| 56 return toCSSImageGeneratorValue(value)->knownToBeOpaque(layoutObject); | 56 return toCSSImageGeneratorValue(value)->knownToBeOpaque(layoutObject); |
| 57 | 57 |
| 58 ASSERT_NOT_REACHED(); | 58 ASSERT_NOT_REACHED(); |
| 59 | 59 |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 | 62 |
| 63 static ImageResource* cachedImageForCSSValue(CSSValue* value, Document* document
) | 63 static ImageResource* cachedImageForCSSValue(CSSValue* value, Document* document
, CSSStyleImageMap& imageMap) |
| 64 { | 64 { |
| 65 if (!value) | 65 if (!value) |
| 66 return 0; | 66 return 0; |
| 67 | 67 |
| 68 if (value->isImageValue()) { | 68 if (value->isImageValue()) { |
| 69 StyleFetchedImage* styleImageResource = toCSSImageValue(value)->cachedIm
age(document); | 69 StyleFetchedImage* styleImageResource = toCSSImageValue(value)->cachedIm
age(document, imageMap); |
| 70 if (!styleImageResource) | 70 if (!styleImageResource) |
| 71 return 0; | 71 return 0; |
| 72 | 72 |
| 73 return styleImageResource->cachedImage(); | 73 return styleImageResource->cachedImage(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 if (value->isImageGeneratorValue()) { | 76 if (value->isImageGeneratorValue()) { |
| 77 toCSSImageGeneratorValue(value)->loadSubimages(document); | 77 toCSSImageGeneratorValue(value)->loadSubimages(document, imageMap); |
| 78 // FIXME: Handle CSSImageGeneratorValue (and thus cross-fades with gradi
ents and canvas). | 78 // FIXME: Handle CSSImageGeneratorValue (and thus cross-fades with gradi
ents and canvas). |
| 79 return 0; | 79 return 0; |
| 80 } | 80 } |
| 81 | 81 |
| 82 ASSERT_NOT_REACHED(); | 82 ASSERT_NOT_REACHED(); |
| 83 | 83 |
| 84 return 0; | 84 return 0; |
| 85 } | 85 } |
| 86 | 86 |
| 87 CSSCrossfadeValue::~CSSCrossfadeValue() | 87 CSSCrossfadeValue::~CSSCrossfadeValue() |
| (...skipping 16 matching lines...) Expand all Loading... |
| 104 result.append(')'); | 104 result.append(')'); |
| 105 return result.toString(); | 105 return result.toString(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 IntSize CSSCrossfadeValue::fixedSize(const LayoutObject* layoutObject) | 108 IntSize CSSCrossfadeValue::fixedSize(const LayoutObject* layoutObject) |
| 109 { | 109 { |
| 110 float percentage = m_percentageValue->getFloatValue(); | 110 float percentage = m_percentageValue->getFloatValue(); |
| 111 float inversePercentage = 1 - percentage; | 111 float inversePercentage = 1 - percentage; |
| 112 | 112 |
| 113 Document* document = &layoutObject->document(); | 113 Document* document = &layoutObject->document(); |
| 114 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument); | 114 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument, layoutObject->mutableStyle()->mutableCssImages()); |
| 115 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent); | 115 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent, layoutObject->mutableStyle()->mutableCssImages()); |
| 116 | 116 |
| 117 if (!cachedFromImage || !cachedToImage) | 117 if (!cachedFromImage || !cachedToImage) |
| 118 return IntSize(); | 118 return IntSize(); |
| 119 | 119 |
| 120 IntSize fromImageSize = cachedFromImage->imageForLayoutObject(layoutObject)-
>size(); | 120 IntSize fromImageSize = cachedFromImage->imageForLayoutObject(layoutObject)-
>size(); |
| 121 IntSize toImageSize = cachedToImage->imageForLayoutObject(layoutObject)->siz
e(); | 121 IntSize toImageSize = cachedToImage->imageForLayoutObject(layoutObject)->siz
e(); |
| 122 | 122 |
| 123 // Rounding issues can cause transitions between images of equal size to ret
urn | 123 // Rounding issues can cause transitions between images of equal size to ret
urn |
| 124 // a different fixed size; avoid performing the interpolation if the images
are the same size. | 124 // a different fixed size; avoid performing the interpolation if the images
are the same size. |
| 125 if (fromImageSize == toImageSize) | 125 if (fromImageSize == toImageSize) |
| 126 return fromImageSize; | 126 return fromImageSize; |
| 127 | 127 |
| 128 return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width
() * percentage, | 128 return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width
() * percentage, |
| 129 fromImageSize.height() * inversePercentage + toImageSize.height() * perc
entage); | 129 fromImageSize.height() * inversePercentage + toImageSize.height() * perc
entage); |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool CSSCrossfadeValue::isPending() const | 132 bool CSSCrossfadeValue::isPending(CSSStyleImageMap& imageMap) const |
| 133 { | 133 { |
| 134 return subimageIsPending(m_fromValue.get()) || subimageIsPending(m_toValue.g
et()); | 134 return subimageIsPending(imageMap, m_fromValue.get()) || subimageIsPending(i
mageMap, m_toValue.get()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool CSSCrossfadeValue::knownToBeOpaque(const LayoutObject* layoutObject) const | 137 bool CSSCrossfadeValue::knownToBeOpaque(const LayoutObject* layoutObject) const |
| 138 { | 138 { |
| 139 return subimageKnownToBeOpaque(m_fromValue.get(), layoutObject) && subimageK
nownToBeOpaque(m_toValue.get(), layoutObject); | 139 return subimageKnownToBeOpaque(m_fromValue.get(), layoutObject) && subimageK
nownToBeOpaque(m_toValue.get(), layoutObject); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void CSSCrossfadeValue::loadSubimages(Document* document) | 142 void CSSCrossfadeValue::loadSubimages(Document* document, CSSStyleImageMap& imag
eMap) |
| 143 { | 143 { |
| 144 ResourcePtr<ImageResource> oldCachedFromImage = m_cachedFromImage; | 144 ResourcePtr<ImageResource>& oldCachedFromImage = imageMap.getImageResourceEn
try(this).storedValue->value; |
| 145 ResourcePtr<ImageResource> oldCachedToImage = m_cachedToImage; | 145 ResourcePtr<ImageResource>& oldCachedToImage = imageMap.getImageResourceEntr
y(reinterpret_cast<CSSCrossfadeValue*>(reinterpret_cast<uintptr_t>(this) & 1)).s
toredValue->value; |
| 146 | 146 |
| 147 m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), document); | 147 ResourcePtr<ImageResource> cachedFromImage = cachedImageForCSSValue(m_fromVa
lue.get(), document, imageMap); |
| 148 m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), document); | 148 ResourcePtr<ImageResource> cachedToImage = cachedImageForCSSValue(m_toValue.
get(), document, imageMap); |
| 149 | 149 |
| 150 if (m_cachedFromImage != oldCachedFromImage) { | 150 if (cachedFromImage != oldCachedFromImage) { |
| 151 if (oldCachedFromImage) | 151 if (oldCachedFromImage) |
| 152 oldCachedFromImage->removeClient(&m_crossfadeSubimageObserver); | 152 oldCachedFromImage->removeClient(&m_crossfadeSubimageObserver); |
| 153 if (m_cachedFromImage) | 153 if (cachedFromImage) |
| 154 m_cachedFromImage->addClient(&m_crossfadeSubimageObserver); | 154 cachedFromImage->addClient(&m_crossfadeSubimageObserver); |
| 155 } | 155 } |
| 156 | 156 |
| 157 if (m_cachedToImage != oldCachedToImage) { | 157 if (cachedToImage != oldCachedToImage) { |
| 158 if (oldCachedToImage) | 158 if (oldCachedToImage) |
| 159 oldCachedToImage->removeClient(&m_crossfadeSubimageObserver); | 159 oldCachedToImage->removeClient(&m_crossfadeSubimageObserver); |
| 160 if (m_cachedToImage) | 160 if (cachedToImage) |
| 161 m_cachedToImage->addClient(&m_crossfadeSubimageObserver); | 161 cachedToImage->addClient(&m_crossfadeSubimageObserver); |
| 162 } | 162 } |
| 163 | 163 |
| 164 oldCachedFromImage = cachedFromImage; |
| 165 oldCachedToImage = cachedToImage; |
| 166 |
| 164 m_crossfadeSubimageObserver.setReady(true); | 167 m_crossfadeSubimageObserver.setReady(true); |
| 165 } | 168 } |
| 166 | 169 |
| 167 PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* layoutObject, const Int
Size& size) | 170 PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* layoutObject, const Int
Size& size) |
| 168 { | 171 { |
| 169 if (size.isEmpty()) | 172 if (size.isEmpty()) |
| 170 return nullptr; | 173 return nullptr; |
| 171 | 174 |
| 172 Document* document = &layoutObject->document(); | 175 Document* document = &layoutObject->document(); |
| 173 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument); | 176 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument, layoutObject->mutableStyle()->mutableCssImages()); |
| 174 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent); | 177 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent, layoutObject->mutableStyle()->mutableCssImages()); |
| 175 | 178 |
| 176 if (!cachedFromImage || !cachedToImage) | 179 if (!cachedFromImage || !cachedToImage) |
| 177 return Image::nullImage(); | 180 return Image::nullImage(); |
| 178 | 181 |
| 179 Image* fromImage = cachedFromImage->imageForLayoutObject(layoutObject); | 182 Image* fromImage = cachedFromImage->imageForLayoutObject(layoutObject); |
| 180 Image* toImage = cachedToImage->imageForLayoutObject(layoutObject); | 183 Image* toImage = cachedToImage->imageForLayoutObject(layoutObject); |
| 181 | 184 |
| 182 if (!fromImage || !toImage) | 185 if (!fromImage || !toImage) |
| 183 return Image::nullImage(); | 186 return Image::nullImage(); |
| 184 | 187 |
| 185 m_generatedImage = CrossfadeGeneratedImage::create(fromImage, toImage, m_per
centageValue->getFloatValue(), fixedSize(layoutObject), size); | 188 RefPtr<Image>& generatedImage = layoutObject->mutableStyle()->mutableCssImag
es().getImageEntry(this).storedValue->value; |
| 189 generatedImage = CrossfadeGeneratedImage::create(fromImage, toImage, m_perce
ntageValue->getFloatValue(), fixedSize(layoutObject), size); |
| 186 | 190 |
| 187 return m_generatedImage.release(); | 191 return generatedImage.release(); |
| 188 } | 192 } |
| 189 | 193 |
| 190 void CSSCrossfadeValue::crossfadeChanged(const IntRect&) | 194 void CSSCrossfadeValue::crossfadeChanged(const IntRect&) |
| 191 { | 195 { |
| 192 for (const auto& curr : clients()) { | 196 for (const auto& curr : clients()) { |
| 193 LayoutObject* client = const_cast<LayoutObject*>(curr.key); | 197 LayoutObject* client = const_cast<LayoutObject*>(curr.key); |
| 194 client->imageChanged(static_cast<WrappedImagePtr>(this)); | 198 client->imageChanged(static_cast<WrappedImagePtr>(this)); |
| 195 } | 199 } |
| 196 } | 200 } |
| 197 | 201 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 220 DEFINE_TRACE_AFTER_DISPATCH(CSSCrossfadeValue) | 224 DEFINE_TRACE_AFTER_DISPATCH(CSSCrossfadeValue) |
| 221 { | 225 { |
| 222 visitor->trace(m_fromValue); | 226 visitor->trace(m_fromValue); |
| 223 visitor->trace(m_toValue); | 227 visitor->trace(m_toValue); |
| 224 visitor->trace(m_percentageValue); | 228 visitor->trace(m_percentageValue); |
| 225 visitor->trace(m_crossfadeSubimageObserver); | 229 visitor->trace(m_crossfadeSubimageObserver); |
| 226 CSSImageGeneratorValue::traceAfterDispatch(visitor); | 230 CSSImageGeneratorValue::traceAfterDispatch(visitor); |
| 227 } | 231 } |
| 228 | 232 |
| 229 } // namespace blink | 233 } // namespace blink |
| OLD | NEW |