Backed out 8 changesets (bug 1265824) for bustage in /builds/worker/workspace/build/src/gfx/layers/opengl/CompositorOGL.cpp on a CLOSED TREE

Backed out changeset 1099d6f15f9f (bug 1265824)
Backed out changeset b5ba15b1a70f (bug 1265824)
Backed out changeset 51795de4adaf (bug 1265824)
Backed out changeset be68741ff4ce (bug 1265824)
Backed out changeset 4731dc56702d (bug 1265824)
Backed out changeset 984133e9614b (bug 1265824)
Backed out changeset efce316a4425 (bug 1265824)
Backed out changeset 367abce30668 (bug 1265824)
This commit is contained in:
Margareta Eliza Balazs 2018-07-19 09:33:28 +03:00
Родитель aa98d8cbd6
Коммит b1e7992b82
43 изменённых файлов: 115 добавлений и 1253 удалений

Просмотреть файл

@ -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 } },

Просмотреть файл

@ -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

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -17,8 +17,7 @@ namespace mozilla {
namespace layers {
bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat,
LayersBackend aLayersBackend,
bool aSupportsTextureDirectMapping);
LayersBackend aLayersBackend);
class BufferTextureData : public TextureData
{

Просмотреть файл

@ -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;
}
};

Просмотреть файл

@ -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<nsUint32HashKey, nsTArray<uint64_t>> 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<uint64_t>* 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();
}

Просмотреть файл

@ -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();

Просмотреть файл

