Changeset 229316 in webkit
- Timestamp:
- Mar 6, 2018 3:35:22 AM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r229313 r229316 1 2018-03-06 Zan Dobersek <zdobersek@igalia.com> 2 3 [CoordGraphics] Clean up CoordinatedImageBacking 4 https://bugs.webkit.org/show_bug.cgi?id=183332 5 6 Reviewed by Carlos Garcia Campos. 7 8 Clean up the CoordinatedImageBacking class. Prefer reference values in 9 class functions, methods and member variables, where possible. Move 10 member variables into a more sensible order. Initialize a few member 11 variables at the place of declaration. 12 13 Drop releaseSurfaceIfNeeded() and updateVisibilityIfNeeded() methods, 14 integrating them into the update() method, which was the only place 15 where they were called from. 16 17 We don't have to keep a reference to the buffer object, since we're 18 not using it internally after it's been passed to the client's 19 updateImageBacking() implementation. 20 21 No new tests -- no change in behavior. 22 23 * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp: 24 (WebCore::CoordinatedGraphicsLayer::syncImageBacking): 25 (WebCore::CoordinatedGraphicsLayer::releaseImageBackingIfNeeded): 26 * platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp: 27 (WebCore::CoordinatedImageBacking::getCoordinatedImageBackingID): 28 (WebCore::CoordinatedImageBacking::CoordinatedImageBacking): 29 (WebCore::CoordinatedImageBacking::addHost): 30 (WebCore::CoordinatedImageBacking::removeHost): 31 (WebCore::CoordinatedImageBacking::update): 32 (WebCore::CoordinatedImageBacking::clearContentsTimerFired): 33 (WebCore::CoordinatedImageBacking::create): Deleted. 34 (WebCore::CoordinatedImageBacking::markDirty): Deleted. 35 (WebCore::CoordinatedImageBacking::releaseSurfaceIfNeeded): Deleted. 36 (WebCore::CoordinatedImageBacking::updateVisibilityIfNeeded): Deleted. 37 * platform/graphics/texmap/coordinated/CoordinatedImageBacking.h: 38 1 39 2018-03-06 Zan Dobersek <zdobersek@igalia.com> 2 40 -
trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp
r229209 r229316 629 629 ASSERT(m_compositedImage); 630 630 631 bool imageInstanceReplaced = m_coordinatedImageBacking && (m_coordinatedImageBacking->id() != CoordinatedImageBacking::getCoordinatedImageBackingID( m_compositedImage.get()));631 bool imageInstanceReplaced = m_coordinatedImageBacking && (m_coordinatedImageBacking->id() != CoordinatedImageBacking::getCoordinatedImageBackingID(*m_compositedImage)); 632 632 if (imageInstanceReplaced) 633 633 releaseImageBackingIfNeeded(); … … 635 635 if (!m_coordinatedImageBacking) { 636 636 m_coordinatedImageBacking = m_coordinator->createImageBackingIfNeeded(*m_compositedImage); 637 m_coordinatedImageBacking->addHost( this);637 m_coordinatedImageBacking->addHost(*this); 638 638 m_layerState.imageID = m_coordinatedImageBacking->id(); 639 639 } … … 791 791 792 792 ASSERT(m_coordinator); 793 m_coordinatedImageBacking->removeHost( this);793 m_coordinatedImageBacking->removeHost(*this); 794 794 m_coordinatedImageBacking = nullptr; 795 795 m_layerState.imageID = InvalidCoordinatedImageBackingID; -
trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp
r225573 r229316 36 36 namespace WebCore { 37 37 38 CoordinatedImageBackingID CoordinatedImageBacking::getCoordinatedImageBackingID(Image *image)38 CoordinatedImageBackingID CoordinatedImageBacking::getCoordinatedImageBackingID(Image& image) 39 39 { 40 40 // CoordinatedImageBacking keeps a RefPtr<Image> member, so the same Image pointer can not refer two different instances until CoordinatedImageBacking releases the member. 41 return reinterpret_cast<CoordinatedImageBackingID>(image); 42 } 43 44 Ref<CoordinatedImageBacking> CoordinatedImageBacking::create(Client& client, Ref<Image>&& image) 45 { 46 return adoptRef(*new CoordinatedImageBacking(client, WTFMove(image))); 41 return reinterpret_cast<CoordinatedImageBackingID>(&image); 47 42 } 48 43 49 44 CoordinatedImageBacking::CoordinatedImageBacking(Client& client, Ref<Image>&& image) 50 : m_client(&client) 45 : m_client(client) 46 , m_id(getCoordinatedImageBackingID(image)) 51 47 , m_image(WTFMove(image)) 52 , m_id(getCoordinatedImageBackingID(m_image.get()))53 48 , m_clearContentsTimer(*this, &CoordinatedImageBacking::clearContentsTimerFired) 54 , m_isDirty(false)55 , m_isVisible(false)56 49 { 57 // FIXME: We would need to decode a small image directly into a GraphicsSurface. 58 // http://webkit.org/b/101426 59 60 m_client->createImageBacking(id()); 50 m_client.createImageBacking(m_id); 61 51 } 62 52 63 53 CoordinatedImageBacking::~CoordinatedImageBacking() = default; 64 54 65 void CoordinatedImageBacking::addHost(Host *host)55 void CoordinatedImageBacking::addHost(Host& host) 66 56 { 67 ASSERT(!m_hosts.contains( host));68 m_hosts.a ppend(host);57 ASSERT(!m_hosts.contains(&host)); 58 m_hosts.add(&host); 69 59 } 70 60 71 void CoordinatedImageBacking::removeHost(Host *host)61 void CoordinatedImageBacking::removeHost(Host& host) 72 62 { 73 size_t position = m_hosts.find(host); 74 ASSERT(position != notFound); 75 m_hosts.remove(position); 63 m_hosts.remove(&host); 76 64 77 65 if (m_hosts.isEmpty()) 78 m_client ->removeImageBacking(id());66 m_client.removeImageBacking(m_id); 79 67 } 80 68 81 void CoordinatedImageBacking::markDirty() 82 { 83 m_isDirty = true; 84 } 69 static const Seconds clearContentsTimerInterval { 3_s }; 85 70 86 71 void CoordinatedImageBacking::update() 87 72 { 88 releaseSurfaceIfNeeded(); 73 bool previousIsVisible = m_isVisible; 74 m_isVisible = std::any_of(m_hosts.begin(), m_hosts.end(), 75 [](auto* host) 76 { 77 return host->imageBackingVisible(); 78 }); 89 79 90 bool changedToVisible; 91 updateVisibilityIfNeeded(changedToVisible); 92 if (!m_isVisible) 80 if (!m_isVisible) { 81 if (previousIsVisible) { 82 ASSERT(!m_clearContentsTimer.isActive()); 83 m_clearContentsTimer.startOneShot(clearContentsTimerInterval); 84 } 93 85 return; 86 } 94 87 88 bool changedToVisible = !previousIsVisible; 89 if (m_clearContentsTimer.isActive()) { 90 m_clearContentsTimer.stop(); 91 // We don't want to update the texture if we didn't remove the texture. 92 changedToVisible = false; 93 } 94 95 auto nativeImagePtr = m_image->nativeImageForCurrentFrame(); 95 96 if (!changedToVisible) { 96 97 if (!m_isDirty) 97 98 return; 98 99 99 if (m_nativeImagePtr == m_image->nativeImageForCurrentFrame()) {100 if (m_nativeImagePtr == nativeImagePtr) { 100 101 m_isDirty = false; 101 102 return; … … 103 104 } 104 105 105 m_buffer = Nicosia::Buffer::create(IntSize(m_image->size()), !m_image->currentFrameKnownToBeOpaque() ? Nicosia::Buffer::SupportsAlpha : Nicosia::Buffer::NoFlags); 106 ASSERT(m_buffer); 106 m_nativeImagePtr = WTFMove(nativeImagePtr); 107 107 108 Nicosia::PaintingContext::paint(*m_buffer, 108 auto buffer = Nicosia::Buffer::create(IntSize(m_image->size()), !m_image->currentFrameKnownToBeOpaque() ? Nicosia::Buffer::SupportsAlpha : Nicosia::Buffer::NoFlags); 109 Nicosia::PaintingContext::paint(buffer, 109 110 [this](GraphicsContext& context) 110 111 { … … 112 113 context.save(); 113 114 context.clip(rect); 114 context.drawImage( *m_image, rect, rect);115 context.drawImage(m_image, rect, rect); 115 116 context.restore(); 116 117 }); 117 118 118 m_nativeImagePtr = m_image->nativeImageForCurrentFrame(); 119 120 m_client->updateImageBacking(id(), m_buffer.copyRef()); 119 m_client.updateImageBacking(m_id, WTFMove(buffer)); 121 120 m_isDirty = false; 122 }123 124 void CoordinatedImageBacking::releaseSurfaceIfNeeded()125 {126 m_buffer = nullptr;127 }128 129 static const Seconds clearContentsTimerInterval { 3_s };130 131 void CoordinatedImageBacking::updateVisibilityIfNeeded(bool& changedToVisible)132 {133 bool previousIsVisible = m_isVisible;134 135 m_isVisible = false;136 for (auto& host : m_hosts) {137 if (host->imageBackingVisible()) {138 m_isVisible = true;139 break;140 }141 }142 143 bool changedToInvisible = previousIsVisible && !m_isVisible;144 if (changedToInvisible) {145 ASSERT(!m_clearContentsTimer.isActive());146 m_clearContentsTimer.startOneShot(clearContentsTimerInterval);147 }148 149 changedToVisible = !previousIsVisible && m_isVisible;150 151 if (m_isVisible && m_clearContentsTimer.isActive()) {152 m_clearContentsTimer.stop();153 // We don't want to update the texture if we didn't remove the texture.154 changedToVisible = false;155 }156 121 } 157 122 158 123 void CoordinatedImageBacking::clearContentsTimerFired() 159 124 { 160 m_client ->clearImageBackingContents(id());125 m_client.clearImageBackingContents(m_id); 161 126 } 162 127 163 128 } // namespace WebCore 129 164 130 #endif -
trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.h
r226657 r229316 24 24 */ 25 25 26 27 #ifndef CoordinatedImageBacking_h 28 #define CoordinatedImageBacking_h 26 #pragma once 29 27 30 28 #if USE(COORDINATED_GRAPHICS) … … 57 55 }; 58 56 59 static Ref<CoordinatedImageBacking> create(Client&, Ref<Image>&&); 57 static Ref<CoordinatedImageBacking> create(Client& client, Ref<Image>&& image) 58 { 59 return adoptRef(*new CoordinatedImageBacking(client, WTFMove(image))); 60 } 60 61 virtual ~CoordinatedImageBacking(); 61 62 62 static CoordinatedImageBackingID getCoordinatedImageBackingID(Image *);63 static CoordinatedImageBackingID getCoordinatedImageBackingID(Image&); 63 64 CoordinatedImageBackingID id() const { return m_id; } 64 65 65 void addHost(Host *);66 void removeHost(Host *);66 void addHost(Host&); 67 void removeHost(Host&); 67 68 68 69 // When a new image is updated or an animated gif is progressed, CoordinatedGraphicsLayer calls markDirty(). 69 void markDirty() ;70 void markDirty() { m_isDirty = true; } 70 71 71 72 // Create, remove or update its backing. … … 75 76 CoordinatedImageBacking(Client&, Ref<Image>&&); 76 77 77 void releaseSurfaceIfNeeded();78 void updateVisibilityIfNeeded(bool& changedToVisible);79 78 void clearContentsTimerFired(); 80 79 81 Client* m_client; 82 RefPtr<Image> m_image; 80 Client& m_client; 81 HashSet<Host*> m_hosts; 82 83 CoordinatedImageBackingID m_id; 84 Ref<Image> m_image; 83 85 NativeImagePtr m_nativeImagePtr; 84 CoordinatedImageBackingID m_id;85 Vector<Host*> m_hosts;86 87 RefPtr<Nicosia::Buffer> m_buffer;88 86 89 87 Timer m_clearContentsTimer; 90 88 91 bool m_isDirty; 92 bool m_isVisible; 93 89 bool m_isDirty { false }; 90 bool m_isVisible { false }; 94 91 }; 95 92 96 93 } // namespace WebCore 94 97 95 #endif // USE(COORDINATED_GRAPHICS) 98 99 #endif // CoordinatedImageBacking_h -
trunk/Source/WebKit/ChangeLog
r229315 r229316 1 2018-03-06 Zan Dobersek <zdobersek@igalia.com> 2 3 [CoordGraphics] Clean up CoordinatedImageBacking 4 https://bugs.webkit.org/show_bug.cgi?id=183332 5 6 Reviewed by Carlos Garcia Campos. 7 8 * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp: 9 (WebKit::CompositingCoordinator::createImageBackingIfNeeded): 10 Adjust call to CoordinatedImageBacking::getCoordinatedImageBackingID(). 11 1 12 2018-03-06 Zan Dobersek <zdobersek@igalia.com> 2 13 -
trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
r228373 r229316 214 214 Ref<CoordinatedImageBacking> CompositingCoordinator::createImageBackingIfNeeded(Image& image) 215 215 { 216 CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID( &image);216 CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID(image); 217 217 auto addResult = m_imageBackings.ensure(imageID, [this, &image] { 218 218 return CoordinatedImageBacking::create(*this, image);
Note: See TracChangeset
for help on using the changeset viewer.