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

Side by Side Diff: Source/core/loader/ImageLoader.cpp

Issue 19393004: Allow eviction of ImageBitmaps that are created from ImageElements. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Name change. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/ImageLoader.h ('k') | Source/core/loader/cache/CachedImageTest.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 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv ed. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv ed.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ImageLoader::ImageLoader(Element* element) 68 ImageLoader::ImageLoader(Element* element)
69 : m_element(element) 69 : m_element(element)
70 , m_image(0) 70 , m_image(0)
71 , m_derefElementTimer(this, &ImageLoader::timerFired) 71 , m_derefElementTimer(this, &ImageLoader::timerFired)
72 , m_hasPendingBeforeLoadEvent(false) 72 , m_hasPendingBeforeLoadEvent(false)
73 , m_hasPendingLoadEvent(false) 73 , m_hasPendingLoadEvent(false)
74 , m_hasPendingErrorEvent(false) 74 , m_hasPendingErrorEvent(false)
75 , m_imageComplete(true) 75 , m_imageComplete(true)
76 , m_loadManually(false) 76 , m_loadManually(false)
77 , m_elementIsProtected(false) 77 , m_elementIsProtected(false)
78 , m_highPriorityClientCount(0)
78 { 79 {
79 } 80 }
80 81
81 ImageLoader::~ImageLoader() 82 ImageLoader::~ImageLoader()
82 { 83 {
83 if (m_image) 84 if (m_image)
84 m_image->removeClient(this); 85 m_image->removeClient(this);
85 86
86 ASSERT(m_hasPendingBeforeLoadEvent || !beforeLoadEventSender().hasPendingEve nts(this)); 87 ASSERT(m_hasPendingBeforeLoadEvent || !beforeLoadEventSender().hasPendingEve nts(this));
87 if (m_hasPendingBeforeLoadEvent) 88 if (m_hasPendingBeforeLoadEvent)
(...skipping 20 matching lines...) Expand all
108 // Only consider updating the protection ref-count of the Element immediatel y before returning 109 // Only consider updating the protection ref-count of the Element immediatel y before returning
109 // from this function as doing so might result in the destruction of this Im ageLoader. 110 // from this function as doing so might result in the destruction of this Im ageLoader.
110 updatedHasPendingEvent(); 111 updatedHasPendingEvent();
111 } 112 }
112 113
113 void ImageLoader::setImageWithoutConsideringPendingLoadEvent(CachedImage* newIma ge) 114 void ImageLoader::setImageWithoutConsideringPendingLoadEvent(CachedImage* newIma ge)
114 { 115 {
115 ASSERT(m_failedLoadURL.isEmpty()); 116 ASSERT(m_failedLoadURL.isEmpty());
116 CachedImage* oldImage = m_image.get(); 117 CachedImage* oldImage = m_image.get();
117 if (newImage != oldImage) { 118 if (newImage != oldImage) {
119 sourceImageChanged();
118 m_image = newImage; 120 m_image = newImage;
119 if (m_hasPendingBeforeLoadEvent) { 121 if (m_hasPendingBeforeLoadEvent) {
120 beforeLoadEventSender().cancelEvent(this); 122 beforeLoadEventSender().cancelEvent(this);
121 m_hasPendingBeforeLoadEvent = false; 123 m_hasPendingBeforeLoadEvent = false;
122 } 124 }
123 if (m_hasPendingLoadEvent) { 125 if (m_hasPendingLoadEvent) {
124 loadEventSender().cancelEvent(this); 126 loadEventSender().cancelEvent(this);
125 m_hasPendingLoadEvent = false; 127 m_hasPendingLoadEvent = false;
126 } 128 }
127 if (m_hasPendingErrorEvent) { 129 if (m_hasPendingErrorEvent) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 m_failedLoadURL = attr; 185 m_failedLoadURL = attr;
184 m_hasPendingErrorEvent = true; 186 m_hasPendingErrorEvent = true;
185 errorEventSender().dispatchEventSoon(this); 187 errorEventSender().dispatchEventSoon(this);
186 } else 188 } else
187 clearFailedLoadURL(); 189 clearFailedLoadURL();
188 } else if (!attr.isNull()) { 190 } else if (!attr.isNull()) {
189 // Fire an error event if the url is empty. 191 // Fire an error event if the url is empty.
190 m_hasPendingErrorEvent = true; 192 m_hasPendingErrorEvent = true;
191 errorEventSender().dispatchEventSoon(this); 193 errorEventSender().dispatchEventSoon(this);
192 } 194 }
193 195
194 CachedImage* oldImage = m_image.get(); 196 CachedImage* oldImage = m_image.get();
195 if (newImage != oldImage) { 197 if (newImage != oldImage) {
198 sourceImageChanged();
199
196 if (m_hasPendingBeforeLoadEvent) { 200 if (m_hasPendingBeforeLoadEvent) {
197 beforeLoadEventSender().cancelEvent(this); 201 beforeLoadEventSender().cancelEvent(this);
198 m_hasPendingBeforeLoadEvent = false; 202 m_hasPendingBeforeLoadEvent = false;
199 } 203 }
200 if (m_hasPendingLoadEvent) { 204 if (m_hasPendingLoadEvent) {
201 loadEventSender().cancelEvent(this); 205 loadEventSender().cancelEvent(this);
202 m_hasPendingLoadEvent = false; 206 m_hasPendingLoadEvent = false;
203 } 207 }
204 208
205 // Cancel error events that belong to the previous load, which is now ca ncelled by changing the src attribute. 209 // Cancel error events that belong to the previous load, which is now ca ncelled by changing the src attribute.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 return; 420 return;
417 m_hasPendingErrorEvent = false; 421 m_hasPendingErrorEvent = false;
418 if (element()->document()->attached()) 422 if (element()->document()->attached())
419 element()->dispatchEvent(Event::create(eventNames().errorEvent, false, f alse)); 423 element()->dispatchEvent(Event::create(eventNames().errorEvent, false, f alse));
420 424
421 // Only consider updating the protection ref-count of the Element immediatel y before returning 425 // Only consider updating the protection ref-count of the Element immediatel y before returning
422 // from this function as doing so might result in the destruction of this Im ageLoader. 426 // from this function as doing so might result in the destruction of this Im ageLoader.
423 updatedHasPendingEvent(); 427 updatedHasPendingEvent();
424 } 428 }
425 429
430 void ImageLoader::addClient(ImageLoaderClient* client)
431 {
432 if (client->requestsHighLiveResourceCachePriority()) {
433 m_highPriorityClientCount++;
434 if (m_image)
Justin Novosad 2013/07/29 17:47:58 Better to only call setCacheLiveResourcePriority i
435 m_image->setCacheLiveResourcePriority(CachedResource::CacheLiveResou rcePriorityHigh);
436 }
437 m_clients.add(client);
438 }
439 void ImageLoader::removeClient(ImageLoaderClient* client)
440 {
441 if (client->requestsHighLiveResourceCachePriority()) {
442 ASSERT(m_highPriorityClientCount);
443 m_highPriorityClientCount--;
444 if (m_image && !m_highPriorityClientCount)
445 m_image->setCacheLiveResourcePriority(CachedResource::CacheLiveResou rcePriorityLow);
446 }
447 m_clients.remove(client);
448 }
449
426 void ImageLoader::dispatchPendingBeforeLoadEvents() 450 void ImageLoader::dispatchPendingBeforeLoadEvents()
427 { 451 {
428 beforeLoadEventSender().dispatchPendingEvents(); 452 beforeLoadEventSender().dispatchPendingEvents();
429 } 453 }
430 454
431 void ImageLoader::dispatchPendingLoadEvents() 455 void ImageLoader::dispatchPendingLoadEvents()
432 { 456 {
433 loadEventSender().dispatchPendingEvents(); 457 loadEventSender().dispatchPendingEvents();
434 } 458 }
435 459
436 void ImageLoader::dispatchPendingErrorEvents() 460 void ImageLoader::dispatchPendingErrorEvents()
437 { 461 {
438 errorEventSender().dispatchPendingEvents(); 462 errorEventSender().dispatchPendingEvents();
439 } 463 }
440 464
441 void ImageLoader::elementDidMoveToNewDocument() 465 void ImageLoader::elementDidMoveToNewDocument()
442 { 466 {
443 clearFailedLoadURL(); 467 clearFailedLoadURL();
444 setImage(0); 468 setImage(0);
445 } 469 }
446 470
471 void ImageLoader::sourceImageChanged()
472 {
473 HashSet<ImageLoaderClient*>::iterator end = m_clients.end();
474 for (HashSet<ImageLoaderClient*>::iterator it = m_clients.begin(); it != end ; ++it) {
475 ImageLoaderClient* handle = *it;
476 handle->notifyImageSourceChanged();
477 }
478 }
479
447 inline void ImageLoader::clearFailedLoadURL() 480 inline void ImageLoader::clearFailedLoadURL()
448 { 481 {
449 m_failedLoadURL = AtomicString(); 482 m_failedLoadURL = AtomicString();
450 } 483 }
451 484
452 } 485 }
OLDNEW
« no previous file with comments | « Source/core/loader/ImageLoader.h ('k') | Source/core/loader/cache/CachedImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698