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

Side by Side Diff: Source/core/fetch/ImageResource.cpp

Issue 1102803002: Remove the pending container size requests list (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove now redundant virtual method Created 5 years, 8 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) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 if (m_image && !m_image->isNull()) 103 if (m_image && !m_image->isNull())
104 static_cast<ImageResourceClient*>(c)->imageChanged(this); 104 static_cast<ImageResourceClient*>(c)->imageChanged(this);
105 105
106 Resource::didAddClient(c); 106 Resource::didAddClient(c);
107 } 107 }
108 108
109 void ImageResource::didRemoveClient(ResourceClient* c) 109 void ImageResource::didRemoveClient(ResourceClient* c)
110 { 110 {
111 ASSERT(c); 111 ASSERT(c);
112 ASSERT(c->resourceClientType() == ImageResourceClient::expectedType()); 112 ASSERT(c->resourceClientType() == ImageResourceClient::expectedType());
113 m_pendingContainerSizeRequests.remove(static_cast<ImageResourceClient*>(c));
114 if (m_imageForContainerMap) 113 if (m_imageForContainerMap)
115 m_imageForContainerMap->remove(static_cast<ImageResourceClient*>(c)); 114 m_imageForContainerMap->remove(static_cast<ImageResourceClient*>(c));
116 115
117 Resource::didRemoveClient(c); 116 Resource::didRemoveClient(c);
118 } 117 }
119 118
120 void ImageResource::switchClientsToRevalidatedResource()
121 {
122 ASSERT(resourceToRevalidate());
123 ASSERT(resourceToRevalidate()->isImage());
124 // Pending container size requests need to be transferred to the revalidated resource.
125 if (!m_pendingContainerSizeRequests.isEmpty()) {
126 // A copy of pending size requests is needed as they are deleted during Resource::switchClientsToRevalidateResource().
127 ContainerSizeRequests switchContainerSizeRequests;
128 for (const auto& containerSizeRequest : m_pendingContainerSizeRequests)
129 switchContainerSizeRequests.set(containerSizeRequest.key, containerS izeRequest.value);
130 Resource::switchClientsToRevalidatedResource();
131 ImageResource* revalidatedImageResource = toImageResource(resourceToReva lidate());
132 for (const auto& containerSizeRequest : switchContainerSizeRequests)
133 revalidatedImageResource->setContainerSizeForLayoutObject(containerS izeRequest.key, containerSizeRequest.value.first, containerSizeRequest.value.sec ond);
134 return;
135 }
136
137 Resource::switchClientsToRevalidatedResource();
138 }
139
140 bool ImageResource::isSafeToUnlock() const 119 bool ImageResource::isSafeToUnlock() const
141 { 120 {
142 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. 121 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class.
143 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); 122 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2);
144 } 123 }
145 124
146 void ImageResource::destroyDecodedDataIfPossible() 125 void ImageResource::destroyDecodedDataIfPossible()
147 { 126 {
148 if (!hasClients() && !isLoading() && (!m_image || (m_image->hasOneRef() && m _image->isBitmapImage()))) { 127 if (!hasClients() && !isLoading() && (!m_image || (m_image->hasOneRef() && m _image->isBitmapImage()))) {
149 m_image = nullptr; 128 m_image = nullptr;
150 setDecodedSize(0); 129 setDecodedSize(0);
151 } else if (m_image && !errorOccurred()) { 130 } else if (m_image && !errorOccurred()) {
152 m_image->destroyDecodedData(true); 131 m_image->destroyDecodedData(true);
153 } 132 }
154 } 133 }
155 134
156 void ImageResource::allClientsRemoved() 135 void ImageResource::allClientsRemoved()
157 { 136 {
158 m_pendingContainerSizeRequests.clear();
159 if (m_image && !errorOccurred()) 137 if (m_image && !errorOccurred())
160 m_image->resetAnimation(); 138 m_image->resetAnimation();
161 Resource::allClientsRemoved(); 139 Resource::allClientsRemoved();
162 } 140 }
163 141
164 pair<blink::Image*, float> ImageResource::brokenImage(float deviceScaleFactor) 142 pair<blink::Image*, float> ImageResource::brokenImage(float deviceScaleFactor)
165 { 143 {
166 if (deviceScaleFactor >= 2) { 144 if (deviceScaleFactor >= 2) {
167 DEFINE_STATIC_REF(blink::Image, brokenImageHiRes, (blink::Image::loadPla tformResource("missingImage@2x"))); 145 DEFINE_STATIC_REF(blink::Image, brokenImageHiRes, (blink::Image::loadPla tformResource("missingImage@2x")));
168 return std::make_pair(brokenImageHiRes, 2); 146 return std::make_pair(brokenImageHiRes, 2);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 194
217 return m_image.get(); 195 return m_image.get();
218 } 196 }
219 197
220 void ImageResource::setContainerSizeForLayoutObject(const ImageResourceClient* l ayoutObject, const IntSize& containerSize, float containerZoom) 198 void ImageResource::setContainerSizeForLayoutObject(const ImageResourceClient* l ayoutObject, const IntSize& containerSize, float containerZoom)
221 { 199 {
222 if (containerSize.isEmpty()) 200 if (containerSize.isEmpty())
223 return; 201 return;
224 ASSERT(layoutObject); 202 ASSERT(layoutObject);
225 ASSERT(containerZoom); 203 ASSERT(containerZoom);
226 if (!m_image) { 204 if (!m_image)
227 m_pendingContainerSizeRequests.set(layoutObject, SizeAndZoom(containerSi ze, containerZoom));
228 return; 205 return;
229 }
230 if (!m_image->isSVGImage()) { 206 if (!m_image->isSVGImage()) {
231 m_image->setContainerSize(containerSize); 207 m_image->setContainerSize(containerSize);
232 return; 208 return;
233 } 209 }
234 210
235 FloatSize containerSizeWithoutZoom(containerSize); 211 FloatSize containerSizeWithoutZoom(containerSize);
236 containerSizeWithoutZoom.scale(1 / containerZoom); 212 containerSizeWithoutZoom.scale(1 / containerZoom);
237 m_imageForContainerMap->set(layoutObject, SVGImageForContainer::create(toSVG Image(m_image.get()), containerSizeWithoutZoom, containerZoom)); 213 m_imageForContainerMap->set(layoutObject, SVGImageForContainer::create(toSVG Image(m_image.get()), containerSizeWithoutZoom, containerZoom));
238 } 214 }
239 215
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 { 276 {
301 ResourceClientWalker<ImageResourceClient> w(m_clients); 277 ResourceClientWalker<ImageResourceClient> w(m_clients);
302 while (ImageResourceClient* c = w.next()) 278 while (ImageResourceClient* c = w.next())
303 c->imageChanged(this, changeRect); 279 c->imageChanged(this, changeRect);
304 } 280 }
305 281
306 void ImageResource::clear() 282 void ImageResource::clear()
307 { 283 {
308 prune(); 284 prune();
309 clearImage(); 285 clearImage();
310 m_pendingContainerSizeRequests.clear();
311 setEncodedSize(0); 286 setEncodedSize(0);
312 } 287 }
313 288
314 void ImageResource::setCustomAcceptHeader() 289 void ImageResource::setCustomAcceptHeader()
315 { 290 {
316 DEFINE_STATIC_LOCAL(const AtomicString, acceptWebP, ("image/webp,*/*;q=0.8", AtomicString::ConstructFromLiteral)); 291 DEFINE_STATIC_LOCAL(const AtomicString, acceptWebP, ("image/webp,*/*;q=0.8", AtomicString::ConstructFromLiteral));
317 setAccept(acceptWebP); 292 setAccept(acceptWebP);
318 } 293 }
319 294
320 inline void ImageResource::createImage() 295 inline void ImageResource::createImage()
321 { 296 {
322 // Create the image if it doesn't yet exist. 297 // Create the image if it doesn't yet exist.
323 if (m_image) 298 if (m_image)
324 return; 299 return;
325 300
326 if (m_response.mimeType() == "image/svg+xml") { 301 if (m_response.mimeType() == "image/svg+xml") {
327 m_image = SVGImage::create(this); 302 m_image = SVGImage::create(this);
328 m_imageForContainerMap = adoptPtr(new ImageForContainerMap); 303 m_imageForContainerMap = adoptPtr(new ImageForContainerMap);
329 } else { 304 } else {
330 m_image = BitmapImage::create(this); 305 m_image = BitmapImage::create(this);
331 } 306 }
332
333 if (m_image) {
334 // Send queued container size requests.
335 if (m_image->usesContainerSize()) {
336 for (const auto& containerSizeRequest : m_pendingContainerSizeReques ts)
337 setContainerSizeForLayoutObject(containerSizeRequest.key, contai nerSizeRequest.value.first, containerSizeRequest.value.second);
338 }
339 m_pendingContainerSizeRequests.clear();
340 }
341 } 307 }
342 308
343 inline void ImageResource::clearImage() 309 inline void ImageResource::clearImage()
344 { 310 {
345 // If our Image has an observer, it's always us so we need to clear the back pointer 311 // If our Image has an observer, it's always us so we need to clear the back pointer
346 // before dropping our reference. 312 // before dropping our reference.
347 if (m_image) 313 if (m_image)
348 m_image->setImageObserver(nullptr); 314 m_image->setImageObserver(nullptr);
349 m_image.clear(); 315 m_image.clear();
350 } 316 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if (node && isHTMLImageElement(node)) { 510 if (node && isHTMLImageElement(node)) {
545 const AtomicString& urlString = toHTMLImageElement(node)->imageSourceURL (); 511 const AtomicString& urlString = toHTMLImageElement(node)->imageSourceURL ();
546 KURL url = node->document().completeURL(urlString); 512 KURL url = node->document().completeURL(urlString);
547 imageForContainer->setURL(url); 513 imageForContainer->setURL(url);
548 } 514 }
549 515
550 return imageForContainer.get(); 516 return imageForContainer.get();
551 } 517 }
552 518
553 } // namespace blink 519 } // namespace blink
OLDNEW
« Source/core/fetch/ImageResource.h ('K') | « Source/core/fetch/ImageResource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698