@ -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 <unordered_set>
#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<nsTArray<TextureSourceProvider*>> gTextureSourceProviders;
static std::map<pid_t, std::unordered_set<uint64_t>> 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<uint64_t>*
GetLockedTextureIdsForProcess(pid_t pid)
{
gTextureLockMonitor.AssertCurrentThreadOwns();
if (gProcessTextureIds.find(pid) == gProcessTextureIds.end()) {
gProcessTextureIds[pid] = std::unordered_set<uint64_t>();
}
return &gProcessTextureIds.at(pid);
}
bool
WaitForTextureIdsToUnlock(pid_t pid, const Span<const uint64_t>& textureIds)
{
{
StaticMonitorAutoLock lock(gTextureLockMonitor);
std::unordered_set<uint64_t>* 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<Runnable> task = NS_NewRunnableFunction(
"CheckTexturesForUnlock",
&CheckTexturesForUnlock);
CompositorThreadHolder::Loop()->PostTask(task.forget());
}
void
TextureSync::HandleWaitForTexturesMessage(MachReceiveMessage* rmsg, ipc::MemoryPorts* ports)
{
WaitForTexturesRequest* req = reinterpret_cast<WaitForTexturesRequest*>(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<uint64_t>(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<TextureSourceProvider*>();
}
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<uint64_t>& textureIds)
{
StaticMonitorAutoLock mal(gTextureLockMonitor);
std::unordered_set<uint64_t>* lockedTextureIds = GetLockedTextureIdsForProcess(pid);
for (uint64_t textureId : textureIds) {
lockedTextureIds->insert(textureId);
}
}
void
TextureSync::SetTexturesUnlocked(pid_t pid, const nsTArray<uint64_t>& textureIds)
{
bool oneErased = false;
{
StaticMonitorAutoLock mal(gTextureLockMonitor);
std::unordered_set<uint64_t>* 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<uint64_t>& textureIds)
{
if (aProcessId == getpid()) {
bool success = WaitForTextureIdsToUnlock(aProcessId, MakeSpan<uint64_t>(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<uint8_t[]> messageData = MakeUnique<uint8_t[]>(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<WaitForTexturesReply*>(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<uint64_t>* lockedTextureIds = GetLockedTextureIdsForProcess(aProcessId);
lockedTextureIds->clear();
}
gTextureLockMonitor.NotifyAll();
}
} // namespace layers
} // namespace mozilla

Просмотреть файл

@ -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<uint64_t>& aTextureIds);
static void SetTexturesLocked(base::ProcessId aProcessId, const nsTArray<uint64_t>& aTextureIds);
static void SetTexturesUnlocked(base::ProcessId aProcessId, const nsTArray<uint64_t>& aTextureIds);
static void Shutdown();
static void CleanupForPid(base::ProcessId aProcessId);
};
} // namespace layers
} // namespace mozilla
#endif

Просмотреть файл

@ -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.

Просмотреть файл

@ -762,14 +762,10 @@ ContentClientRemoteBuffer::CreateBufferInternal(const gfx::IntRect& aRect,
RefPtr<TextureClient> 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;

Просмотреть файл

@ -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<uint64_t, 10> 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) {

Просмотреть файл

@ -156,10 +156,6 @@ private:
nsIntRegion& aRegionToPaint,
BasicTiledLayerPaintData* aPaintData,
bool aIsRepeated);
void MaybeSyncTextures(const nsIntRegion& aPaintRegion,
const TilesPlacement& aNewTiles,
const gfx::IntSize& aScaledTileSize);
};
/**

Просмотреть файл

@ -140,15 +140,6 @@ ClientSingleTiledLayerBuffer::PaintThebes(const nsIntRegion& aNewValidRegion,
mTile.SetTextureAllocator(this);
}
if (mManager->AsShadowForwarder()->SupportsTextureDirectMapping()) {
AutoTArray<uint64_t, 2> 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);

Просмотреть файл

@ -660,9 +660,7 @@ TextureClient::UpdateFromSurface(gfx::SourceSurface* aSurface)
already_AddRefed<TextureClient>
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(),

Просмотреть файл

@ -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,
};
/**

Просмотреть файл

@ -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<TextureClient> 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) {

Просмотреть файл

@ -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

Просмотреть файл

@ -664,32 +664,6 @@ CreateBackBufferTexture(TextureClient* aCurrentTexture,
return texture.forget();
}
void
TileClient::GetSyncTextureSerials(SurfaceMode aMode, nsTArray<uint64_t>& 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);

Просмотреть файл

@ -114,8 +114,6 @@ struct TileClient
CompositableClient::DumpTextureClient(aStream, mFrontBuffer, aCompress);
}
void GetSyncTextureSerials(SurfaceMode aMode, nsTArray<uint64_t>& 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<uint64_t>& aSerials) { return; }
virtual bool SupportsProgressiveUpdate() = 0;
virtual bool ProgressiveUpdate(const nsIntRegion& aValidRegion,

Просмотреть файл

@ -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<uint64_t, 1> 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();

Просмотреть файл

@ -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<TextureSource> 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<wr::ImageKey>& 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<Compositor> mCompositor;

Просмотреть файл

@ -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<uint64_t, 10> 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

Просмотреть файл

@ -936,7 +936,6 @@ CompositorBridgeChild::GetTexturePool(KnowsCompositor* aAllocator,
mTexturePools.AppendElement(
new TextureClientPool(aAllocator->GetCompositorBackendType(),
aAllocator->SupportsTextureDirectMapping(),
aAllocator->GetMaxTextureSize(),
aFormat,
gfx::gfxVars::TileSize(),

Просмотреть файл

@ -102,11 +102,6 @@ public:
return mTextureFactoryIdentifier.mSupportsComponentAlpha;
}
bool SupportsTextureDirectMapping() const
{
return mTextureFactoryIdentifier.mSupportsTextureDirectMapping;
}
bool SupportsD3D11() const
{
return GetCompositorBackendType() == layers::LayersBackend::LAYERS_D3D11 ||

Просмотреть файл

@ -335,7 +335,6 @@ struct ParamTraits<mozilla::layers::TextureFactoryIdentifier>
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<mozilla::layers::TextureFactoryIdentifier>
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) &&

Просмотреть файл

@ -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<uint64_t>& 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)
{

Просмотреть файл

@ -361,9 +361,6 @@ public:
virtual void UpdateFwdTransactionId() override;
virtual uint64_t GetFwdTransactionId() override;
void UpdateTextureLocks();
void SyncTextures(const nsTArray<uint64_t>& aSerials);
void ReleaseLayer(const LayerHandle& aHandle);
bool InForwarderThread() override {

Просмотреть файл

@ -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<BufferTextureData*>(mTextureClient->GetInternalData())
->SetDesciptor(YCbCrDescriptor(aData.mYSize,

Просмотреть файл

@ -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',

Просмотреть файл

@ -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<TextureImageTextureSourceOGL>(this, aFlags);
}
already_AddRefed<DataTextureSource>
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<gfx::DataSourceSurface> tempY =
gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetYChannel(buf, desc),
desc.yStride(),
desc.ySize(),
SurfaceFormatForAlphaBitDepth(desc.bitDepth()));
if (!tempY) {
return nullptr;
}
RefPtr<gfx::DataSourceSurface> tempCb =
gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetCbChannel(buf, desc),
desc.cbCrStride(),
desc.cbCrSize(),
SurfaceFormatForAlphaBitDepth(desc.bitDepth()));
if (!tempCb) {
return nullptr;
}
RefPtr<gfx::DataSourceSurface> tempCr =
gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetCrChannel(buf, desc),
desc.cbCrStride(),
desc.cbCrSize(),
SurfaceFormatForAlphaBitDepth(desc.bitDepth()));
if (!tempCr) {
return nullptr;
}
RefPtr<DirectMapTextureSource> srcY = new DirectMapTextureSource(this, tempY);
RefPtr<DirectMapTextureSource> srcU = new DirectMapTextureSource(this, tempCb);
RefPtr<DirectMapTextureSource> 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<nsUint32HashKey, nsTArray<uint64_t>> texturesIdsToUnlockByPid;
for (auto& texture : mMaybeUnlockBeforeNextComposition) {
if (texture->IsDirectMap() && texture->CanUnlock()) {
texture->ReadUnlock();
auto actor = texture->GetIPDLActor();
if (actor) {
base::ProcessId pid = actor->OtherPid();
nsTArray<uint64_t>* 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<DataTextureSource>
CompositorOGL::CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface)
{
return MakeAndAddRef<DirectMapTextureSource>(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)
{

Просмотреть файл

@ -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<DataTextureSource>
CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
virtual already_AddRefed<DataTextureSource>
CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) override;
virtual already_AddRefed<DataTextureSource>
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<GLContext> mGLContext;
UniquePtr<GLBlitTextureImageHelper> mBlitTextureImageHelper;
gfx::Matrix4x4 mProjMatrix;
#ifdef XP_DARWIN
nsTArray<RefPtr<BufferTextureHost>> mMaybeUnlockBeforeNextComposition;
#endif
/** The size of the surface we are rendering to */
gfx::IntSize mSurfaceSize;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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);

Просмотреть файл

@ -12,7 +12,6 @@
#include "SharedMemory.h"
#include <mach/port.h>
#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<mach_port_t>
{
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;

Просмотреть файл

@ -22,11 +22,11 @@
#include <pthread.h>
#include <unistd.h>
#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<pid_t, MemoryPorts> 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<pid_t*>(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<pid_t*>(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)

Просмотреть файл

@ -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<OffTheBooksMutex*> mMutex;
Atomic<OffTheBooksCondVar*> 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

Просмотреть файл

@ -117,7 +117,6 @@ EXPORTS.mozilla += [
'NSPRLogModulesParser.h',
'OwningNonNull.h',
'SizeOfState.h',
'StaticMonitor.h',
'StaticMutex.h',
'StaticPtr.h',
]

Просмотреть файл

@ -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();

Просмотреть файл

@ -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

Просмотреть файл

@ -104,7 +104,7 @@ private:
OffTheBooksMutex(const OffTheBooksMutex&);
OffTheBooksMutex& operator=(const OffTheBooksMutex&);
friend class OffTheBooksCondVar;
friend class CondVar;
#ifdef DEBUG
PRThread* mOwningThread;