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

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

Issue 1339183003: NOT FOR LANDING Experiment with allocating SVGImageForContainer on demand (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 3 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/fetch/ImageResource.h ('k') | Source/core/layout/LayoutImage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 15 matching lines...) Expand all
26 26
27 #include "core/fetch/ImageResourceClient.h" 27 #include "core/fetch/ImageResourceClient.h"
28 #include "core/fetch/MemoryCache.h" 28 #include "core/fetch/MemoryCache.h"
29 #include "core/fetch/ResourceClient.h" 29 #include "core/fetch/ResourceClient.h"
30 #include "core/fetch/ResourceClientWalker.h" 30 #include "core/fetch/ResourceClientWalker.h"
31 #include "core/fetch/ResourceFetcher.h" 31 #include "core/fetch/ResourceFetcher.h"
32 #include "core/fetch/ResourceLoader.h" 32 #include "core/fetch/ResourceLoader.h"
33 #include "core/html/HTMLImageElement.h" 33 #include "core/html/HTMLImageElement.h"
34 #include "core/layout/LayoutObject.h" 34 #include "core/layout/LayoutObject.h"
35 #include "core/svg/graphics/SVGImage.h" 35 #include "core/svg/graphics/SVGImage.h"
36 #include "core/svg/graphics/SVGImageForContainer.h"
37 #include "platform/Logging.h" 36 #include "platform/Logging.h"
38 #include "platform/RuntimeEnabledFeatures.h" 37 #include "platform/RuntimeEnabledFeatures.h"
39 #include "platform/SharedBuffer.h" 38 #include "platform/SharedBuffer.h"
40 #include "platform/TraceEvent.h" 39 #include "platform/TraceEvent.h"
41 #include "platform/graphics/BitmapImage.h" 40 #include "platform/graphics/BitmapImage.h"
42 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
43 #include "wtf/CurrentTime.h" 42 #include "wtf/CurrentTime.h"
44 #include "wtf/StdLibExtras.h" 43 #include "wtf/StdLibExtras.h"
45 44
46 namespace blink { 45 namespace blink {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (m_image && !m_image->isNull()) 119 if (m_image && !m_image->isNull())
121 static_cast<ImageResourceClient*>(c)->imageChanged(this); 120 static_cast<ImageResourceClient*>(c)->imageChanged(this);
122 121
123 Resource::didAddClient(c); 122 Resource::didAddClient(c);
124 } 123 }
125 124
126 void ImageResource::didRemoveClient(ResourceClient* c) 125 void ImageResource::didRemoveClient(ResourceClient* c)
127 { 126 {
128 ASSERT(c); 127 ASSERT(c);
129 ASSERT(c->resourceClientType() == ImageResourceClient::expectedType()); 128 ASSERT(c->resourceClientType() == ImageResourceClient::expectedType());
130 if (m_imageForContainerMap)
131 m_imageForContainerMap->remove(static_cast<ImageResourceClient*>(c));
132 129
133 Resource::didRemoveClient(c); 130 Resource::didRemoveClient(c);
134 } 131 }
135 132
136 bool ImageResource::isSafeToUnlock() const 133 bool ImageResource::isSafeToUnlock() const
137 { 134 {
138 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. 135 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class.
139 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); 136 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2);
140 } 137 }
141 138
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (errorOccurred()) { 193 if (errorOccurred()) {
197 // Returning the 1x broken image is non-ideal, but we cannot reliably ac cess the appropriate 194 // Returning the 1x broken image is non-ideal, but we cannot reliably ac cess the appropriate
198 // deviceScaleFactor from here. It is critical that callers use ImageRes ource::brokenImage() 195 // deviceScaleFactor from here. It is critical that callers use ImageRes ource::brokenImage()
199 // when they need the real, deviceScaleFactor-appropriate broken image i con. 196 // when they need the real, deviceScaleFactor-appropriate broken image i con.
200 return brokenImage(1).first; 197 return brokenImage(1).first;
201 } 198 }
202 199
203 if (!m_image) 200 if (!m_image)
204 return blink::Image::nullImage(); 201 return blink::Image::nullImage();
205 202
206 if (m_image->isSVGImage()) {
207 blink::Image* image = svgImageForLayoutObject(layoutObject);
208 if (image != blink::Image::nullImage())
209 return image;
210 }
211
212 return m_image.get(); 203 return m_image.get();
213 } 204 }
214 205
215 void ImageResource::setContainerSizeForLayoutObject(const ImageResourceClient* l ayoutObject, const IntSize& containerSize, float containerZoom)
216 {
217 if (containerSize.isEmpty())
218 return;
219 ASSERT(layoutObject);
220 ASSERT(containerZoom);
221 if (!m_image)
222 return;
223 if (!m_image->isSVGImage()) {
224 m_image->setContainerSize(containerSize);
225 return;
226 }
227
228 FloatSize containerSizeWithoutZoom(containerSize);
229 containerSizeWithoutZoom.scale(1 / containerZoom);
230 m_imageForContainerMap->set(layoutObject, SVGImageForContainer::create(toSVG Image(m_image.get()), containerSizeWithoutZoom, containerZoom));
231 }
232
233 bool ImageResource::usesImageContainerSize() const 206 bool ImageResource::usesImageContainerSize() const
234 { 207 {
235 if (m_image) 208 if (m_image)
236 return m_image->usesContainerSize(); 209 return m_image->usesContainerSize();
237 210
238 return false; 211 return false;
239 } 212 }
240 213
241 bool ImageResource::imageHasRelativeWidth() const 214 bool ImageResource::imageHasRelativeWidth() const
242 { 215 {
(...skipping 15 matching lines...) Expand all
258 { 231 {
259 ASSERT(!isPurgeable()); 232 ASSERT(!isPurgeable());
260 233
261 if (!m_image) 234 if (!m_image)
262 return LayoutSize(); 235 return LayoutSize();
263 236
264 LayoutSize imageSize; 237 LayoutSize imageSize;
265 238
266 if (m_image->isBitmapImage() && (layoutObject && layoutObject->shouldRespect ImageOrientation() == RespectImageOrientation)) 239 if (m_image->isBitmapImage() && (layoutObject && layoutObject->shouldRespect ImageOrientation() == RespectImageOrientation))
267 imageSize = LayoutSize(toBitmapImage(m_image.get())->sizeRespectingOrien tation()); 240 imageSize = LayoutSize(toBitmapImage(m_image.get())->sizeRespectingOrien tation());
268 else if (m_image->isSVGImage() && sizeType == NormalSize)
269 imageSize = LayoutSize(svgImageSizeForLayoutObject(layoutObject));
270 else 241 else
271 imageSize = LayoutSize(m_image->size()); 242 imageSize = LayoutSize(m_image->size());
272 243
273 if (sizeType == IntrinsicCorrectedToDPR && m_hasDevicePixelRatioHeaderValue && m_devicePixelRatioHeaderValue > 0) 244 if (sizeType == IntrinsicCorrectedToDPR && m_hasDevicePixelRatioHeaderValue && m_devicePixelRatioHeaderValue > 0)
274 multiplier = 1.0 / m_devicePixelRatioHeaderValue; 245 multiplier = 1.0 / m_devicePixelRatioHeaderValue;
275 246
276 if (multiplier == 1.0f) 247 if (multiplier == 1.0f)
277 return imageSize; 248 return imageSize;
278 249
279 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed . 250 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed .
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 284 }
314 285
315 inline void ImageResource::createImage() 286 inline void ImageResource::createImage()
316 { 287 {
317 // Create the image if it doesn't yet exist. 288 // Create the image if it doesn't yet exist.
318 if (m_image) 289 if (m_image)
319 return; 290 return;
320 291
321 if (m_response.mimeType() == "image/svg+xml") { 292 if (m_response.mimeType() == "image/svg+xml") {
322 m_image = SVGImage::create(this); 293 m_image = SVGImage::create(this);
323 m_imageForContainerMap = adoptPtr(new ImageForContainerMap);
324 } else { 294 } else {
325 m_image = BitmapImage::create(this); 295 m_image = BitmapImage::create(this);
326 } 296 }
327 } 297 }
328 298
329 inline void ImageResource::clearImage() 299 inline void ImageResource::clearImage()
330 { 300 {
331 // If our Image has an observer, it's always us so we need to clear the back pointer 301 // If our Image has an observer, it's always us so we need to clear the back pointer
332 // before dropping our reference. 302 // before dropping our reference.
333 if (m_image) 303 if (m_image)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 { 459 {
490 if (response().wasFetchedViaServiceWorker()) 460 if (response().wasFetchedViaServiceWorker())
491 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; 461 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque;
492 if (!image()->currentFrameHasSingleSecurityOrigin()) 462 if (!image()->currentFrameHasSingleSecurityOrigin())
493 return false; 463 return false;
494 if (passesAccessControlCheck(securityOrigin)) 464 if (passesAccessControlCheck(securityOrigin))
495 return true; 465 return true;
496 return !securityOrigin->taintsCanvas(response().url()); 466 return !securityOrigin->taintsCanvas(response().url());
497 } 467 }
498 468
499 IntSize ImageResource::svgImageSizeForLayoutObject(const LayoutObject* layoutObj ect) const
500 {
501 IntSize imageSize = m_image->size();
502 if (!layoutObject)
503 return imageSize;
504
505 ImageForContainerMap::const_iterator it = m_imageForContainerMap->find(layou tObject);
506 if (it == m_imageForContainerMap->end())
507 return imageSize;
508
509 RefPtr<SVGImageForContainer> imageForContainer = it->value;
510 ASSERT(!imageForContainer->size().isEmpty());
511 return imageForContainer->size();
512 }
513
514 // FIXME: This doesn't take into account the animation timeline so animations wi ll not
515 // restart on page load, nor will two animations in different pages have differe nt timelines.
516 Image* ImageResource::svgImageForLayoutObject(const LayoutObject* layoutObject)
517 {
518 if (!layoutObject)
519 return Image::nullImage();
520
521 ImageForContainerMap::iterator it = m_imageForContainerMap->find(layoutObjec t);
522 if (it == m_imageForContainerMap->end())
523 return Image::nullImage();
524
525 RefPtr<SVGImageForContainer> imageForContainer = it->value;
526 ASSERT(!imageForContainer->size().isEmpty());
527
528 Node* node = layoutObject->node();
529 if (node && isHTMLImageElement(node)) {
530 const AtomicString& urlString = toHTMLImageElement(node)->imageSourceURL ();
531 KURL url = node->document().completeURL(urlString);
532 imageForContainer->setURL(url);
533 }
534
535 return imageForContainer.get();
536 }
537
538 bool ImageResource::loadingMultipartContent() const 469 bool ImageResource::loadingMultipartContent() const
539 { 470 {
540 return m_loader && m_loader->loadingMultipartContent(); 471 return m_loader && m_loader->loadingMultipartContent();
541 } 472 }
542 473
543 } // namespace blink 474 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/fetch/ImageResource.h ('k') | Source/core/layout/LayoutImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698