mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 05:11:03 +00:00
081721a2da
- reapply Bug 1574573 - Disambiguate a use of Handle in XPCShellEnvironment.cpp r=Ehsan (a674c4b006) - Bug 1255707 - Part 2. Remove ScreenSizeChanged. r=snorp (3a93e4e768) - Bug 1250418 - Remove the assertion check of mCanSend in CompositorCh ld::ActorDestroy, r=nical (14bb402a1d) - Bug 1250718 - Improve layer logging for preserve-3d layers. r=thinker (f373a50040) - Bug 1232042 - Addendum: Add comment for mLayerManager check. r=jrmuizel (2b69aa784a) - Bug 1239861. Skip composite if vsync time is before force composite time. r=kats (5ee4038157) - Bug 1241678 - Fix low-volume null-deref crash. r=BenWa (b28d944615) - Rename PCompositor to PCompositorBridge. (bug 1258479 part 2, r=mattwoodrow) (dd535a9bdd) - Bug 1220184 - Eliminate Gingerbread compatibility. r=froydnj, r=nalexander (dce9e4f9e8) - Bug 1250917 - Remove NS_SUCCESS_I_DID_SOMETHING; r=bholley (9dd6fe351b) - Bug 1155241: Check mInstanceOwner for nullptr in nsObjectLoadingContent::PluginDestroyed; r=smaug (ad60991e3e) - Bug 1229220 - Update the scrollbar visibility prefs when initializing a TabChild; r=smaug (28997e0a6d) - Bug 1252262 - Don't combine the client offset into the outer rect for the child process. r=jimm (f415c0418e) - Bug 1249943 - Make test_basic_pan work on Fennec and Linux as well. r=botond (657c940be1) - bit of bug 1245765 part 5 (82463f7eaa) - Bug 1207512 - Remove the JS_IsRunning call in nsObjectLoadingContent::ScriptRequestPluginInstance; r=bholley (76047284a6) - Bug 1239463 - Do not assert when notifying an inactive document about changed content from the plugin crash notification. r=bz (03bf38a683) - Bug 1192450 - Remove PlayPreview registration from Shumway. r=jet (9b6e131876) - Bug 1200602 - Use the alternate content for <applet>. r=kmachulis (843fccf0aa)
258 lines
7.1 KiB
C++
258 lines
7.1 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
/* 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 "MediaSystemResourceManagerParent.h"
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "MediaSystemResourceService.h"
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
namespace mozilla {
|
|
|
|
/* static */ StaticRefPtr<MediaSystemResourceService> MediaSystemResourceService::sSingleton;
|
|
|
|
/* static */ MediaSystemResourceService*
|
|
MediaSystemResourceService::Get()
|
|
{
|
|
if (sSingleton) {
|
|
return sSingleton;
|
|
}
|
|
Init();
|
|
return sSingleton;
|
|
}
|
|
|
|
/* static */ void
|
|
MediaSystemResourceService::Init()
|
|
{
|
|
if (!sSingleton) {
|
|
sSingleton = new MediaSystemResourceService();
|
|
}
|
|
}
|
|
|
|
/* static */ void
|
|
MediaSystemResourceService::Shutdown()
|
|
{
|
|
if (sSingleton) {
|
|
sSingleton->Destroy();
|
|
sSingleton = nullptr;
|
|
}
|
|
}
|
|
|
|
MediaSystemResourceService::MediaSystemResourceService()
|
|
: mDestroyed(false)
|
|
{
|
|
MOZ_ASSERT(CompositorBridgeParent::IsInCompositorThread());
|
|
#ifdef MOZ_WIDGET_GONK
|
|
// The maximum number of hardware resoureces available.
|
|
// XXX need to hange to a dynamic way.
|
|
enum
|
|
{
|
|
VIDEO_DECODER_COUNT = 1,
|
|
VIDEO_ENCODER_COUNT = 1
|
|
};
|
|
|
|
MediaSystemResource* resource;
|
|
|
|
resource = new MediaSystemResource(VIDEO_DECODER_COUNT);
|
|
mResources.Put(static_cast<uint32_t>(MediaSystemResourceType::VIDEO_DECODER), resource);
|
|
|
|
resource = new MediaSystemResource(VIDEO_ENCODER_COUNT);
|
|
mResources.Put(static_cast<uint32_t>(MediaSystemResourceType::VIDEO_ENCODER), resource);
|
|
#endif
|
|
}
|
|
|
|
MediaSystemResourceService::~MediaSystemResourceService()
|
|
{
|
|
}
|
|
|
|
void
|
|
MediaSystemResourceService::Destroy()
|
|
{
|
|
mDestroyed = true;
|
|
}
|
|
|
|
void
|
|
MediaSystemResourceService::Acquire(media::MediaSystemResourceManagerParent* aParent,
|
|
uint32_t aId,
|
|
MediaSystemResourceType aResourceType,
|
|
bool aWillWait)
|
|
{
|
|
MOZ_ASSERT(CompositorBridgeParent::IsInCompositorThread());
|
|
MOZ_ASSERT(aParent);
|
|
|
|
if (mDestroyed) {
|
|
return;
|
|
}
|
|
|
|
MediaSystemResource* resource = mResources.Get(static_cast<uint32_t>(aResourceType));
|
|
|
|
if (!resource ||
|
|
resource->mResourceCount == 0) {
|
|
// Resource does not exit
|
|
// Send fail response
|
|
mozilla::Unused << aParent->SendResponse(aId, false /* fail */);
|
|
return;
|
|
}
|
|
|
|
// Try to acquire a resource
|
|
if (resource->mAcquiredRequests.size() < resource->mResourceCount) {
|
|
// Resource is available
|
|
resource->mAcquiredRequests.push_back(
|
|
MediaSystemResourceRequest(aParent, aId));
|
|
// Send success response
|
|
mozilla::Unused << aParent->SendResponse(aId, true /* success */);
|
|
return;
|
|
} else if (!aWillWait) {
|
|
// Resource is not available and do not wait.
|
|
// Send fail response
|
|
mozilla::Unused << aParent->SendResponse(aId, false /* fail */);
|
|
return;
|
|
}
|
|
// Wait until acquire.
|
|
resource->mWaitingRequests.push_back(
|
|
MediaSystemResourceRequest(aParent, aId));
|
|
}
|
|
|
|
void
|
|
MediaSystemResourceService::ReleaseResource(media::MediaSystemResourceManagerParent* aParent,
|
|
uint32_t aId,
|
|
MediaSystemResourceType aResourceType)
|
|
{
|
|
MOZ_ASSERT(CompositorBridgeParent::IsInCompositorThread());
|
|
MOZ_ASSERT(aParent);
|
|
|
|
if (mDestroyed) {
|
|
return;
|
|
}
|
|
|
|
MediaSystemResource* resource = mResources.Get(static_cast<uint32_t>(aResourceType));
|
|
|
|
if (!resource ||
|
|
resource->mResourceCount == 0) {
|
|
// Resource does not exit
|
|
return;
|
|
}
|
|
RemoveRequest(aParent, aId, aResourceType);
|
|
UpdateRequests(aResourceType);
|
|
}
|
|
|
|
void
|
|
MediaSystemResourceService::ReleaseResource(media::MediaSystemResourceManagerParent* aParent)
|
|
{
|
|
MOZ_ASSERT(aParent);
|
|
|
|
if (mDestroyed) {
|
|
return;
|
|
}
|
|
|
|
for (auto iter = mResources.Iter(); !iter.Done(); iter.Next()) {
|
|
const uint32_t& key = iter.Key();
|
|
RemoveRequests(aParent, static_cast<MediaSystemResourceType>(key));
|
|
UpdateRequests(static_cast<MediaSystemResourceType>(key));
|
|
}
|
|
}
|
|
|
|
void
|
|
MediaSystemResourceService::RemoveRequest(media::MediaSystemResourceManagerParent* aParent,
|
|
uint32_t aId,
|
|
MediaSystemResourceType aResourceType)
|
|
{
|
|
MOZ_ASSERT(aParent);
|
|
|
|
MediaSystemResource* resource = mResources.Get(static_cast<uint32_t>(aResourceType));
|
|
if (!resource) {
|
|
return;
|
|
}
|
|
|
|
std::deque<MediaSystemResourceRequest>::iterator it;
|
|
std::deque<MediaSystemResourceRequest>& acquiredRequests =
|
|
resource->mAcquiredRequests;
|
|
for (it = acquiredRequests.begin(); it != acquiredRequests.end(); it++) {
|
|
if (((*it).mParent == aParent) && ((*it).mId == aId)) {
|
|
acquiredRequests.erase(it);
|
|
return;
|
|
}
|
|
}
|
|
|
|
std::deque<MediaSystemResourceRequest>& waitingRequests =
|
|
resource->mWaitingRequests;
|
|
for (it = waitingRequests.begin(); it != waitingRequests.end(); it++) {
|
|
if (((*it).mParent == aParent) && ((*it).mId == aId)) {
|
|
waitingRequests.erase(it);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
MediaSystemResourceService::RemoveRequests(media::MediaSystemResourceManagerParent* aParent,
|
|
MediaSystemResourceType aResourceType)
|
|
{
|
|
MOZ_ASSERT(aParent);
|
|
|
|
MediaSystemResource* resource = mResources.Get(static_cast<uint32_t>(aResourceType));
|
|
|
|
if (!resource ||
|
|
resource->mResourceCount == 0) {
|
|
// Resource does not exit
|
|
return;
|
|
}
|
|
|
|
std::deque<MediaSystemResourceRequest>::iterator it;
|
|
std::deque<MediaSystemResourceRequest>& acquiredRequests =
|
|
resource->mAcquiredRequests;
|
|
for (it = acquiredRequests.begin(); it != acquiredRequests.end();) {
|
|
if ((*it).mParent == aParent) {
|
|
it = acquiredRequests.erase(it);
|
|
} else {
|
|
it++;
|
|
}
|
|
}
|
|
|
|
std::deque<MediaSystemResourceRequest>& waitingRequests =
|
|
resource->mWaitingRequests;
|
|
for (it = waitingRequests.begin(); it != waitingRequests.end();) {
|
|
if ((*it).mParent == aParent) {
|
|
it = waitingRequests.erase(it);
|
|
return;
|
|
} else {
|
|
it++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
MediaSystemResourceService::UpdateRequests(MediaSystemResourceType aResourceType)
|
|
{
|
|
MediaSystemResource* resource = mResources.Get(static_cast<uint32_t>(aResourceType));
|
|
|
|
if (!resource ||
|
|
resource->mResourceCount == 0) {
|
|
// Resource does not exit
|
|
return;
|
|
}
|
|
|
|
std::deque<MediaSystemResourceRequest>& acquiredRequests =
|
|
resource->mAcquiredRequests;
|
|
std::deque<MediaSystemResourceRequest>& waitingRequests =
|
|
resource->mWaitingRequests;
|
|
|
|
while ((acquiredRequests.size() < resource->mResourceCount) &&
|
|
(waitingRequests.size() > 0)) {
|
|
MediaSystemResourceRequest& request = waitingRequests.front();
|
|
MOZ_ASSERT(request.mParent);
|
|
// Send response
|
|
mozilla::Unused << request.mParent->SendResponse(request.mId, true /* success */);
|
|
// Move request to mAcquiredRequests
|
|
acquiredRequests.push_back(waitingRequests.front());
|
|
waitingRequests.pop_front();
|
|
}
|
|
}
|
|
|
|
} // namespace mozilla
|