本文整理汇总了C++中StaticRefPtr类的典型用法代码示例。如果您正苦于以下问题:C++ StaticRefPtr类的具体用法?C++ StaticRefPtr怎么用?C++ StaticRefPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StaticRefPtr类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReleaseVRManagerParentSingleton
namespace gfx {
static StaticRefPtr<VRManagerChild> sVRManagerChildSingleton;
static StaticRefPtr<VRManagerParent> sVRManagerParentSingleton;
void ReleaseVRManagerParentSingleton() {
sVRManagerParentSingleton = nullptr;
}
VRManagerChild::VRManagerChild()
: mInputFrameID(-1)
{
MOZ_COUNT_CTOR(VRManagerChild);
MOZ_ASSERT(NS_IsMainThread());
}
VRManagerChild::~VRManagerChild()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_DTOR(VRManagerChild);
Transport* trans = GetTransport();
if (trans) {
MOZ_ASSERT(XRE_GetIOMessageLoop());
RefPtr<DeleteTask<Transport>> task = new DeleteTask<Transport>(trans);
XRE_GetIOMessageLoop()->PostTask(task.forget());
}
}
/*static*/ VRManagerChild*
VRManagerChild::Get()
{
MOZ_ASSERT(sVRManagerChildSingleton);
return sVRManagerChildSingleton;
}
/*static*/ VRManagerChild*
VRManagerChild::StartUpInChildProcess(Transport* aTransport, ProcessId aOtherPid)
{
MOZ_ASSERT(NS_IsMainThread());
// There's only one VRManager per child process.
MOZ_ASSERT(!sVRManagerChildSingleton);
RefPtr<VRManagerChild> child(new VRManagerChild());
if (!child->Open(aTransport, aOtherPid, XRE_GetIOMessageLoop(), ipc::ChildSide)) {
NS_RUNTIMEABORT("Couldn't Open() Compositor channel.");
return nullptr;
}
sVRManagerChildSingleton = child;
return sVRManagerChildSingleton;
}
/*static*/ void
VRManagerChild::StartUpSameProcess()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on the main Thread!");
if (sVRManagerChildSingleton == nullptr) {
sVRManagerChildSingleton = new VRManagerChild();
sVRManagerParentSingleton = VRManagerParent::CreateSameProcess();
sVRManagerChildSingleton->Open(sVRManagerParentSingleton->GetIPCChannel(),
mozilla::layers::CompositorThreadHolder::Loop(),
mozilla::ipc::ChildSide);
}
}
/*static*/ void
VRManagerChild::ShutDown()
{
MOZ_ASSERT(NS_IsMainThread());
if (sVRManagerChildSingleton) {
sVRManagerChildSingleton->Destroy();
sVRManagerChildSingleton = nullptr;
}
}
/*static*/ void
VRManagerChild::DeferredDestroy(RefPtr<VRManagerChild> aVRManagerChild)
{
aVRManagerChild->Close();
}
void
VRManagerChild::Destroy()
{
// This must not be called from the destructor!
MOZ_ASSERT(mRefCnt != 0);
// Keep ourselves alive until everything has been shut down
RefPtr<VRManagerChild> selfRef = this;
// The DeferredDestroyVRManager task takes ownership of
// the VRManagerChild and will release it when it runs.
MessageLoop::current()->PostTask(
NewRunnableFunction(DeferredDestroy, selfRef));
}
bool
//.........这里部分代码省略.........
示例2: AllocUnsafeShmem
namespace layers {
StaticRefPtr<VideoBridgeChild> sVideoBridgeChildSingleton;
/* static */ void
VideoBridgeChild::Startup()
{
sVideoBridgeChildSingleton = new VideoBridgeChild();
RefPtr<VideoBridgeParent> parent = new VideoBridgeParent();
MessageLoop* loop = CompositorThreadHolder::Loop();
sVideoBridgeChildSingleton->Open(parent->GetIPCChannel(),
loop,
ipc::ChildSide);
parent->SetOtherProcessId(base::GetCurrentProcId());
}
/* static */ void
VideoBridgeChild::Shutdown()
{
sVideoBridgeChildSingleton = nullptr;
}
VideoBridgeChild::VideoBridgeChild()
: mMessageLoop(MessageLoop::current())
{
sVideoBridgeChildSingleton = this;
}
VideoBridgeChild::~VideoBridgeChild()
{
}
VideoBridgeChild*
VideoBridgeChild::GetSingleton()
{
return sVideoBridgeChildSingleton;
}
bool
VideoBridgeChild::AllocUnsafeShmem(size_t aSize,
ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem)
{
return PVideoBridgeChild::AllocUnsafeShmem(aSize, aType, aShmem);
}
bool
VideoBridgeChild::AllocShmem(size_t aSize,
ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem)
{
MOZ_ASSERT(CanSend());
return PVideoBridgeChild::AllocShmem(aSize, aType, aShmem);
}
bool
VideoBridgeChild::DeallocShmem(ipc::Shmem& aShmem)
{
return PVideoBridgeChild::DeallocShmem(aShmem);
}
PTextureChild*
VideoBridgeChild::AllocPTextureChild(const SurfaceDescriptor&,
const LayersBackend&,
const TextureFlags&,
const uint64_t& aSerial)
{
MOZ_ASSERT(CanSend());
return TextureClient::CreateIPDLActor();
}
bool
VideoBridgeChild::DeallocPTextureChild(PTextureChild* actor)
{
return TextureClient::DestroyIPDLActor(actor);
}
PTextureChild*
VideoBridgeChild::CreateTexture(const SurfaceDescriptor& aSharedData,
LayersBackend aLayersBackend,
TextureFlags aFlags,
uint64_t aSerial)
{
MOZ_ASSERT(CanSend());
return SendPTextureConstructor(aSharedData, aLayersBackend, aFlags, aSerial);
}
bool VideoBridgeChild::IsSameProcess() const
{
return OtherPid() == base::GetCurrentProcId();
}
} // namespace layers
示例3: ReadSysFile
//.........这里部分代码省略.........
}
if (aMode != mMode) {
LOG("Changing mode from '%s' to '%s'", ModeStr(mMode), ModeStr(aMode));
mMode = aMode;
DBG("Calling UpdateState due to mode set to %d", mMode);
UpdateState();
}
}
void SetSharingMode(const nsACString& aVolumeName, bool aAllowSharing)
{
RefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
if (!vol) {
return;
}
if (vol->IsSharingEnabled() == aAllowSharing) {
return;
}
vol->SetSharingEnabled(aAllowSharing);
DBG("Calling UpdateState due to volume %s shareing set to %d",
vol->NameStr(), (int)aAllowSharing);
UpdateState();
}
private:
AutoVolumeEventObserver mVolumeEventObserver;
AutoVolumeManagerStateObserver mVolumeManagerStateObserver;
RefPtr<VolumeResponseCallback> mResponseCallback;
int32_t mMode;
};
static StaticRefPtr<AutoMounter> sAutoMounter;
/***************************************************************************/
void
AutoVolumeManagerStateObserver::Notify(const VolumeManager::StateChangedEvent &)
{
LOG("VolumeManager state changed event: %s", VolumeManager::StateStr());
if (!sAutoMounter) {
return;
}
DBG("Calling UpdateState due to VolumeManagerStateObserver");
sAutoMounter->UpdateState();
}
void
AutoVolumeEventObserver::Notify(Volume * const &)
{
if (!sAutoMounter) {
return;
}
DBG("Calling UpdateState due to VolumeEventStateObserver");
sAutoMounter->UpdateState();
}
void
AutoMounterResponseCallback::ResponseReceived(const VolumeCommand* aCommand)
{
if (WasSuccessful()) {
DBG("Calling UpdateState due to Volume::OnSuccess");
mErrorCount = 0;
示例4: InitializeThread
namespace mozilla {
using namespace ipc;
using namespace layers;
using namespace gfx;
// Only modified on the main-thread
StaticRefPtr<nsIThread> sVideoDecoderChildThread;
StaticRefPtr<AbstractThread> sVideoDecoderChildAbstractThread;
// Only accessed from sVideoDecoderChildThread
static StaticRefPtr<VideoDecoderManagerChild> sDecoderManager;
static UniquePtr<nsTArray<RefPtr<Runnable>>> sRecreateTasks;
/* static */
void VideoDecoderManagerChild::InitializeThread() {
MOZ_ASSERT(NS_IsMainThread());
if (!sVideoDecoderChildThread) {
RefPtr<nsIThread> childThread;
nsresult rv = NS_NewNamedThread("VideoChild", getter_AddRefs(childThread));
NS_ENSURE_SUCCESS_VOID(rv);
sVideoDecoderChildThread = childThread;
sVideoDecoderChildAbstractThread =
AbstractThread::CreateXPCOMThreadWrapper(childThread, false);
sRecreateTasks = MakeUnique<nsTArray<RefPtr<Runnable>>>();
}
}
/* static */
void VideoDecoderManagerChild::InitForContent(
Endpoint<PVideoDecoderManagerChild>&& aVideoManager) {
InitializeThread();
sVideoDecoderChildThread->Dispatch(
NewRunnableFunction("InitForContentRunnable", &Open,
std::move(aVideoManager)),
NS_DISPATCH_NORMAL);
}
/* static */
void VideoDecoderManagerChild::Shutdown() {
MOZ_ASSERT(NS_IsMainThread());
if (sVideoDecoderChildThread) {
sVideoDecoderChildThread->Dispatch(
NS_NewRunnableFunction("VideoDecoderManagerChild::Shutdown",
[]() {
if (sDecoderManager &&
sDecoderManager->CanSend()) {
sDecoderManager->Close();
sDecoderManager = nullptr;
}
}),
NS_DISPATCH_NORMAL);
sVideoDecoderChildAbstractThread = nullptr;
sVideoDecoderChildThread->Shutdown();
sVideoDecoderChildThread = nullptr;
sRecreateTasks = nullptr;
}
}
void VideoDecoderManagerChild::RunWhenRecreated(
already_AddRefed<Runnable> aTask) {
MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
// If we've already been recreated, then run the task immediately.
if (sDecoderManager && sDecoderManager != this &&
sDecoderManager->CanSend()) {
RefPtr<Runnable> task = aTask;
task->Run();
} else {
sRecreateTasks->AppendElement(aTask);
}
}
/* static */
VideoDecoderManagerChild* VideoDecoderManagerChild::GetSingleton() {
MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
return sDecoderManager;
}
/* static */
nsIThread* VideoDecoderManagerChild::GetManagerThread() {
return sVideoDecoderChildThread;
}
/* static */
AbstractThread* VideoDecoderManagerChild::GetManagerAbstractThread() {
return sVideoDecoderChildAbstractThread;
}
PVideoDecoderChild* VideoDecoderManagerChild::AllocPVideoDecoderChild(
const VideoInfo& aVideoInfo, const float& aFramerate,
const CreateDecoderParams::OptionSet& aOptions,
const layers::TextureFactoryIdentifier& aIdentifier, bool* aSuccess,
nsCString* /* not used */, nsCString* /* not used */,
//.........这里部分代码省略.........
示例5: UnregisterStateObserver
namespace system {
static StaticRefPtr<VolumeManager> sVolumeManager;
VolumeManager::STATE VolumeManager::mState = VolumeManager::UNINITIALIZED;
VolumeManager::StateObserverList VolumeManager::mStateObserverList;
/***************************************************************************/
VolumeManager::VolumeManager()
: LineWatcher('\0', kRcvBufSize),
mSocket(-1),
mCommandPending(false)
{
DBG("VolumeManager constructor called");
}
VolumeManager::~VolumeManager()
{
}
//static
void
VolumeManager::Dump(const char* aLabel)
{
if (!sVolumeManager) {
LOG("%s: sVolumeManager == null", aLabel);
return;
}
VolumeArray::size_type numVolumes = NumVolumes();
VolumeArray::index_type volIndex;
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
RefPtr<Volume> vol = GetVolume(volIndex);
vol->Dump(aLabel);
}
}
//static
size_t
VolumeManager::NumVolumes()
{
if (!sVolumeManager) {
return 0;
}
return sVolumeManager->mVolumeArray.Length();
}
//static
TemporaryRef<Volume>
VolumeManager::GetVolume(size_t aIndex)
{
MOZ_ASSERT(aIndex < NumVolumes());
return sVolumeManager->mVolumeArray[aIndex];
}
//static
VolumeManager::STATE
VolumeManager::State()
{
return mState;
}
//static
const char *
VolumeManager::StateStr(VolumeManager::STATE aState)
{
switch (aState) {
case UNINITIALIZED: return "Uninitialized";
case STARTING: return "Starting";
case VOLUMES_READY: return "Volumes Ready";
}
return "???";
}
//static
void
VolumeManager::SetState(STATE aNewState)
{
if (mState != aNewState) {
LOG("changing state from '%s' to '%s'",
StateStr(mState), StateStr(aNewState));
mState = aNewState;
mStateObserverList.Broadcast(StateChangedEvent());
}
}
//static
void
VolumeManager::RegisterStateObserver(StateObserver* aObserver)
{
mStateObserverList.AddObserver(aObserver);
}
//static
void VolumeManager::UnregisterStateObserver(StateObserver* aObserver)
{
mStateObserverList.RemoveObserver(aObserver);
}
//.........这里部分代码省略.........
示例6: ReleaseVRManagerParentSingleton
namespace gfx {
static StaticRefPtr<VRManagerChild> sVRManagerChildSingleton;
static StaticRefPtr<VRManagerParent> sVRManagerParentSingleton;
void ReleaseVRManagerParentSingleton() {
sVRManagerParentSingleton = nullptr;
}
VRManagerChild::VRManagerChild()
: TextureForwarder()
, mDisplaysInitialized(false)
, mMessageLoop(MessageLoop::current())
, mFrameRequestCallbackCounter(0)
, mBackend(layers::LayersBackend::LAYERS_NONE)
, mPromiseID(0)
, mVRMockDisplay(nullptr)
{
MOZ_ASSERT(NS_IsMainThread());
mStartTimeStamp = TimeStamp::Now();
}
VRManagerChild::~VRManagerChild()
{
MOZ_ASSERT(NS_IsMainThread());
}
/*static*/ void
VRManagerChild::IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier)
{
if (sVRManagerChildSingleton) {
sVRManagerChildSingleton->mBackend = aIdentifier.mParentBackend;
sVRManagerChildSingleton->mSyncObject =
layers::SyncObjectClient::CreateSyncObjectClient(aIdentifier.mSyncHandle);
}
}
layers::LayersBackend
VRManagerChild::GetBackendType() const
{
return mBackend;
}
/*static*/ VRManagerChild*
VRManagerChild::Get()
{
MOZ_ASSERT(sVRManagerChildSingleton);
return sVRManagerChildSingleton;
}
/* static */ bool
VRManagerChild::IsCreated()
{
return !!sVRManagerChildSingleton;
}
/* static */ bool
VRManagerChild::InitForContent(Endpoint<PVRManagerChild>&& aEndpoint)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sVRManagerChildSingleton);
RefPtr<VRManagerChild> child(new VRManagerChild());
if (!aEndpoint.Bind(child)) {
NS_RUNTIMEABORT("Couldn't Open() Compositor channel.");
return false;
}
sVRManagerChildSingleton = child;
return true;
}
/* static */ bool
VRManagerChild::ReinitForContent(Endpoint<PVRManagerChild>&& aEndpoint)
{
MOZ_ASSERT(NS_IsMainThread());
ShutDown();
return InitForContent(Move(aEndpoint));
}
/*static*/ void
VRManagerChild::InitSameProcess()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sVRManagerChildSingleton);
sVRManagerChildSingleton = new VRManagerChild();
sVRManagerParentSingleton = VRManagerParent::CreateSameProcess();
sVRManagerChildSingleton->Open(sVRManagerParentSingleton->GetIPCChannel(),
mozilla::layers::CompositorThreadHolder::Loop(),
mozilla::ipc::ChildSide);
}
/* static */ void
VRManagerChild::InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sVRManagerChildSingleton);
//.........这里部分代码省略.........
示例7: ReleaseImageBridgeParentSingleton
namespace layers {
static StaticRefPtr<CompositorThreadHolder> sCompositorThreadHolder;
static bool sFinishedCompositorShutDown = false;
// See ImageBridgeChild.cpp
void ReleaseImageBridgeParentSingleton();
CompositorThreadHolder* GetCompositorThreadHolder()
{
return sCompositorThreadHolder;
}
base::Thread*
CompositorThread()
{
return sCompositorThreadHolder
? sCompositorThreadHolder->GetCompositorThread()
: nullptr;
}
/* static */ MessageLoop*
CompositorThreadHolder::Loop()
{
return CompositorThread() ? CompositorThread()->message_loop() : nullptr;
}
CompositorThreadHolder*
CompositorThreadHolder::GetSingleton()
{
return sCompositorThreadHolder;
}
CompositorThreadHolder::CompositorThreadHolder()
: mCompositorThread(CreateCompositorThread())
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_CTOR(CompositorThreadHolder);
}
CompositorThreadHolder::~CompositorThreadHolder()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_DTOR(CompositorThreadHolder);
DestroyCompositorThread(mCompositorThread);
}
/* static */ void
CompositorThreadHolder::DestroyCompositorThread(base::Thread* aCompositorThread)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sCompositorThreadHolder, "We shouldn't be destroying the compositor thread yet.");
CompositorBridgeParent::Shutdown();
delete aCompositorThread;
sFinishedCompositorShutDown = true;
}
/* static */ base::Thread*
CompositorThreadHolder::CreateCompositorThread()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sCompositorThreadHolder, "The compositor thread has already been started!");
base::Thread* compositorThread = new base::Thread("Compositor");
base::Thread::Options options;
/* Timeout values are powers-of-two to enable us get better data.
128ms is chosen for transient hangs because 8Hz should be the minimally
acceptable goal for Compositor responsiveness (normal goal is 60Hz). */
options.transient_hang_timeout = 128; // milliseconds
/* 2048ms is chosen for permanent hangs because it's longer than most
* Compositor hangs seen in the wild, but is short enough to not miss getting
* native hang stacks. */
options.permanent_hang_timeout = 2048; // milliseconds
#if defined(_WIN32)
/* With d3d9 the compositor thread creates native ui, see DeviceManagerD3D9. As
* such the thread is a gui thread, and must process a windows message queue or
* risk deadlocks. Chromium message loop TYPE_UI does exactly what we need. */
options.message_loop_type = MessageLoop::TYPE_UI;
#endif
if (!compositorThread->StartWithOptions(options)) {
delete compositorThread;
return nullptr;
}
CompositorBridgeParent::Setup();
return compositorThread;
}
void
CompositorThreadHolder::Start()
{
MOZ_ASSERT(NS_IsMainThread(), "Should be on the main Thread!");
//.........这里部分代码省略.........
示例8: DispatchReleaseTextureClient
// static
void ImageBridgeChild::DispatchReleaseTextureClient(TextureClient* aClient)
{
sImageBridgeChildSingleton->GetMessageLoop()->PostTask(
FROM_HERE,
NewRunnableFunction(&ReleaseTextureClientNow, aClient));
}