diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp index 7c5e2b81fe90..a3b5f8ec5cf9 100644 --- a/gfx/gl/GLContext.cpp +++ b/gfx/gl/GLContext.cpp @@ -81,7 +81,6 @@ static const char* const sExtensionNames[] = { "GL_ANGLE_texture_compression_dxt5", "GL_ANGLE_timer_query", "GL_APPLE_client_storage", - "GL_APPLE_fence", "GL_APPLE_framebuffer_multisample", "GL_APPLE_sync", "GL_APPLE_texture_range", @@ -1081,15 +1080,6 @@ GLContext::LoadMoreSymbols(const char* prefix, bool trygl) fnLoadForExt(symbols, APPLE_texture_range); } - if (IsExtensionSupported(APPLE_fence)) { - const SymLoadStruct symbols[] = { - { (PRFuncPtr*) &mSymbols.fFinishObjectAPPLE, { "FinishObjectAPPLE", nullptr } }, - { (PRFuncPtr*) &mSymbols.fTestObjectAPPLE, { "TestObjectAPPLE", nullptr } }, - END_SYMBOLS - }; - fnLoadForExt(symbols, APPLE_fence); - } - if (IsSupported(GLFeature::vertex_array_object)) { const SymLoadStruct coreSymbols[] = { { (PRFuncPtr*) &mSymbols.fIsVertexArray, { "IsVertexArray", nullptr } }, diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index e0d03159ccd9..5ba544d4ee00 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -380,7 +380,6 @@ public: ANGLE_texture_compression_dxt5, ANGLE_timer_query, APPLE_client_storage, - APPLE_fence, APPLE_framebuffer_multisample, APPLE_sync, APPLE_texture_range, @@ -3303,25 +3302,6 @@ public: AFTER_GL_CALL; } -// ----------------------------------------------------------------------------- -// APPLE_fence - - void fFinishObjectAPPLE(GLenum object, GLint name) { - BEFORE_GL_CALL; - ASSERT_SYMBOL_PRESENT(fFinishObjectAPPLE); - mSymbols.fFinishObjectAPPLE(object, name); - AFTER_GL_CALL; - } - - realGLboolean fTestObjectAPPLE(GLenum object, GLint name) { - realGLboolean ret = false; - BEFORE_GL_CALL; - ASSERT_SYMBOL_PRESENT(fTestObjectAPPLE); - ret = mSymbols.fTestObjectAPPLE(object, name); - AFTER_GL_CALL; - return ret; - } - // ----------------------------------------------------------------------------- // prim_restart diff --git a/gfx/gl/GLContextSymbols.h b/gfx/gl/GLContextSymbols.h index 7ee30f952bfe..76f6008ef6af 100644 --- a/gfx/gl/GLContextSymbols.h +++ b/gfx/gl/GLContextSymbols.h @@ -137,8 +137,6 @@ struct GLContextSymbols final void (GLAPIENTRY * fTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const void*); void (GLAPIENTRY * fTextureRangeAPPLE)(GLenum, GLsizei, GLvoid*); - void (GLAPIENTRY * fFinishObjectAPPLE)(GLenum, GLint); - realGLboolean (GLAPIENTRY * fTestObjectAPPLE)(GLenum, GLint); void (GLAPIENTRY * fUniform1f)(GLint, GLfloat); void (GLAPIENTRY * fUniform1fv)(GLint, GLsizei, const GLfloat*); void (GLAPIENTRY * fUniform1i)(GLint, GLint); diff --git a/gfx/layers/BufferTexture.cpp b/gfx/layers/BufferTexture.cpp index b107da9f60df..d78d4e308bee 100644 --- a/gfx/layers/BufferTexture.cpp +++ b/gfx/layers/BufferTexture.cpp @@ -105,13 +105,8 @@ static bool UsingX11Compositor() } bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat, - LayersBackend aLayersBackend, - bool aSupportsTextureDirectMapping) + LayersBackend aLayersBackend) { - if (aSupportsTextureDirectMapping) { - return false; - } - return aLayersBackend != LayersBackend::LAYERS_BASIC || UsingX11Compositor() || aFormat == gfx::SurfaceFormat::UNKNOWN; @@ -173,8 +168,7 @@ BufferTextureData::CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator, } bool hasIntermediateBuffer = aAllocator ? ComputeHasIntermediateBuffer(gfx::SurfaceFormat::YUV, - aAllocator->GetCompositorBackendType(), - aAllocator->SupportsTextureDirectMapping()) + aAllocator->GetCompositorBackendType()) : true; // Initialize the metadata with something, even if it will have to be rewritten @@ -216,8 +210,7 @@ BufferTextureData::CreateForYCbCr(KnowsCompositor* aAllocator, bool hasIntermediateBuffer = aAllocator ? ComputeHasIntermediateBuffer(gfx::SurfaceFormat::YUV, - aAllocator->GetCompositorBackendType(), - aAllocator->SupportsTextureDirectMapping()) + aAllocator->GetCompositorBackendType()) : true; YCbCrDescriptor descriptor = YCbCrDescriptor(aYSize, aYStride, @@ -532,9 +525,7 @@ MemoryTextureData::Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat, return nullptr; } - bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat, - aLayersBackend, - aAllocFlags & ALLOC_ALLOW_DIRECT_MAPPING); + bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat, aLayersBackend); GfxMemoryImageReporter::DidAlloc(buf); @@ -610,9 +601,7 @@ ShmemTextureData::Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat, return nullptr; } - bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat, - aLayersBackend, - aAllocFlags & ALLOC_ALLOW_DIRECT_MAPPING); + bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat, aLayersBackend); BufferDescriptor descriptor = RGBDescriptor(aSize, aFormat, hasIntermediateBuffer); diff --git a/gfx/layers/BufferTexture.h b/gfx/layers/BufferTexture.h index 570b0a652dc4..4dad7b30efb6 100644 --- a/gfx/layers/BufferTexture.h +++ b/gfx/layers/BufferTexture.h @@ -17,8 +17,7 @@ namespace mozilla { namespace layers { bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat, - LayersBackend aLayersBackend, - bool aSupportsTextureDirectMapping); + LayersBackend aLayersBackend); class BufferTextureData : public TextureData { diff --git a/gfx/layers/CompositorTypes.h b/gfx/layers/CompositorTypes.h index 12cf745201dd..0bda30f7970c 100644 --- a/gfx/layers/CompositorTypes.h +++ b/gfx/layers/CompositorTypes.h @@ -175,7 +175,6 @@ struct TextureFactoryIdentifier LayersBackend mParentBackend; GeckoProcessType mParentProcessType; int32_t mMaxTextureSize; - bool mSupportsTextureDirectMapping; bool mCompositorUseANGLE; bool mSupportsTextureBlitting; bool mSupportsPartialUploads; @@ -186,7 +185,6 @@ struct TextureFactoryIdentifier explicit TextureFactoryIdentifier(LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE, GeckoProcessType aParentProcessType = GeckoProcessType_Default, int32_t aMaxTextureSize = 4096, - bool aSupportsTextureDirectMapping = false, bool aCompositorUseANGLE = false, bool aSupportsTextureBlitting = false, bool aSupportsPartialUploads = false, @@ -195,7 +193,6 @@ struct TextureFactoryIdentifier : mParentBackend(aLayersBackend) , mParentProcessType(aParentProcessType) , mMaxTextureSize(aMaxTextureSize) - , mSupportsTextureDirectMapping(aSupportsTextureDirectMapping) , mCompositorUseANGLE(aCompositorUseANGLE) , mSupportsTextureBlitting(aSupportsTextureBlitting) , mSupportsPartialUploads(aSupportsPartialUploads) @@ -209,12 +206,10 @@ struct TextureFactoryIdentifier mParentBackend == aOther.mParentBackend && mParentProcessType == aOther.mParentProcessType && mMaxTextureSize == aOther.mMaxTextureSize && - mSupportsTextureDirectMapping == aOther.mSupportsTextureDirectMapping && mCompositorUseANGLE == aOther.mCompositorUseANGLE && mSupportsTextureBlitting == aOther.mSupportsTextureBlitting && mSupportsPartialUploads == aOther.mSupportsPartialUploads && mSupportsComponentAlpha == aOther.mSupportsComponentAlpha && - mUsingAdvancedLayers == aOther.mUsingAdvancedLayers && mSyncHandle == aOther.mSyncHandle; } }; diff --git a/gfx/layers/TextureSourceProvider.cpp b/gfx/layers/TextureSourceProvider.cpp index 826acc37f03a..ca3ccc957359 100644 --- a/gfx/layers/TextureSourceProvider.cpp +++ b/gfx/layers/TextureSourceProvider.cpp @@ -6,10 +6,6 @@ #include "mozilla/layers/TextureSourceProvider.h" #include "mozilla/layers/TextureHost.h" -#include "mozilla/layers/PTextureParent.h" -#ifdef XP_DARWIN -#include "mozilla/layers/TextureSync.h" -#endif namespace mozilla { namespace layers { @@ -22,30 +18,9 @@ TextureSourceProvider::~TextureSourceProvider() void TextureSourceProvider::ReadUnlockTextures() { -#ifdef XP_DARWIN - nsClassHashtable> texturesIdsToUnlockByPid; - for (auto& texture : mUnlockAfterComposition) { - auto bufferTexture = texture->AsBufferTextureHost(); - if (bufferTexture && bufferTexture->IsDirectMap()) { - texture->ReadUnlock(); - auto actor = texture->GetIPDLActor(); - if (actor) { - base::ProcessId pid = actor->OtherPid(); - nsTArray* textureIds = texturesIdsToUnlockByPid.LookupOrAdd(pid); - textureIds->AppendElement(TextureHost::GetTextureSerial(actor)); - } - } else { - texture->ReadUnlock(); - } - } - for (auto it = texturesIdsToUnlockByPid.ConstIter(); !it.Done(); it.Next()) { - TextureSync::SetTexturesUnlocked(it.Key(), *it.UserData()); - } -#else for (auto& texture : mUnlockAfterComposition) { texture->ReadUnlock(); } -#endif mUnlockAfterComposition.Clear(); } diff --git a/gfx/layers/TextureSourceProvider.h b/gfx/layers/TextureSourceProvider.h index 830c0be21110..08fe608db845 100644 --- a/gfx/layers/TextureSourceProvider.h +++ b/gfx/layers/TextureSourceProvider.h @@ -74,9 +74,6 @@ public: /// Returns true if notified, false otherwise. virtual bool NotifyNotUsedAfterComposition(TextureHost* aTextureHost); - virtual void MaybeUnlockBeforeNextComposition(TextureHost* aTextureHost) {} - virtual void TryUnlockTextures() {} - // If overridden, make sure to call the base function. virtual void Destroy(); diff --git a/gfx/layers/TextureSync.cpp b/gfx/layers/TextureSync.cpp deleted file mode 100644 index 2f3a6bf4e9e3..000000000000 --- a/gfx/layers/TextureSync.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "TextureSync.h" - -#include - -#include "chrome/common/mach_ipc_mac.h" -#include "mozilla/ipc/SharedMemoryBasic.h" -#include "mozilla/layers/CompositorThread.h" -#include "mozilla/StaticMonitor.h" -#include "mozilla/StaticPtr.h" - -#ifdef DEBUG -#define LOG_ERROR(str, args...) \ - PR_BEGIN_MACRO \ - mozilla::SmprintfPointer msg = mozilla::Smprintf(str, ## args); \ - NS_WARNING(msg.get()); \ - PR_END_MACRO -#else -#define LOG_ERROR(str, args...) do { /* nothing */ } while(0) -#endif - -namespace mozilla { - -namespace layers { - -// Hold raw pointers and trust that TextureSourceProviders will be -// unregistered in their destructors - we don't want to keep these -// alive, and destroying them from the main thread will be an -// error anyway. -StaticAutoPtr> gTextureSourceProviders; - -static std::map> gProcessTextureIds; -static StaticMonitor gTextureLockMonitor; - -const int kSendMessageTimeout = 1000; -const int kTextureLockTimeout = 32; // We really don't want to wait more than - // two frames for a texture to unlock. This - // will in any case be very uncommon. - -struct WaitForTexturesReply -{ - bool success; -}; - -struct WaitForTexturesRequest -{ - pid_t pid; -}; - -std::unordered_set* -GetLockedTextureIdsForProcess(pid_t pid) -{ - gTextureLockMonitor.AssertCurrentThreadOwns(); - - if (gProcessTextureIds.find(pid) == gProcessTextureIds.end()) { - gProcessTextureIds[pid] = std::unordered_set(); - } - - return &gProcessTextureIds.at(pid); -} - -bool -WaitForTextureIdsToUnlock(pid_t pid, const Span& textureIds) -{ - { - StaticMonitorAutoLock lock(gTextureLockMonitor); - std::unordered_set* freedTextureIds = GetLockedTextureIdsForProcess(pid); - - TimeStamp start = TimeStamp::Now(); - while (true) { - bool allCleared = true; - for (uint64_t textureId : textureIds) { - if (freedTextureIds->find(textureId) != freedTextureIds->end()) { - allCleared = false; - } - } - - if (allCleared) { - return true; - } - - if (lock.Wait(TimeDuration::FromMilliseconds(kTextureLockTimeout)) == CVStatus::Timeout) { - return false; - } - - // In case the monitor gets signaled multiple times, each less than kTextureLockTimeout. - // This ensures that the total time we wait is < 2 * kTextureLockTimeout - if ((TimeStamp::Now() - start).ToMilliseconds() > (double)kTextureLockTimeout) { - return false; - } - } - } -} - -void -CheckTexturesForUnlock() -{ - if (gTextureSourceProviders) { - for (auto it = gTextureSourceProviders->begin(); it != gTextureSourceProviders->end(); ++it) { - (*it)->TryUnlockTextures(); - } - } -} - -void -TextureSync::DispatchCheckTexturesForUnlock() -{ - RefPtr task = NS_NewRunnableFunction( - "CheckTexturesForUnlock", - &CheckTexturesForUnlock); - CompositorThreadHolder::Loop()->PostTask(task.forget()); -} - -void -TextureSync::HandleWaitForTexturesMessage(MachReceiveMessage* rmsg, ipc::MemoryPorts* ports) -{ - WaitForTexturesRequest* req = reinterpret_cast(rmsg->GetData()); - uint64_t* textureIds = (uint64_t*)(req + 1); - uint32_t textureIdsLength = (rmsg->GetDataLength() - sizeof(WaitForTexturesRequest)) / sizeof(uint64_t); - - bool success = WaitForTextureIdsToUnlock(req->pid, MakeSpan(textureIds, textureIdsLength)); - - if (!success) { - LOG_ERROR("Waiting for textures to unlock failed.\n"); - } - - MachSendMessage msg(ipc::kReturnWaitForTexturesMsg); - WaitForTexturesReply replydata; - replydata.success = success; - msg.SetData(&replydata, sizeof(WaitForTexturesReply)); - kern_return_t err = ports->mSender->SendMessage(msg, kSendMessageTimeout); - if (KERN_SUCCESS != err) { - LOG_ERROR("SendMessage failed 0x%x %s\n", err, mach_error_string(err)); - } -} - -void -TextureSync::RegisterTextureSourceProvider(TextureSourceProvider* textureSourceProvider) -{ - if (!gTextureSourceProviders) { - gTextureSourceProviders = new nsTArray(); - } - MOZ_RELEASE_ASSERT(!gTextureSourceProviders->Contains(textureSourceProvider)); - gTextureSourceProviders->AppendElement(textureSourceProvider); -} - -void -TextureSync::UnregisterTextureSourceProvider(TextureSourceProvider* textureSourceProvider) -{ - if (gTextureSourceProviders) { - MOZ_ASSERT(gTextureSourceProviders->Contains(textureSourceProvider)); - gTextureSourceProviders->RemoveElement(textureSourceProvider); - if (gTextureSourceProviders->Length() == 0) { - gTextureSourceProviders = nullptr; - } - } -} - -void -TextureSync::SetTexturesLocked(pid_t pid, const nsTArray& textureIds) -{ - StaticMonitorAutoLock mal(gTextureLockMonitor); - std::unordered_set* lockedTextureIds = GetLockedTextureIdsForProcess(pid); - for (uint64_t textureId : textureIds) { - lockedTextureIds->insert(textureId); - } -} - -void -TextureSync::SetTexturesUnlocked(pid_t pid, const nsTArray& textureIds) -{ - bool oneErased = false; - { - StaticMonitorAutoLock mal(gTextureLockMonitor); - std::unordered_set* lockedTextureIds = GetLockedTextureIdsForProcess(pid); - for (uint64_t textureId : textureIds) { - if (lockedTextureIds->erase(textureId)) { - oneErased = true; - } - } - } - if (oneErased) { - gTextureLockMonitor.NotifyAll(); - } -} - -void -TextureSync::Shutdown() -{ - { - StaticMonitorAutoLock lock(gTextureLockMonitor); - - for (auto& lockedTextureIds : gProcessTextureIds) { - lockedTextureIds.second.clear(); - } - } - - gTextureLockMonitor.NotifyAll(); - - { - StaticMonitorAutoLock lock(gTextureLockMonitor); - gProcessTextureIds.clear(); - } -} - -void -TextureSync::UpdateTextureLocks(base::ProcessId aProcessId) -{ - if (aProcessId == getpid()) { - DispatchCheckTexturesForUnlock(); - return; - } - - MachSendMessage smsg(ipc::kUpdateTextureLocksMsg); - smsg.SetData(&aProcessId, sizeof(aProcessId)); - ipc::SharedMemoryBasic::SendMachMessage(aProcessId, smsg, NULL); -} - -bool -TextureSync::WaitForTextures(base::ProcessId aProcessId, const nsTArray& textureIds) -{ - if (aProcessId == getpid()) { - bool success = WaitForTextureIdsToUnlock(aProcessId, MakeSpan(textureIds)); - if (!success) { - LOG_ERROR("Failed waiting for textures to unlock.\n"); - } - - return success; - } - - MachSendMessage smsg(ipc::kWaitForTexturesMsg); - size_t messageSize = sizeof(WaitForTexturesRequest) + textureIds.Length() * sizeof(uint64_t); - UniquePtr messageData = MakeUnique(messageSize); - WaitForTexturesRequest* req = (WaitForTexturesRequest*)messageData.get(); - uint64_t* reqTextureIds = (uint64_t*)(req + 1); - - for (uint32_t i = 0; i < textureIds.Length(); ++i) { - reqTextureIds[i] = textureIds[i]; - } - - req->pid = getpid(); - bool dataWasSet = smsg.SetData(req, messageSize); - - if (!dataWasSet) { - LOG_ERROR("Data was too large: %zu\n", messageSize); - return false; - } - - MachReceiveMessage msg; - bool success = ipc::SharedMemoryBasic::SendMachMessage(aProcessId, smsg, &msg); - if (!success) { - return false; - } - - if (msg.GetDataLength() != sizeof(WaitForTexturesReply)) { - LOG_ERROR("Improperly formatted reply\n"); - return false; - } - - WaitForTexturesReply* msg_data = reinterpret_cast(msg.GetData()); - if (!msg_data->success) { - LOG_ERROR("Failed waiting for textures to unlock.\n"); - return false; - } - - return true; -} - -void -TextureSync::CleanupForPid(base::ProcessId aProcessId) -{ - { - StaticMonitorAutoLock lock(gTextureLockMonitor); - std::unordered_set* lockedTextureIds = GetLockedTextureIdsForProcess(aProcessId); - lockedTextureIds->clear(); - } - gTextureLockMonitor.NotifyAll(); -} - -} // namespace layers - -} // namespace mozilla \ No newline at end of file diff --git a/gfx/layers/TextureSync.h b/gfx/layers/TextureSync.h deleted file mode 100644 index 67b83af1883f..000000000000 --- a/gfx/layers/TextureSync.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MOZILLA_LAYERS_TEXTURESYNC_H -#define MOZILLA_LAYERS_TEXTURESYNC_H - -#include "base/process.h" - -#include "nsTArray.h" -#include "mozilla/layers/TextureSourceProvider.h" - -#include "SharedMemory.h" - -class MachReceiveMessage; - -namespace mozilla { -namespace ipc { - struct MemoryPorts; -} // namespace ipc - -namespace layers { - -class TextureSync -{ -public: - static void RegisterTextureSourceProvider(layers::TextureSourceProvider* aTextureSourceProvider); - static void UnregisterTextureSourceProvider(layers::TextureSourceProvider* aTextureSourceProvider); - static void DispatchCheckTexturesForUnlock(); - static void HandleWaitForTexturesMessage(MachReceiveMessage* rmsg, ipc::MemoryPorts* ports); - static void UpdateTextureLocks(base::ProcessId aProcessId); - static bool WaitForTextures(base::ProcessId aProcessId, const nsTArray& aTextureIds); - static void SetTexturesLocked(base::ProcessId aProcessId, const nsTArray& aTextureIds); - static void SetTexturesUnlocked(base::ProcessId aProcessId, const nsTArray& aTextureIds); - static void Shutdown(); - static void CleanupForPid(base::ProcessId aProcessId); -}; - -} // namespace layers -} // namespace mozilla - -#endif \ No newline at end of file diff --git a/gfx/layers/client/ClientLayerManager.cpp b/gfx/layers/client/ClientLayerManager.cpp index 264ac70dbde5..df6e2a345d9a 100644 --- a/gfx/layers/client/ClientLayerManager.cpp +++ b/gfx/layers/client/ClientLayerManager.cpp @@ -317,15 +317,6 @@ ClientLayerManager::EndTransactionInternal(DrawPaintedLayerCallback aCallback, void* aCallbackData, EndTransactionFlags) { - // This just causes the compositor to check whether the GPU is done with its - // textures or not and unlock them if it is. This helps us avoid the case - // where we take a long time painting asynchronously, turn IPC back on at - // the end of that, and then have to wait for the compositor to to get into - // TiledLayerBufferComposite::UseTiles before getting a response. - if (mForwarder) { - mForwarder->UpdateTextureLocks(); - } - // Wait for any previous async paints to complete before starting to paint again. // Do this outside the profiler and telemetry block so this doesn't count as time // spent rasterizing. diff --git a/gfx/layers/client/ContentClient.cpp b/gfx/layers/client/ContentClient.cpp index 9f4d7bee146a..af117dd21208 100644 --- a/gfx/layers/client/ContentClient.cpp +++ b/gfx/layers/client/ContentClient.cpp @@ -762,14 +762,10 @@ ContentClientRemoteBuffer::CreateBufferInternal(const gfx::IntRect& aRect, RefPtr textureClientOnWhite; if (aFlags & TextureFlags::COMPONENT_ALPHA) { - TextureAllocationFlags allocFlags = ALLOC_CLEAR_BUFFER_WHITE; - if (mForwarder->SupportsTextureDirectMapping()) { - allocFlags = TextureAllocationFlags(allocFlags | ALLOC_ALLOW_DIRECT_MAPPING); - } textureClientOnWhite = textureClient->CreateSimilar( mForwarder->GetCompositorBackendType(), aFlags | ExtraTextureFlags(), - allocFlags + TextureAllocationFlags::ALLOC_CLEAR_BUFFER_WHITE ); if (!textureClientOnWhite || !AddTextureClient(textureClientOnWhite)) { return nullptr; diff --git a/gfx/layers/client/MultiTiledContentClient.cpp b/gfx/layers/client/MultiTiledContentClient.cpp index 174ae027aa18..36ceed2a484d 100644 --- a/gfx/layers/client/MultiTiledContentClient.cpp +++ b/gfx/layers/client/MultiTiledContentClient.cpp @@ -140,42 +140,6 @@ ClientMultiTiledLayerBuffer::PaintThebes(const nsIntRegion& aNewValidRegion, mCallbackData = nullptr; } -void ClientMultiTiledLayerBuffer::MaybeSyncTextures(const nsIntRegion& aPaintRegion, - const TilesPlacement& aNewTiles, - const IntSize& aScaledTileSize) -{ - if (mManager->AsShadowForwarder()->SupportsTextureDirectMapping()) { - AutoTArray syncTextureSerials; - SurfaceMode mode; - Unused << GetContentType(&mode); - - // Pre-pass through the tiles (mirroring the filter logic below) to gather - // texture IDs that we need to ensure are unused by the GPU before we - // continue. - if (!aPaintRegion.IsEmpty()) { - MOZ_ASSERT(mPaintStates.size() == 0); - for (size_t i = 0; i < mRetainedTiles.Length(); ++i) { - const TileCoordIntPoint tileCoord = aNewTiles.TileCoord(i); - - IntPoint tileOffset = GetTileOffset(tileCoord); - nsIntRegion tileDrawRegion = IntRect(tileOffset, aScaledTileSize); - tileDrawRegion.AndWith(aPaintRegion); - - if (tileDrawRegion.IsEmpty()) { - continue; - } - - TileClient& tile = mRetainedTiles[i]; - tile.GetSyncTextureSerials(mode, syncTextureSerials); - } - } - - if (syncTextureSerials.Length() > 0) { - mManager->AsShadowForwarder()->SyncTextures(syncTextureSerials); - } - } -} - void ClientMultiTiledLayerBuffer::Update(const nsIntRegion& newValidRegion, const nsIntRegion& aPaintRegion, const nsIntRegion& aDirtyRegion, @@ -217,9 +181,6 @@ void ClientMultiTiledLayerBuffer::Update(const nsIntRegion& newValidRegion, nsIntRegion paintRegion = aPaintRegion; nsIntRegion dirtyRegion = aDirtyRegion; - - MaybeSyncTextures(paintRegion, newTiles, scaledTileSize); - if (!paintRegion.IsEmpty()) { MOZ_ASSERT(mPaintStates.size() == 0); for (size_t i = 0; i < newTileCount; ++i) { diff --git a/gfx/layers/client/MultiTiledContentClient.h b/gfx/layers/client/MultiTiledContentClient.h index 4140a845eb24..592a63c67ce5 100644 --- a/gfx/layers/client/MultiTiledContentClient.h +++ b/gfx/layers/client/MultiTiledContentClient.h @@ -156,10 +156,6 @@ private: nsIntRegion& aRegionToPaint, BasicTiledLayerPaintData* aPaintData, bool aIsRepeated); - - void MaybeSyncTextures(const nsIntRegion& aPaintRegion, - const TilesPlacement& aNewTiles, - const gfx::IntSize& aScaledTileSize); }; /** diff --git a/gfx/layers/client/SingleTiledContentClient.cpp b/gfx/layers/client/SingleTiledContentClient.cpp index 93a0c807ddb6..be0ff3bde670 100644 --- a/gfx/layers/client/SingleTiledContentClient.cpp +++ b/gfx/layers/client/SingleTiledContentClient.cpp @@ -140,15 +140,6 @@ ClientSingleTiledLayerBuffer::PaintThebes(const nsIntRegion& aNewValidRegion, mTile.SetTextureAllocator(this); } - - if (mManager->AsShadowForwarder()->SupportsTextureDirectMapping()) { - AutoTArray syncTextureSerials; - mTile.GetSyncTextureSerials(mode, syncTextureSerials); - if (syncTextureSerials.Length() > 0) { - mManager->AsShadowForwarder()->SyncTextures(syncTextureSerials); - } - } - // The dirty region relative to the top-left of the tile. nsIntRegion tileVisibleRegion = aNewValidRegion.MovedBy(-mTilingOrigin); nsIntRegion tileDirtyRegion = paintRegion.MovedBy(-mTilingOrigin); diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index dd17a997f065..d359e7aaee15 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -660,9 +660,7 @@ TextureClient::UpdateFromSurface(gfx::SourceSurface* aSurface) already_AddRefed -TextureClient::CreateSimilar(LayersBackend aLayersBackend, - TextureFlags aFlags, - TextureAllocationFlags aAllocFlags) const +TextureClient::CreateSimilar(LayersBackend aLayersBackend, TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const { MOZ_ASSERT(IsValid()); @@ -672,10 +670,7 @@ TextureClient::CreateSimilar(LayersBackend aLayersBackend, } LockActor(); - TextureData* data = mData->CreateSimilar(mAllocator, - aLayersBackend, - aFlags, - aAllocFlags); + TextureData* data = mData->CreateSimilar(mAllocator, aLayersBackend, aFlags, aAllocFlags); UnlockActor(); if (!data) { @@ -1065,9 +1060,6 @@ TextureClient::CreateForDrawing(KnowsCompositor* aAllocator, TextureAllocationFlags aAllocFlags) { LayersBackend layersBackend = aAllocator->GetCompositorBackendType(); - if (aAllocator->SupportsTextureDirectMapping()) { - aAllocFlags = TextureAllocationFlags(aAllocFlags | ALLOC_ALLOW_DIRECT_MAPPING); - } return TextureClient::CreateForDrawing(aAllocator->GetTextureForwarder(), aFormat, aSize, layersBackend, @@ -1234,16 +1226,6 @@ TextureClient::CreateForRawBufferAccess(KnowsCompositor* aAllocator, TextureFlags aTextureFlags, TextureAllocationFlags aAllocFlags) { - // If we exceed the max texture size for the GPU, then just fall back to no - // texture direct mapping. If it becomes a problem we can implement tiling - // logic inside DirectMapTextureSource to allow this. - bool supportsTextureDirectMapping = aAllocator->SupportsTextureDirectMapping() && - std::max(aSize.width, aSize.height) <= aAllocator->GetMaxTextureSize(); - if (supportsTextureDirectMapping) { - aAllocFlags = TextureAllocationFlags(aAllocFlags | ALLOC_ALLOW_DIRECT_MAPPING); - } else { - aAllocFlags = TextureAllocationFlags(aAllocFlags & ~ALLOC_ALLOW_DIRECT_MAPPING); - } return CreateForRawBufferAccess(aAllocator->GetTextureForwarder(), aFormat, aSize, aMoz2DBackend, aAllocator->GetCompositorBackendType(), diff --git a/gfx/layers/client/TextureClient.h b/gfx/layers/client/TextureClient.h index 40c87606b8e2..321b1c65e1d8 100644 --- a/gfx/layers/client/TextureClient.h +++ b/gfx/layers/client/TextureClient.h @@ -94,10 +94,6 @@ enum TextureAllocationFlags { // The texture is going to be updated using UpdateFromSurface and needs to support // that call. ALLOC_UPDATE_FROM_SURFACE = 1 << 7, - - // In practice, this means we support the APPLE_client_storage extension, meaning - // the buffer will not be internally copied by the graphics driver. - ALLOC_ALLOW_DIRECT_MAPPING = 1 << 8, }; /** diff --git a/gfx/layers/client/TextureClientPool.cpp b/gfx/layers/client/TextureClientPool.cpp index 721c6cc9c6b6..5861604e538e 100644 --- a/gfx/layers/client/TextureClientPool.cpp +++ b/gfx/layers/client/TextureClientPool.cpp @@ -39,7 +39,6 @@ ClearCallback(nsITimer *aTimer, void *aClosure) } TextureClientPool::TextureClientPool(LayersBackend aLayersBackend, - bool aSupportsTextureDirectMapping, int32_t aMaxTextureSize, gfx::SurfaceFormat aFormat, gfx::IntSize aSize, @@ -61,7 +60,6 @@ TextureClientPool::TextureClientPool(LayersBackend aLayersBackend, , mOutstandingClients(0) , mSurfaceAllocator(aAllocator) , mDestroyed(false) - , mSupportsTextureDirectMapping(aSupportsTextureDirectMapping) { TCP_LOG("TexturePool %p created with maximum unused texture clients %u\n", this, mInitialPoolSize); @@ -151,12 +149,6 @@ TextureClientPool::AllocateTextureClient() TCP_LOG("TexturePool %p allocating TextureClient, outstanding %u\n", this, mOutstandingClients); - TextureAllocationFlags allocFlags = ALLOC_DEFAULT; - - if (mSupportsTextureDirectMapping) { - allocFlags = TextureAllocationFlags(allocFlags | ALLOC_ALLOW_DIRECT_MAPPING); - } - RefPtr newClient; if (gfxPrefs::ForceShmemTiles()) { // gfx::BackendType::NONE means use the content backend @@ -165,7 +157,7 @@ TextureClientPool::AllocateTextureClient() mFormat, mSize, gfx::BackendType::NONE, mBackend, - mFlags, allocFlags); + mFlags, ALLOC_DEFAULT); } else { newClient = TextureClient::CreateForDrawing(mSurfaceAllocator, @@ -173,7 +165,7 @@ TextureClientPool::AllocateTextureClient() mBackend, mMaxTextureSize, BackendSelector::Content, - mFlags, allocFlags); + mFlags); } if (newClient) { diff --git a/gfx/layers/client/TextureClientPool.h b/gfx/layers/client/TextureClientPool.h index d2a4cdf17346..ee46b5ba34cf 100644 --- a/gfx/layers/client/TextureClientPool.h +++ b/gfx/layers/client/TextureClientPool.h @@ -46,7 +46,6 @@ class TextureClientPool final : public TextureClientAllocator public: TextureClientPool(LayersBackend aBackend, - bool aSupportsTextureDirectMapping, int32_t aMaxTextureSize, gfx::SurfaceFormat aFormat, gfx::IntSize aSize, @@ -171,8 +170,6 @@ private: // we won't accept returns of TextureClients anymore, and the refcounting // should take care of their destruction. bool mDestroyed; - - bool mSupportsTextureDirectMapping; }; } // namespace layers diff --git a/gfx/layers/client/TiledContentClient.cpp b/gfx/layers/client/TiledContentClient.cpp index 66ede3245f48..923330e29f79 100644 --- a/gfx/layers/client/TiledContentClient.cpp +++ b/gfx/layers/client/TiledContentClient.cpp @@ -664,32 +664,6 @@ CreateBackBufferTexture(TextureClient* aCurrentTexture, return texture.forget(); } -void -TileClient::GetSyncTextureSerials(SurfaceMode aMode, nsTArray& aSerials) -{ - if (mFrontBuffer && - mFrontBuffer->HasIntermediateBuffer() && - !mFrontBuffer->IsReadLocked() && - (aMode != SurfaceMode::SURFACE_COMPONENT_ALPHA || ( - mFrontBufferOnWhite && !mFrontBufferOnWhite->IsReadLocked()))) - { - return; - } - - if (mBackBuffer && - !mBackBuffer->HasIntermediateBuffer() && - mBackBuffer->IsReadLocked()) { - aSerials.AppendElement(mBackBuffer->GetSerial()); - } - - if (aMode == SurfaceMode::SURFACE_COMPONENT_ALPHA && - mBackBufferOnWhite && - !mBackBufferOnWhite->HasIntermediateBuffer() && - mBackBufferOnWhite->IsReadLocked()) { - aSerials.AppendElement(mBackBufferOnWhite->GetSerial()); - } -} - TextureClient* TileClient::GetBackBuffer(CompositableClient& aCompositable, const nsIntRegion& aDirtyRegion, @@ -748,18 +722,17 @@ TileClient::GetBackBuffer(CompositableClient& aCompositable, mInvalidBack = IntRect(IntPoint(), mBackBuffer->GetSize()); } - if (aMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) { - if (!mBackBufferOnWhite || mBackBufferOnWhite->IsReadLocked()) { - mBackBufferOnWhite = CreateBackBufferTexture( - mBackBufferOnWhite, aCompositable, mAllocator - ); - if (!mBackBufferOnWhite) { - DiscardBackBuffer(); - DiscardFrontBuffer(); - return nullptr; - } - mInvalidBack = IntRect(IntPoint(), mBackBufferOnWhite->GetSize()); + if (aMode == SurfaceMode::SURFACE_COMPONENT_ALPHA + && (!mBackBufferOnWhite || mBackBufferOnWhite->IsReadLocked())) { + mBackBufferOnWhite = CreateBackBufferTexture( + mBackBufferOnWhite, aCompositable, mAllocator + ); + if (!mBackBufferOnWhite) { + DiscardBackBuffer(); + DiscardFrontBuffer(); + return nullptr; } + mInvalidBack = IntRect(IntPoint(), mBackBufferOnWhite->GetSize()); } ValidateBackBufferFromFront(aDirtyRegion, aVisibleRegion, aAddPaintedRegion, aFlags, aCopies, aClients); diff --git a/gfx/layers/client/TiledContentClient.h b/gfx/layers/client/TiledContentClient.h index e9235b581765..4af771462c02 100644 --- a/gfx/layers/client/TiledContentClient.h +++ b/gfx/layers/client/TiledContentClient.h @@ -114,8 +114,6 @@ struct TileClient CompositableClient::DumpTextureClient(aStream, mFrontBuffer, aCompress); } - void GetSyncTextureSerials(SurfaceMode aMode, nsTArray& aSerials); - /** * Returns an unlocked TextureClient that can be used for writing new * data to the tile. This may flip the front-buffer to the back-buffer if @@ -327,9 +325,6 @@ public: LayerManager::DrawPaintedLayerCallback aCallback, void* aCallbackData, TilePaintFlags aFlags) = 0; - virtual void GetSyncTextureSerials(const nsIntRegion& aPaintRegion, - const nsIntRegion& aDirtyRegion, - nsTArray& aSerials) { return; } virtual bool SupportsProgressiveUpdate() = 0; virtual bool ProgressiveUpdate(const nsIntRegion& aValidRegion, diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index 66f901d40f90..0b2a1528848c 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -21,9 +21,6 @@ #include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL #include "mozilla/layers/ImageDataSerializer.h" #include "mozilla/layers/TextureClient.h" -#ifdef XP_DARWIN -#include "mozilla/layers/TextureSync.h" -#endif #include "mozilla/layers/GPUVideoTextureHost.h" #include "mozilla/layers/WebRenderTextureHost.h" #include "mozilla/webrender/RenderBufferTextureHost.h" @@ -373,14 +370,11 @@ TextureHost::TextureHost(TextureFlags aFlags) TextureHost::~TextureHost() { - if (mReadLocked) { - // If we still have a ReadLock, unlock it. At this point we don't care about - // the texture client being written into on the other side since it should be - // destroyed by now. But we will hit assertions if we don't ReadUnlock before - // destroying the lock itself. - ReadUnlock(); - MaybeNotifyUnlocked(); - } + // If we still have a ReadLock, unlock it. At this point we don't care about + // the texture client being written into on the other side since it should be + // destroyed by now. But we will hit assertions if we don't ReadUnlock before + // destroying the lock itself. + ReadUnlock(); } void TextureHost::Finalize() @@ -406,7 +400,6 @@ TextureHost::UnbindTextureSource() // GetCompositor returned null which means no compositor can be using this // texture. We can ReadUnlock right away. ReadUnlock(); - MaybeNotifyUnlocked(); } } } @@ -708,9 +701,6 @@ TextureHost::SetReadLocked() // side should not have been able to write into this texture and read lock again! MOZ_ASSERT(!mReadLocked); mReadLocked = true; - if (mProvider) { - mProvider->MaybeUnlockBeforeNextComposition(this); - } } void @@ -896,36 +886,12 @@ BufferTextureHost::AcquireTextureSource(CompositableTextureSourceRef& aTexture) return !!mFirstSource; } -void -BufferTextureHost::ReadUnlock() -{ - if (mFirstSource) { - mFirstSource->Sync(true); - } - - TextureHost::ReadUnlock(); -} - -void -BufferTextureHost::MaybeNotifyUnlocked() -{ -#ifdef XP_DARWIN - auto actor = GetIPDLActor(); - if (actor) { - AutoTArray serials; - serials.AppendElement(TextureHost::GetTextureSerial(actor)); - TextureSync::SetTexturesUnlocked(actor->OtherPid(), serials); - } -#endif -} - void BufferTextureHost::UnbindTextureSource() { if (mFirstSource && mFirstSource->IsOwnedBy(this)) { mFirstSource->Unbind(); } - // This texture is not used by any layer anymore. // If the texture doesn't have an intermediate buffer, it means we are // compositing synchronously on the CPU, so we don't need to wait until @@ -934,7 +900,6 @@ BufferTextureHost::UnbindTextureSource() // If the texture has an intermediate buffer we don't care either because // texture uploads are also performed synchronously for BufferTextureHost. ReadUnlock(); - MaybeNotifyUnlocked(); } gfx::SurfaceFormat @@ -1001,7 +966,6 @@ BufferTextureHost::MaybeUpload(nsIntRegion *aRegion) // We just did the texture upload, the content side can now freely write // into the shared buffer. ReadUnlock(); - MaybeNotifyUnlocked(); } // We no longer have an invalid region. @@ -1031,9 +995,7 @@ BufferTextureHost::Upload(nsIntRegion *aRegion) return false; } if (!mHasIntermediateBuffer && EnsureWrappingTextureSource()) { - if (!mFirstSource || !mFirstSource->IsDirectMap()) { - return true; - } + return true; } if (mFormat == gfx::SurfaceFormat::UNKNOWN) { @@ -1315,12 +1277,9 @@ TextureParent::Destroy() return; } - if (mTextureHost->mReadLocked) { - // ReadUnlock here to make sure the ReadLock's shmem does not outlive the - // protocol that created it. - mTextureHost->ReadUnlock(); - mTextureHost->MaybeNotifyUnlocked(); - } + // ReadUnlock here to make sure the ReadLock's shmem does not outlive the + // protocol that created it. + mTextureHost->ReadUnlock(); if (mTextureHost->GetFlags() & TextureFlags::DEALLOCATE_CLIENT) { mTextureHost->ForgetSharedData(); diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index 086ccda48579..66f88efc4741 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -183,16 +183,6 @@ public: int NumCompositableRefs() const { return mCompositableCount; } - // Some texture sources could wrap the cpu buffer to gpu directly. Then, - // we could get better performance of texture uploading. - virtual bool IsDirectMap() { return false; } - // The direct-map cpu buffer should be alive when gpu uses it. And it - // should not be updated while gpu reads it. This Sync() function - // implements this synchronized behavior by allowing us to check if - // the GPU is done with the texture, and block on it if aBlocking is - // true. - virtual bool Sync(bool aBlocking) { return true; } - protected: RefPtr mNextSibling; @@ -672,15 +662,11 @@ public: */ virtual MacIOSurface* GetMacIOSurface() { return nullptr; } - virtual bool IsDirectMap() { return false; } - protected: - virtual void ReadUnlock(); + void ReadUnlock(); void RecycleTexture(TextureFlags aFlags); - virtual void MaybeNotifyUnlocked() {} - virtual void UpdatedInternal(const nsIntRegion *Region) {} /** @@ -782,11 +768,6 @@ public: wr::ImageRendering aFilter, const Range& aImageKeys) override; - virtual void ReadUnlock() override; - virtual bool IsDirectMap() override { return mFirstSource && mFirstSource->IsDirectMap(); }; - - bool CanUnlock() { return !mFirstSource || mFirstSource->Sync(false); } - protected: bool Upload(nsIntRegion *aRegion = nullptr); bool UploadIfNeeded(); @@ -794,8 +775,6 @@ protected: bool EnsureWrappingTextureSource(); virtual void UpdatedInternal(const nsIntRegion* aRegion = nullptr) override; - virtual void MaybeNotifyUnlocked() override; - BufferDescriptor mDescriptor; RefPtr mCompositor; diff --git a/gfx/layers/composite/TiledContentHost.cpp b/gfx/layers/composite/TiledContentHost.cpp index 25b30413b3f6..2e00f2ce9404 100644 --- a/gfx/layers/composite/TiledContentHost.cpp +++ b/gfx/layers/composite/TiledContentHost.cpp @@ -15,9 +15,6 @@ #include "mozilla/layers/Effects.h" // for TexturedEffect, Effect, etc #include "mozilla/layers/LayerMetricsWrapper.h" // for LayerMetricsWrapper #include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL -#ifdef XP_DARWIN -#include "mozilla/layers/TextureSync.h" // for TextureSync -#endif #include "nsAString.h" #include "nsDebug.h" // for NS_WARNING #include "nsPoint.h" // for IntPoint @@ -301,9 +298,6 @@ TiledLayerBufferComposite::UseTiles(const SurfaceDescriptorTiles& aTiles, TextureSourceRecycler oldRetainedTiles(std::move(mRetainedTiles)); mRetainedTiles.SetLength(tileDescriptors.Length()); - AutoTArray lockedTextureSerials; - base::ProcessId lockedTexturePid = 0; - // Step 1, deserialize the incoming set of tiles into mRetainedTiles, and attempt // to recycle the TextureSource for any repeated tiles. // @@ -328,15 +322,6 @@ TiledLayerBufferComposite::UseTiles(const SurfaceDescriptorTiles& aTiles, tile.mTextureHost = TextureHost::AsTextureHost(texturedDesc.textureParent()); if (texturedDesc.readLocked()) { tile.mTextureHost->SetReadLocked(); - auto actor = tile.mTextureHost->GetIPDLActor(); - if (actor && tile.mTextureHost->IsDirectMap()) { - lockedTextureSerials.AppendElement(TextureHost::GetTextureSerial(actor)); - - if (lockedTexturePid) { - MOZ_ASSERT(lockedTexturePid == actor->OtherPid()); - } - lockedTexturePid = actor->OtherPid(); - } } if (texturedDesc.textureOnWhite().type() == MaybeTexture::TPTextureParent) { @@ -345,10 +330,6 @@ TiledLayerBufferComposite::UseTiles(const SurfaceDescriptorTiles& aTiles, ); if (texturedDesc.readLockedOnWhite()) { tile.mTextureHostOnWhite->SetReadLocked(); - auto actor = tile.mTextureHostOnWhite->GetIPDLActor(); - if (actor && tile.mTextureHostOnWhite->IsDirectMap()) { - lockedTextureSerials.AppendElement(TextureHost::GetTextureSerial(actor)); - } } } @@ -373,12 +354,6 @@ TiledLayerBufferComposite::UseTiles(const SurfaceDescriptorTiles& aTiles, } } - #ifdef XP_DARWIN - if (lockedTextureSerials.Length() > 0) { - TextureSync::SetTexturesLocked(lockedTexturePid, lockedTextureSerials); - } - #endif - // Step 2, attempt to recycle unused texture sources from the old tile set into new tiles. // // For gralloc, binding a new TextureHost to the existing TextureSource is the fastest way diff --git a/gfx/layers/ipc/CompositorBridgeChild.cpp b/gfx/layers/ipc/CompositorBridgeChild.cpp index a08baa6d27ac..7740509259ff 100644 --- a/gfx/layers/ipc/CompositorBridgeChild.cpp +++ b/gfx/layers/ipc/CompositorBridgeChild.cpp @@ -936,7 +936,6 @@ CompositorBridgeChild::GetTexturePool(KnowsCompositor* aAllocator, mTexturePools.AppendElement( new TextureClientPool(aAllocator->GetCompositorBackendType(), - aAllocator->SupportsTextureDirectMapping(), aAllocator->GetMaxTextureSize(), aFormat, gfx::gfxVars::TileSize(), diff --git a/gfx/layers/ipc/KnowsCompositor.h b/gfx/layers/ipc/KnowsCompositor.h index 11bea2d78c27..6d72841bfcc2 100644 --- a/gfx/layers/ipc/KnowsCompositor.h +++ b/gfx/layers/ipc/KnowsCompositor.h @@ -102,11 +102,6 @@ public: return mTextureFactoryIdentifier.mSupportsComponentAlpha; } - bool SupportsTextureDirectMapping() const - { - return mTextureFactoryIdentifier.mSupportsTextureDirectMapping; - } - bool SupportsD3D11() const { return GetCompositorBackendType() == layers::LayersBackend::LAYERS_D3D11 || diff --git a/gfx/layers/ipc/LayersMessageUtils.h b/gfx/layers/ipc/LayersMessageUtils.h index b58577e63d83..625bd8253148 100644 --- a/gfx/layers/ipc/LayersMessageUtils.h +++ b/gfx/layers/ipc/LayersMessageUtils.h @@ -335,7 +335,6 @@ struct ParamTraits WriteParam(aMsg, aParam.mParentBackend); WriteParam(aMsg, aParam.mParentProcessType); WriteParam(aMsg, aParam.mMaxTextureSize); - WriteParam(aMsg, aParam.mSupportsTextureDirectMapping); WriteParam(aMsg, aParam.mCompositorUseANGLE); WriteParam(aMsg, aParam.mSupportsTextureBlitting); WriteParam(aMsg, aParam.mSupportsPartialUploads); @@ -349,7 +348,6 @@ struct ParamTraits bool result = ReadParam(aMsg, aIter, &aResult->mParentBackend) && ReadParam(aMsg, aIter, &aResult->mParentProcessType) && ReadParam(aMsg, aIter, &aResult->mMaxTextureSize) && - ReadParam(aMsg, aIter, &aResult->mSupportsTextureDirectMapping) && ReadParam(aMsg, aIter, &aResult->mCompositorUseANGLE) && ReadParam(aMsg, aIter, &aResult->mSupportsTextureBlitting) && ReadParam(aMsg, aIter, &aResult->mSupportsPartialUploads) && diff --git a/gfx/layers/ipc/ShadowLayers.cpp b/gfx/layers/ipc/ShadowLayers.cpp index f36bba8a0760..042ff72ccfd9 100644 --- a/gfx/layers/ipc/ShadowLayers.cpp +++ b/gfx/layers/ipc/ShadowLayers.cpp @@ -32,9 +32,6 @@ #include "mozilla/layers/LayerTransactionChild.h" #include "mozilla/layers/PTextureChild.h" #include "mozilla/layers/SyncObject.h" -#ifdef XP_DARWIN -#include "mozilla/layers/TextureSync.h" -#endif #include "ShadowLayerUtils.h" #include "mozilla/layers/TextureClient.h" // for TextureClient #include "mozilla/mozalloc.h" // for operator new, etc @@ -808,38 +805,6 @@ ShadowLayerForwarder::SetLayerObserverEpoch(uint64_t aLayerObserverEpoch) Unused << mShadowManager->SendSetLayerObserverEpoch(aLayerObserverEpoch); } -void -ShadowLayerForwarder::UpdateTextureLocks() -{ -#ifdef XP_DARWIN - if (!IPCOpen()) { - return; - } - - auto compositorBridge = GetCompositorBridgeChild(); - if (compositorBridge) { - auto pid = compositorBridge->OtherPid(); - TextureSync::UpdateTextureLocks(pid); - } -#endif -} - -void -ShadowLayerForwarder::SyncTextures(const nsTArray& aSerials) -{ -#ifdef XP_DARWIN - if (!IPCOpen()) { - return; - } - - auto compositorBridge = GetCompositorBridgeChild(); - if (compositorBridge) { - auto pid = compositorBridge->OtherPid(); - TextureSync::WaitForTextures(pid, aSerials); - } -#endif -} - void ShadowLayerForwarder::ReleaseLayer(const LayerHandle& aHandle) { diff --git a/gfx/layers/ipc/ShadowLayers.h b/gfx/layers/ipc/ShadowLayers.h index 472309a60874..5859c64e62a9 100644 --- a/gfx/layers/ipc/ShadowLayers.h +++ b/gfx/layers/ipc/ShadowLayers.h @@ -361,9 +361,6 @@ public: virtual void UpdateFwdTransactionId() override; virtual uint64_t GetFwdTransactionId() override; - void UpdateTextureLocks(); - void SyncTextures(const nsTArray& aSerials); - void ReleaseLayer(const LayerHandle& aHandle); bool InForwarderThread() override { diff --git a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp index 04901e11dbe3..a7f8aad10c76 100644 --- a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp +++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp @@ -115,11 +115,8 @@ SharedPlanarYCbCrImage::AdoptData(const Data& aData) uint32_t crOffset = aData.mCrChannel - base; auto fwd = mCompositable->GetForwarder(); - bool supportsTextureDirectMapping = fwd->SupportsTextureDirectMapping() && - std::max(mSize.width, mSize.height) <= fwd->GetMaxTextureSize(); bool hasIntermediateBuffer = ComputeHasIntermediateBuffer( - gfx::SurfaceFormat::YUV, fwd->GetCompositorBackendType(), - supportsTextureDirectMapping); + gfx::SurfaceFormat::YUV, fwd->GetCompositorBackendType()); static_cast(mTextureClient->GetInternalData()) ->SetDesciptor(YCbCrDescriptor(aData.mYSize, diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 0cf9f0a938f3..6f6075345198 100755 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -274,7 +274,6 @@ if CONFIG['MOZ_X11']: if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': EXPORTS.mozilla.layers += [ 'opengl/GLManager.h', - 'TextureSync.h', ] EXPORTS += [ 'MacIOSurfaceHelpers.h', @@ -282,7 +281,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': ] UNIFIED_SOURCES += [ 'opengl/GLManager.cpp', - 'TextureSync.cpp', ] SOURCES += [ 'ipc/ShadowLayerUtilsMac.cpp', diff --git a/gfx/layers/opengl/CompositorOGL.cpp b/gfx/layers/opengl/CompositorOGL.cpp index c9aaba2204e3..4904f02bbe2e 100644 --- a/gfx/layers/opengl/CompositorOGL.cpp +++ b/gfx/layers/opengl/CompositorOGL.cpp @@ -25,16 +25,11 @@ #include "mozilla/gfx/Matrix.h" // for Matrix4x4, Matrix #include "mozilla/gfx/Triangle.h" // for Triangle #include "mozilla/gfx/gfxVars.h" // for gfxVars -#include "mozilla/layers/ImageDataSerializer.h" #include "mozilla/layers/LayerManagerComposite.h" // for LayerComposite, etc #include "mozilla/layers/CompositingRenderTargetOGL.h" #include "mozilla/layers/Effects.h" // for EffectChain, TexturedEffect, etc #include "mozilla/layers/TextureHost.h" // for TextureSource, etc #include "mozilla/layers/TextureHostOGL.h" // for TextureSourceOGL, etc -#include "mozilla/layers/PTextureParent.h" // for OtherPid() on PTextureParent -#ifdef XP_DARWIN -#include "mozilla/layers/TextureSync.h" // for TextureSync::etc. -#endif #include "mozilla/mozalloc.h" // for operator delete, etc #include "nsAppRunner.h" #include "nsAString.h" @@ -187,17 +182,11 @@ CompositorOGL::CompositorOGL(CompositorBridgeParent* aParent, , mViewportSize(0, 0) , mCurrentProgram(nullptr) { -#ifdef XP_DARWIN - TextureSync::RegisterTextureSourceProvider(this); -#endif MOZ_COUNT_CTOR(CompositorOGL); } CompositorOGL::~CompositorOGL() { -#ifdef XP_DARWIN - TextureSync::UnregisterTextureSourceProvider(this); -#endif MOZ_COUNT_DTOR(CompositorOGL); Destroy(); } @@ -256,8 +245,6 @@ CompositorOGL::Destroy() mTexturePool = nullptr; } - mMaybeUnlockBeforeNextComposition.Clear(); - if (!mDestroyed) { mDestroyed = true; CleanupResources(); @@ -1886,93 +1873,6 @@ CompositorOGL::CreateDataTextureSource(TextureFlags aFlags) return MakeAndAddRef(this, aFlags); } -already_AddRefed -CompositorOGL::CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) -{ - BufferTextureHost* bufferTexture = aTexture->AsBufferTextureHost(); - MOZ_ASSERT(bufferTexture); - - if (!bufferTexture) { - return nullptr; - } - - uint8_t* buf = bufferTexture->GetBuffer(); - const BufferDescriptor& buffDesc = bufferTexture->GetBufferDescriptor(); - const YCbCrDescriptor& desc = buffDesc.get_YCbCrDescriptor(); - - RefPtr tempY = - gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetYChannel(buf, desc), - desc.yStride(), - desc.ySize(), - SurfaceFormatForAlphaBitDepth(desc.bitDepth())); - if (!tempY) { - return nullptr; - } - RefPtr tempCb = - gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetCbChannel(buf, desc), - desc.cbCrStride(), - desc.cbCrSize(), - SurfaceFormatForAlphaBitDepth(desc.bitDepth())); - if (!tempCb) { - return nullptr; - } - RefPtr tempCr = - gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetCrChannel(buf, desc), - desc.cbCrStride(), - desc.cbCrSize(), - SurfaceFormatForAlphaBitDepth(desc.bitDepth())); - if (!tempCr) { - return nullptr; - } - - RefPtr srcY = new DirectMapTextureSource(this, tempY); - RefPtr srcU = new DirectMapTextureSource(this, tempCb); - RefPtr srcV = new DirectMapTextureSource(this, tempCr); - - srcY->SetNextSibling(srcU); - srcU->SetNextSibling(srcV); - - return srcY.forget(); -} - -#ifdef XP_DARWIN -void -CompositorOGL::MaybeUnlockBeforeNextComposition(TextureHost* aTextureHost) -{ - auto bufferTexture = aTextureHost->AsBufferTextureHost(); - if (bufferTexture) { - mMaybeUnlockBeforeNextComposition.AppendElement(bufferTexture); - } -} - -void -CompositorOGL::TryUnlockTextures() -{ - nsClassHashtable> texturesIdsToUnlockByPid; - for (auto& texture : mMaybeUnlockBeforeNextComposition) { - if (texture->IsDirectMap() && texture->CanUnlock()) { - texture->ReadUnlock(); - auto actor = texture->GetIPDLActor(); - if (actor) { - base::ProcessId pid = actor->OtherPid(); - nsTArray* textureIds = texturesIdsToUnlockByPid.LookupOrAdd(pid); - textureIds->AppendElement(TextureHost::GetTextureSerial(actor)); - } - } - } - mMaybeUnlockBeforeNextComposition.Clear(); - for (auto it = texturesIdsToUnlockByPid.ConstIter(); !it.Done(); it.Next()) { - TextureSync::SetTexturesUnlocked(it.Key(), *it.UserData()); - } -} -#endif - -already_AddRefed -CompositorOGL::CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface) -{ - return MakeAndAddRef(this, aSurface); -} - bool CompositorOGL::SupportsPartialTextureUpdate() { @@ -2009,6 +1909,8 @@ CompositorOGL::BlitTextureImageHelper() return mBlitTextureImageHelper.get(); } + + GLuint CompositorOGL::GetTemporaryTexture(GLenum aTarget, GLenum aUnit) { @@ -2018,22 +1920,6 @@ CompositorOGL::GetTemporaryTexture(GLenum aTarget, GLenum aUnit) return mTexturePool->GetTexture(aTarget, aUnit); } -bool -CompositorOGL::SupportsTextureDirectMapping() -{ - if (!gfxPrefs::AllowTextureDirectMapping()) { - return false; - } - - if (mGLContext) { - mGLContext->MakeCurrent(); - return mGLContext->IsExtensionSupported(gl::GLContext::APPLE_client_storage) && - mGLContext->IsExtensionSupported(gl::GLContext::APPLE_texture_range); - } - - return false; -} - GLuint PerUnitTexturePoolOGL::GetTexture(GLenum aTarget, GLenum aTextureUnit) { diff --git a/gfx/layers/opengl/CompositorOGL.h b/gfx/layers/opengl/CompositorOGL.h index 8af60f5b1c3f..9c8df4621e32 100644 --- a/gfx/layers/opengl/CompositorOGL.h +++ b/gfx/layers/opengl/CompositorOGL.h @@ -44,7 +44,6 @@ class CompositingRenderTargetOGL; class DataTextureSource; class GLManagerCompositor; class TextureSource; -class BufferTextureHost; struct Effect; struct EffectChain; class GLBlitTextureImageHelper; @@ -132,12 +131,6 @@ public: virtual already_AddRefed CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override; - virtual already_AddRefed - CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) override; - - virtual already_AddRefed - CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface) override; - virtual bool Initialize(nsCString* const out_failureReason) override; virtual void Destroy() override; @@ -148,7 +141,6 @@ public: TextureFactoryIdentifier(LayersBackend::LAYERS_OPENGL, XRE_GetProcessType(), GetMaxTextureSize(), - SupportsTextureDirectMapping(), false, mFBOTextureTarget == LOCAL_GL_TEXTURE_2D, SupportsPartialTextureUpdate()); @@ -236,11 +228,6 @@ public: GLContext* gl() const { return mGLContext; } GLContext* GetGLContext() const override { return mGLContext; } -#ifdef XP_DARWIN - virtual void MaybeUnlockBeforeNextComposition(TextureHost* aTextureHost) override; - virtual void TryUnlockTextures() override; -#endif - /** * Clear the program state. This must be called * before operating on the GLContext directly. */ @@ -286,18 +273,12 @@ private: void PrepareViewport(CompositingRenderTargetOGL *aRenderTarget); - bool SupportsTextureDirectMapping(); - /** Widget associated with this compositor */ LayoutDeviceIntSize mWidgetSize; RefPtr mGLContext; UniquePtr mBlitTextureImageHelper; gfx::Matrix4x4 mProjMatrix; -#ifdef XP_DARWIN - nsTArray> mMaybeUnlockBeforeNextComposition; -#endif - /** The size of the surface we are rendering to */ gfx::IntSize mSurfaceSize; diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp index 03759655f579..fb4ee7d4b53c 100644 --- a/gfx/layers/opengl/TextureHostOGL.cpp +++ b/gfx/layers/opengl/TextureHostOGL.cpp @@ -242,12 +242,14 @@ GLTextureSource::GLTextureSource(TextureSourceProvider* aProvider, GLuint aTextureHandle, GLenum aTarget, gfx::IntSize aSize, - gfx::SurfaceFormat aFormat) + gfx::SurfaceFormat aFormat, + bool aExternallyOwned) : mGL(aProvider->GetGLContext()) , mTextureHandle(aTextureHandle) , mTextureTarget(aTarget) , mSize(aSize) , mFormat(aFormat) + , mExternallyOwned(aExternallyOwned) { MOZ_COUNT_CTOR(GLTextureSource); } @@ -255,13 +257,17 @@ GLTextureSource::GLTextureSource(TextureSourceProvider* aProvider, GLTextureSource::~GLTextureSource() { MOZ_COUNT_DTOR(GLTextureSource); - DeleteTextureHandle(); + if (!mExternallyOwned) { + DeleteTextureHandle(); + } } void GLTextureSource::DeallocateDeviceData() { - DeleteTextureHandle(); + if (!mExternallyOwned) { + DeleteTextureHandle(); + } } void @@ -309,98 +315,6 @@ GLTextureSource::IsValid() const return !!gl() && mTextureHandle != 0; } -//////////////////////////////////////////////////////////////////////// -// DirectMapTextureSource - -DirectMapTextureSource::DirectMapTextureSource(TextureSourceProvider* aProvider, - gfx::DataSourceSurface* aSurface) - : GLTextureSource(aProvider, - 0, - LOCAL_GL_TEXTURE_2D, - aSurface->GetSize(), - aSurface->GetFormat()) -{ - MOZ_ASSERT(aSurface); - - UpdateInternal(aSurface, nullptr, nullptr, true); -} - -bool -DirectMapTextureSource::Update(gfx::DataSourceSurface* aSurface, - nsIntRegion* aDestRegion, - gfx::IntPoint* aSrcOffset) -{ - if (!aSurface) { - return false; - } - - return UpdateInternal(aSurface, aDestRegion, aSrcOffset, false); -} - -bool -DirectMapTextureSource::Sync(bool aBlocking) -{ - gl()->MakeCurrent(); - if (!gl()->IsDestroyed()) { - if (aBlocking) { - gl()->fFinishObjectAPPLE(LOCAL_GL_TEXTURE, mTextureHandle); - } else { - return gl()->fTestObjectAPPLE(LOCAL_GL_TEXTURE, mTextureHandle); - } - } - return true; -} - -bool -DirectMapTextureSource::UpdateInternal(gfx::DataSourceSurface* aSurface, - nsIntRegion* aDestRegion, - gfx::IntPoint* aSrcOffset, - bool aInit) -{ - gl()->MakeCurrent(); - - if (aInit) { - gl()->fGenTextures(1, &mTextureHandle); - gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle); - - gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, - LOCAL_GL_TEXTURE_STORAGE_HINT_APPLE, - LOCAL_GL_STORAGE_CACHED_APPLE); - - gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, - LOCAL_GL_TEXTURE_WRAP_S, - LOCAL_GL_CLAMP_TO_EDGE); - gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, - LOCAL_GL_TEXTURE_WRAP_T, - LOCAL_GL_CLAMP_TO_EDGE); - } - - MOZ_ASSERT(mTextureHandle); - - // APPLE_client_storage - gl()->fPixelStorei(LOCAL_GL_UNPACK_CLIENT_STORAGE_APPLE, LOCAL_GL_TRUE); - - nsIntRegion destRegion = aDestRegion ? *aDestRegion - : IntRect(0, 0, - aSurface->GetSize().width, - aSurface->GetSize().height); - gfx::IntPoint srcPoint = aSrcOffset ? *aSrcOffset - : gfx::IntPoint(0, 0); - mFormat = gl::UploadSurfaceToTexture(gl(), - aSurface, - destRegion, - mTextureHandle, - aSurface->GetSize(), - nullptr, - aInit, - srcPoint, - LOCAL_GL_TEXTURE0, - LOCAL_GL_TEXTURE_2D); - - gl()->fPixelStorei(LOCAL_GL_UNPACK_CLIENT_STORAGE_APPLE, LOCAL_GL_FALSE); - return true; -} - //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // SurfaceTextureHost @@ -850,7 +764,8 @@ GLTextureHost::Lock() mTexture, mTarget, mSize, - format); + format, + false /* owned by the client */); } return true; diff --git a/gfx/layers/opengl/TextureHostOGL.h b/gfx/layers/opengl/TextureHostOGL.h index f121ce9adbcf..22801857e1d0 100644 --- a/gfx/layers/opengl/TextureHostOGL.h +++ b/gfx/layers/opengl/TextureHostOGL.h @@ -224,7 +224,7 @@ protected: * * The shared texture handle is owned by the TextureHost. */ -class GLTextureSource : public DataTextureSource +class GLTextureSource : public TextureSource , public TextureSourceOGL { public: @@ -232,9 +232,10 @@ public: GLuint aTextureHandle, GLenum aTarget, gfx::IntSize aSize, - gfx::SurfaceFormat aFormat); + gfx::SurfaceFormat aFormat, + bool aExternallyOwned = false); - virtual ~GLTextureSource(); + ~GLTextureSource(); virtual const char* Name() const override { return "GLTextureSource"; } @@ -269,13 +270,6 @@ public: return mGL; } - virtual bool Update(gfx::DataSourceSurface* aSurface, - nsIntRegion* aDestRegion = nullptr, - gfx::IntPoint* aSrcOffset = nullptr) override - { - return false; - } - protected: void DeleteTextureHandle(); @@ -285,35 +279,9 @@ protected: GLenum mTextureTarget; gfx::IntSize mSize; gfx::SurfaceFormat mFormat; -}; - -// This texture source try to wrap "aSurface" in ctor for compositor direct -// access. Since we can't know the timing for gpu buffer access, the surface -// should be alive until the ~ClientStorageTextureSource(). And if we try to -// update the surface we mapped before, we need to call Sync() to make sure -// the surface is not used by compositor. -class DirectMapTextureSource : public GLTextureSource -{ -public: - DirectMapTextureSource(TextureSourceProvider* aProvider, - gfx::DataSourceSurface* aSurface); - - virtual bool Update(gfx::DataSourceSurface* aSurface, - nsIntRegion* aDestRegion = nullptr, - gfx::IntPoint* aSrcOffset = nullptr) override; - - virtual bool IsDirectMap() override { return true; } - - // If aBlocking is false, check if this texture is no longer being used - // by the GPU - if aBlocking is true, this will block until the GPU is - // done with it. - virtual bool Sync(bool aBlocking) override; - -private: - bool UpdateInternal(gfx::DataSourceSurface* aSurface, - nsIntRegion* aDestRegion, - gfx::IntPoint* aSrcOffset, - bool aInit); + // If the texture is externally owned, the gl handle will not be deleted + // in the destructor. + bool mExternallyOwned; }; class GLTextureHost : public TextureHost diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index e877e462b4d0..e9cd175844bc 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -513,12 +513,6 @@ private: DECL_GFX_PREF(Once, "gfx.use-mutex-on-present", UseMutexOnPresent, bool, false); DECL_GFX_PREF(Once, "gfx.use-surfacetexture-textures", UseSurfaceTextureTextures, bool, false); -#if defined(RELEASE_OR_BETA) - DECL_GFX_PREF(Once, "gfx.allow-texture-direct-mapping", AllowTextureDirectMapping, bool, false); -#else - DECL_GFX_PREF(Once, "gfx.allow-texture-direct-mapping", AllowTextureDirectMapping, bool, true); -#endif - DECL_GFX_PREF(Live, "gfx.vsync.collect-scroll-transforms", CollectScrollTransforms, bool, false); DECL_GFX_PREF(Once, "gfx.vsync.compositor.unobserve-count", CompositorUnobserveCount, int32_t, 10); diff --git a/ipc/glue/SharedMemoryBasic_mach.h b/ipc/glue/SharedMemoryBasic_mach.h index 4ebe1e6673cb..8613ebaab56a 100644 --- a/ipc/glue/SharedMemoryBasic_mach.h +++ b/ipc/glue/SharedMemoryBasic_mach.h @@ -12,7 +12,6 @@ #include "SharedMemory.h" #include -#include "chrome/common/mach_ipc_mac.h" #ifdef FUZZING #include "SharedMemoryFuzzer.h" @@ -29,27 +28,6 @@ class ReceivePort; namespace mozilla { namespace ipc { -enum { - kGetPortsMsg = 1, - kSharePortsMsg, - kWaitForTexturesMsg, - kUpdateTextureLocksMsg, - kReturnIdMsg, - kReturnWaitForTexturesMsg, - kReturnPortsMsg, - kShutdownMsg, - kCleanupMsg, -}; - -struct MemoryPorts { - MachPortSender* mSender; - ReceivePort* mReceiver; - - MemoryPorts() = default; - MemoryPorts(MachPortSender* sender, ReceivePort* receiver) - : mSender(sender), mReceiver(receiver) {} -}; - class SharedMemoryBasic final : public SharedMemoryCommon { public: @@ -64,10 +42,6 @@ public: static void Shutdown(); - static bool SendMachMessage(pid_t pid, - MachSendMessage& message, - MachReceiveMessage* response); - SharedMemoryBasic(); virtual bool SetHandle(const Handle& aHandle, OpenRights aRights) override; diff --git a/ipc/glue/SharedMemoryBasic_mach.mm b/ipc/glue/SharedMemoryBasic_mach.mm index 066f8cc2680c..03baf585fabb 100644 --- a/ipc/glue/SharedMemoryBasic_mach.mm +++ b/ipc/glue/SharedMemoryBasic_mach.mm @@ -22,11 +22,11 @@ #include #include #include "SharedMemoryBasic.h" +#include "chrome/common/mach_ipc_mac.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/Printf.h" #include "mozilla/StaticMutex.h" -#include "mozilla/layers/TextureSync.h" #ifdef DEBUG #define LOG_ERROR(str, args...) \ @@ -82,10 +82,29 @@ namespace mozilla { namespace ipc { +struct MemoryPorts { + MachPortSender* mSender; + ReceivePort* mReceiver; + + MemoryPorts() = default; + MemoryPorts(MachPortSender* sender, ReceivePort* receiver) + : mSender(sender), mReceiver(receiver) {} +}; + // Protects gMemoryCommPorts and gThreads. static StaticMutex gMutex; + static std::map gMemoryCommPorts; +enum { + kGetPortsMsg = 1, + kSharePortsMsg, + kReturnIdMsg, + kReturnPortsMsg, + kShutdownMsg, + kCleanupMsg, +}; + const int kTimeout = 1000; const int kLongTimeout = 60 * kTimeout; @@ -135,7 +154,6 @@ SetupMachMemory(pid_t pid, pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - int err = pthread_create(&thread, &attr, PortServerThread, listen_ports); if (err) { LOG_ERROR("pthread_create failed with %x\n", err); @@ -387,36 +405,30 @@ PortServerThread(void *argument) delete ports; return nullptr; } - if (rmsg.GetMessageID() == kWaitForTexturesMsg) { - layers::TextureSync::HandleWaitForTexturesMessage(&rmsg, ports); - } else if (rmsg.GetMessageID() == kUpdateTextureLocksMsg) { - layers::TextureSync::DispatchCheckTexturesForUnlock(); - } else { - StaticMutexAutoLock smal(gMutex); - switch (rmsg.GetMessageID()) { - case kSharePortsMsg: - HandleSharePortsMessage(&rmsg, ports); - break; - case kGetPortsMsg: - HandleGetPortsMessage(&rmsg, ports); - break; - case kCleanupMsg: - if (gParentPid == 0) { - LOG_ERROR("Cleanup message not valid for parent process"); - continue; - } + StaticMutexAutoLock smal(gMutex); + switch (rmsg.GetMessageID()) { + case kSharePortsMsg: + HandleSharePortsMessage(&rmsg, ports); + break; + case kGetPortsMsg: + HandleGetPortsMessage(&rmsg, ports); + break; + case kCleanupMsg: + if (gParentPid == 0) { + LOG_ERROR("Cleanup message not valid for parent process"); + continue; + } - pid_t* pid; - if (rmsg.GetDataLength() != sizeof(pid_t)) { - LOG_ERROR("Improperly formatted message\n"); - continue; - } - pid = reinterpret_cast(rmsg.GetData()); - SharedMemoryBasic::CleanupForPid(*pid); - break; - default: - LOG_ERROR("Unknown message\n"); + pid_t* pid; + if (rmsg.GetDataLength() != sizeof(pid_t)) { + LOG_ERROR("Improperly formatted message\n"); + continue; } + pid = reinterpret_cast(rmsg.GetData()); + SharedMemoryBasic::CleanupForPid(*pid); + break; + default: + LOG_ERROR("Unknown message\n"); } } } @@ -438,8 +450,6 @@ SharedMemoryBasic::Shutdown() { StaticMutexAutoLock smal(gMutex); - layers::TextureSync::Shutdown(); - for (auto& thread : gThreads) { MachSendMessage shutdownMsg(kShutdownMsg); thread.second.mPorts->mReceiver->SendMessageToSelf(shutdownMsg, kTimeout); @@ -459,9 +469,6 @@ SharedMemoryBasic::CleanupForPid(pid_t pid) if (gThreads.find(pid) == gThreads.end()) { return; } - - layers::TextureSync::CleanupForPid(pid); - const ListeningThread& listeningThread = gThreads[pid]; MachSendMessage shutdownMsg(kShutdownMsg); kern_return_t ret = listeningThread.mPorts->mReceiver->SendMessageToSelf(shutdownMsg, kTimeout); @@ -486,40 +493,6 @@ SharedMemoryBasic::CleanupForPid(pid_t pid) gMemoryCommPorts.erase(pid); } -bool -SharedMemoryBasic::SendMachMessage(pid_t pid, - MachSendMessage& message, - MachReceiveMessage* response) -{ - StaticMutexAutoLock smal(gMutex); - ipc::MemoryPorts* ports = GetMemoryPortsForPid(pid); - if (!ports) { - LOG_ERROR("Unable to get ports for process.\n"); - return false; - } - - kern_return_t err = ports->mSender->SendMessage(message, kTimeout); - if (err != KERN_SUCCESS) { - LOG_ERROR("Failed updating texture locks.\n"); - return false; - } - - if (response) { - err = ports->mReceiver->WaitForMessage(response, kTimeout); - if (err != KERN_SUCCESS) { - LOG_ERROR("short timeout didn't get an id %s %x\n", mach_error_string(err), err); - err = ports->mReceiver->WaitForMessage(response, kLongTimeout); - - if (err != KERN_SUCCESS) { - LOG_ERROR("long timeout didn't get an id %s %x\n", mach_error_string(err), err); - return false; - } - } - } - - return true; -} - SharedMemoryBasic::SharedMemoryBasic() : mPort(MACH_PORT_NULL) , mMemory(nullptr) diff --git a/xpcom/base/StaticMonitor.h b/xpcom/base/StaticMonitor.h deleted file mode 100644 index 1912d348775c..000000000000 --- a/xpcom/base/StaticMonitor.h +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_StaticMonitor_h -#define mozilla_StaticMonitor_h - -#include "mozilla/Atomics.h" -#include "mozilla/CondVar.h" - -namespace mozilla { - -class MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS StaticMonitor -{ -public: - // In debug builds, check that mMutex is initialized for us as we expect by - // the compiler. In non-debug builds, don't declare a constructor so that - // the compiler can see that the constructor is trivial. -#ifdef DEBUG - StaticMonitor() - { - MOZ_ASSERT(!mMutex); - } -#endif - - void Lock() - { - Mutex()->Lock(); - } - - void Unlock() - { - Mutex()->Unlock(); - } - - void Wait() { CondVar()->Wait(); } - CVStatus Wait(TimeDuration aDuration) { return CondVar()->Wait(aDuration); } - - nsresult Notify() { return CondVar()->Notify(); } - nsresult NotifyAll() { return CondVar()->NotifyAll(); } - - void AssertCurrentThreadOwns() - { -#ifdef DEBUG - Mutex()->AssertCurrentThreadOwns(); -#endif - } - -private: - OffTheBooksMutex* Mutex() - { - if (mMutex) { - return mMutex; - } - - OffTheBooksMutex* mutex = new OffTheBooksMutex("StaticMutex"); - if (!mMutex.compareExchange(nullptr, mutex)) { - delete mutex; - } - - return mMutex; - } - - OffTheBooksCondVar* CondVar() - { - if (mCondVar) { - return mCondVar; - } - - OffTheBooksCondVar* condvar = new OffTheBooksCondVar(*Mutex(), "StaticCondVar"); - if (!mCondVar.compareExchange(nullptr, condvar)) { - delete condvar; - } - - return mCondVar; - } - - Atomic mMutex; - Atomic mCondVar; - - - // Disallow copy constructor, but only in debug mode. We only define - // a default constructor in debug mode (see above); if we declared - // this constructor always, the compiler wouldn't generate a trivial - // default constructor for us in non-debug mode. -#ifdef DEBUG - StaticMonitor(const StaticMonitor& aOther); -#endif - - // Disallow these operators. - StaticMonitor& operator=(const StaticMonitor& aRhs); - static void* operator new(size_t) CPP_THROW_NEW; - static void operator delete(void*); -}; - -class MOZ_STACK_CLASS StaticMonitorAutoLock -{ -public: - explicit StaticMonitorAutoLock(StaticMonitor& aMonitor) - : mMonitor(&aMonitor) - { - mMonitor->Lock(); - } - - ~StaticMonitorAutoLock() - { - mMonitor->Unlock(); - } - - void Wait() { mMonitor->Wait(); } - CVStatus Wait(TimeDuration aDuration) { return mMonitor->Wait(aDuration); } - - nsresult Notify() { return mMonitor->Notify(); } - nsresult NotifyAll() { return mMonitor->NotifyAll(); } - -private: - StaticMonitorAutoLock(); - StaticMonitorAutoLock(const StaticMonitorAutoLock&); - StaticMonitorAutoLock& operator=(const StaticMonitorAutoLock&); - static void* operator new(size_t) CPP_THROW_NEW; - - StaticMonitor* mMonitor; -}; - -} // namespace mozilla - -#endif diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build index 9e1fab4471b1..853b7f135e06 100644 --- a/xpcom/base/moz.build +++ b/xpcom/base/moz.build @@ -117,7 +117,6 @@ EXPORTS.mozilla += [ 'NSPRLogModulesParser.h', 'OwningNonNull.h', 'SizeOfState.h', - 'StaticMonitor.h', 'StaticMutex.h', 'StaticPtr.h', ] diff --git a/xpcom/threads/BlockingResourceBase.cpp b/xpcom/threads/BlockingResourceBase.cpp index ca72f16a2ff9..b135a97ddd83 100644 --- a/xpcom/threads/BlockingResourceBase.cpp +++ b/xpcom/threads/BlockingResourceBase.cpp @@ -587,15 +587,15 @@ RecursiveMutex::AssertCurrentThreadIn() // // Debug implementation of CondVar void -OffTheBooksCondVar::Wait() +CondVar::Wait() { - // Forward to the timed version of OffTheBooksCondVar::Wait to avoid code duplication. + // Forward to the timed version of CondVar::Wait to avoid code duplication. CVStatus status = Wait(TimeDuration::Forever()); MOZ_ASSERT(status == CVStatus::NoTimeout); } CVStatus -OffTheBooksCondVar::Wait(TimeDuration aDuration) +CondVar::Wait(TimeDuration aDuration) { AssertCurrentThreadOwnsMutex(); diff --git a/xpcom/threads/CondVar.h b/xpcom/threads/CondVar.h index 348a53a75329..fe9bdec6cb74 100644 --- a/xpcom/threads/CondVar.h +++ b/xpcom/threads/CondVar.h @@ -17,17 +17,17 @@ namespace mozilla { + /** - * Similarly to OffTheBooksMutex, OffTheBooksCondvar is identical to CondVar, - * except that OffTheBooksCondVar doesn't include leak checking. Sometimes - * you want to intentionally "leak" a CondVar until shutdown; in these cases, - * OffTheBooksCondVar is for you. + * CondVar + * Vanilla condition variable. Please don't use this unless you have a + * compelling reason --- Monitor provides a simpler API. */ -class OffTheBooksCondVar : BlockingResourceBase +class CondVar : BlockingResourceBase { public: /** - * OffTheBooksCondVar + * CondVar * * The CALLER owns |aLock|. * @@ -37,18 +37,20 @@ public: * If success, a valid Monitor* which must be destroyed * by Monitor::DestroyMonitor() **/ - OffTheBooksCondVar(OffTheBooksMutex& aLock, const char* aName) + CondVar(Mutex& aLock, const char* aName) : BlockingResourceBase(aName, eCondVar) , mLock(&aLock) { + MOZ_COUNT_CTOR(CondVar); } /** - * ~OffTheBooksCondVar - * Clean up after this OffTheBooksCondVar, but NOT its associated Mutex. + * ~CondVar + * Clean up after this CondVar, but NOT its associated Mutex. **/ - ~OffTheBooksCondVar() + ~CondVar() { + MOZ_COUNT_DTOR(CondVar); } /** @@ -122,38 +124,13 @@ public: #endif // ifdef DEBUG -private: - OffTheBooksCondVar(); - OffTheBooksCondVar(const OffTheBooksCondVar&) = delete; - OffTheBooksCondVar& operator=(const OffTheBooksCondVar&) = delete; - - OffTheBooksMutex* mLock; - detail::ConditionVariableImpl mImpl; -}; - -/** - * CondVar - * Vanilla condition variable. Please don't use this unless you have a - * compelling reason --- Monitor provides a simpler API. - */ -class CondVar : public OffTheBooksCondVar -{ -public: - CondVar(OffTheBooksMutex& aLock, const char* aName) - : OffTheBooksCondVar(aLock, aName) - { - MOZ_COUNT_CTOR(CondVar); - } - - ~CondVar() - { - MOZ_COUNT_DTOR(CondVar); - } - private: CondVar(); - CondVar(const CondVar&); - CondVar& operator=(const CondVar&); + CondVar(const CondVar&) = delete; + CondVar& operator=(const CondVar&) = delete; + + Mutex* mLock; + detail::ConditionVariableImpl mImpl; }; } // namespace mozilla diff --git a/xpcom/threads/Mutex.h b/xpcom/threads/Mutex.h index e7815f8c8012..57babe338768 100644 --- a/xpcom/threads/Mutex.h +++ b/xpcom/threads/Mutex.h @@ -104,7 +104,7 @@ private: OffTheBooksMutex(const OffTheBooksMutex&); OffTheBooksMutex& operator=(const OffTheBooksMutex&); - friend class OffTheBooksCondVar; + friend class CondVar; #ifdef DEBUG PRThread* mOwningThread;