Merge mozilla-central to mozilla-inbound.

This commit is contained in:
Cosmin Sabou 2019-01-04 11:46:43 +02:00
Родитель 64e5de9372 fef7f858ef
Коммит d65302a51b
40 изменённых файлов: 437 добавлений и 299 удалений

9
Cargo.lock сгенерированный
Просмотреть файл

@ -2999,6 +2999,7 @@ dependencies = [
"thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_api 0.58.0",
"webrender_build 0.0.1",
]
[[package]]
@ -3040,6 +3041,14 @@ dependencies = [
"webrender 0.58.0",
]
[[package]]
name = "webrender_build"
version = "0.0.1"
dependencies = [
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "which"
version = "1.0.3"

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

@ -63,7 +63,7 @@ class MOZ_STACK_CLASS DragDataProducer {
nsIContent* aSelectionTargetNode, bool aIsAltKeyPressed);
nsresult Produce(DataTransfer* aDataTransfer, bool* aCanDrag,
Selection** aSelection, nsIContent** aDragNode,
nsACString& aPrincipalURISpec);
nsIPrincipal** aPrincipal);
private:
void AddString(DataTransfer* aDataTransfer, const nsAString& aFlavor,
@ -108,7 +108,7 @@ nsresult nsContentAreaDragDrop::GetDragData(
nsPIDOMWindowOuter* aWindow, nsIContent* aTarget,
nsIContent* aSelectionTargetNode, bool aIsAltKeyPressed,
DataTransfer* aDataTransfer, bool* aCanDrag, Selection** aSelection,
nsIContent** aDragNode, nsACString& aPrincipalURISpec) {
nsIContent** aDragNode, nsIPrincipal** aPrincipal) {
NS_ENSURE_TRUE(aSelectionTargetNode, NS_ERROR_INVALID_ARG);
*aCanDrag = true;
@ -116,7 +116,7 @@ nsresult nsContentAreaDragDrop::GetDragData(
DragDataProducer provider(aWindow, aTarget, aSelectionTargetNode,
aIsAltKeyPressed);
return provider.Produce(aDataTransfer, aCanDrag, aSelection, aDragNode,
aPrincipalURISpec);
aPrincipal);
}
NS_IMPL_ISUPPORTS(nsContentAreaDragDropDataProvider, nsIFlavorDataProvider)
@ -483,7 +483,7 @@ nsresult DragDataProducer::GetImageData(imgIContainer* aImage,
nsresult DragDataProducer::Produce(DataTransfer* aDataTransfer, bool* aCanDrag,
Selection** aSelection,
nsIContent** aDragNode,
nsACString& aPrincipalURISpec) {
nsIPrincipal** aPrincipal) {
MOZ_ASSERT(aCanDrag && aSelection && aDataTransfer && aDragNode,
"null pointer passed to Produce");
NS_ASSERTION(mWindow, "window not set");
@ -548,7 +548,7 @@ nsresult DragDataProducer::Produce(DataTransfer* aDataTransfer, bool* aCanDrag,
if (tp) {
// We have a TabParent, so it may have data for dnd in case the child
// process started a dnd session.
tp->AddInitialDnDDataTo(aDataTransfer, aPrincipalURISpec);
tp->AddInitialDnDDataTo(aDataTransfer, aPrincipal);
}
}
}

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

@ -46,9 +46,8 @@ class nsContentAreaDragDrop {
* selection is being dragged.
* aDragNode - [out] the link, image or area being dragged, or null if the
* drag occurred on another element.
* aPrincipalURISpec - [out] set to the URI of the triggering principal of
* the drag, or empty string if it's from
* browser chrome or OS
* aPrincipal - [out] set to the triggering principal of the drag, or null if
* it's from browser chrome or OS
*/
static nsresult GetDragData(nsPIDOMWindowOuter* aWindow, nsIContent* aTarget,
nsIContent* aSelectionTargetNode,
@ -57,7 +56,7 @@ class nsContentAreaDragDrop {
bool* aCanDrag,
mozilla::dom::Selection** aSelection,
nsIContent** aDragNode,
nsACString& aPrincipalURISpec);
nsIPrincipal** aPrincipal);
};
// this is used to save images to disk lazily when the image data is asked for

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

@ -244,9 +244,28 @@ void DataTransfer::GetMozTriggeringPrincipalURISpec(
return;
}
nsCString principalURISpec;
dragSession->GetTriggeringPrincipalURISpec(principalURISpec);
CopyUTF8toUTF16(principalURISpec, aPrincipalURISpec);
nsCOMPtr<nsIPrincipal> principal;
dragSession->GetTriggeringPrincipal(getter_AddRefs(principal));
if (!principal) {
aPrincipalURISpec.Truncate(0);
return;
}
nsCOMPtr<nsIURI> uri;
principal->GetURI(getter_AddRefs(uri));
if (!uri) {
aPrincipalURISpec.Truncate(0);
return;
}
nsAutoCString spec;
nsresult rv = uri->GetSpec(spec);
if (NS_FAILED(rv)) {
aPrincipalURISpec.Truncate(0);
return;
}
CopyUTF8toUTF16(spec, aPrincipalURISpec);
}
already_AddRefed<FileList> DataTransfer::GetFiles(

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

@ -1250,11 +1250,11 @@ void EventStateManager::DispatchCrossProcessEvent(WidgetEvent* aEvent,
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
uint32_t dropEffect = nsIDragService::DRAGDROP_ACTION_NONE;
uint32_t action = nsIDragService::DRAGDROP_ACTION_NONE;
nsCString principalURISpec;
nsCOMPtr<nsIPrincipal> principal;
if (dragSession) {
dragSession->DragEventDispatchedToChildProcess();
dragSession->GetDragAction(&action);
dragSession->GetTriggeringPrincipalURISpec(principalURISpec);
dragSession->GetTriggeringPrincipal(getter_AddRefs(principal));
RefPtr<DataTransfer> initialDataTransfer =
dragSession->GetDataTransfer();
if (initialDataTransfer) {
@ -1263,7 +1263,7 @@ void EventStateManager::DispatchCrossProcessEvent(WidgetEvent* aEvent,
}
tabParent->SendRealDragEvent(*aEvent->AsDragEvent(), action, dropEffect,
principalURISpec);
IPC::Principal(principal));
return;
}
case ePluginEventClass: {
@ -1748,12 +1748,12 @@ void EventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
RefPtr<Selection> selection;
nsCOMPtr<nsIContent> eventContent, targetContent;
nsCString principalURISpec;
nsCOMPtr<nsIPrincipal> principal;
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(eventContent));
if (eventContent)
DetermineDragTargetAndDefaultData(
window, eventContent, dataTransfer, getter_AddRefs(selection),
getter_AddRefs(targetContent), principalURISpec);
getter_AddRefs(targetContent), getter_AddRefs(principal));
// Stop tracking the drag gesture now. This should stop us from
// reentering GenerateDragGesture inside DOM event processing.
@ -1816,7 +1816,7 @@ void EventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
if (status != nsEventStatus_eConsumeNoDefault) {
bool dragStarted =
DoDefaultDragStart(aPresContext, event, dataTransfer, targetContent,
selection, principalURISpec);
selection, principal);
if (dragStarted) {
sActiveESM = nullptr;
MaybeFirePointerCancel(aEvent);
@ -1837,7 +1837,7 @@ void EventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
void EventStateManager::DetermineDragTargetAndDefaultData(
nsPIDOMWindowOuter* aWindow, nsIContent* aSelectionTarget,
DataTransfer* aDataTransfer, Selection** aSelection,
nsIContent** aTargetNode, nsACString& aPrincipalURISpec) {
nsIContent** aTargetNode, nsIPrincipal** aPrincipal) {
*aTargetNode = nullptr;
// GetDragData determines if a selection, link or image in the content
@ -1850,7 +1850,7 @@ void EventStateManager::DetermineDragTargetAndDefaultData(
bool wasAlt = (mGestureModifiers & MODIFIER_ALT) != 0;
nsresult rv = nsContentAreaDragDrop::GetDragData(
aWindow, mGestureDownContent, aSelectionTarget, wasAlt, aDataTransfer,
&canDrag, aSelection, getter_AddRefs(dragDataNode), aPrincipalURISpec);
&canDrag, aSelection, getter_AddRefs(dragDataNode), aPrincipal);
if (NS_FAILED(rv) || !canDrag) return;
// if GetDragData returned a node, use that as the node being dragged.
@ -1906,10 +1906,12 @@ void EventStateManager::DetermineDragTargetAndDefaultData(
}
}
bool EventStateManager::DoDefaultDragStart(
nsPresContext* aPresContext, WidgetDragEvent* aDragEvent,
DataTransfer* aDataTransfer, nsIContent* aDragTarget, Selection* aSelection,
const nsACString& aPrincipalURISpec) {
bool EventStateManager::DoDefaultDragStart(nsPresContext* aPresContext,
WidgetDragEvent* aDragEvent,
DataTransfer* aDataTransfer,
nsIContent* aDragTarget,
Selection* aSelection,
nsIPrincipal* aPrincipal) {
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
if (!dragService) return false;
@ -1982,11 +1984,11 @@ bool EventStateManager::DoDefaultDragStart(
// other than a selection is being dragged.
if (!dragImage && aSelection) {
dragService->InvokeDragSessionWithSelection(
aSelection, aPrincipalURISpec, transArray, action, event, dataTransfer);
aSelection, aPrincipal, transArray, action, event, dataTransfer);
} else {
dragService->InvokeDragSessionWithImage(
dragTarget, aPrincipalURISpec, transArray, action, dragImage, imageX,
imageY, event, dataTransfer);
dragService->InvokeDragSessionWithImage(dragTarget, aPrincipal, transArray,
action, dragImage, imageX, imageY,
event, dataTransfer);
}
return true;

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

@ -1061,16 +1061,15 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
* aDataTransfer - data transfer object that will contain the data to drag
* aSelection - [out] set to the selection to be dragged
* aTargetNode - [out] the draggable node, or null if there isn't one
* aPrincipalURISpec - [out] set to the URI of the triggering principal of
* the drag, or an empty string if it's from
* browser chrome or OS
* aPrincipal - [out] set to the triggering principal of the drag, or null
* if it's from browser chrome or OS
*/
void DetermineDragTargetAndDefaultData(nsPIDOMWindowOuter* aWindow,
nsIContent* aSelectionTarget,
dom::DataTransfer* aDataTransfer,
dom::Selection** aSelection,
nsIContent** aTargetNode,
nsACString& aPrincipalURISpec);
nsIPrincipal** aPrincipal);
/*
* Perform the default handling for the dragstart event and set up a
@ -1081,14 +1080,14 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
* aDataTransfer - the data transfer that holds the data to be dragged
* aDragTarget - the target of the drag
* aSelection - the selection to be dragged
* aPrincipalURISpec - the URI of the triggering principal of the drag,
* or an empty string if it's from browser chrome or OS
* aPrincipal - the triggering principal of the drag, or null if it's from
* browser chrome or OS
*/
bool DoDefaultDragStart(nsPresContext* aPresContext,
WidgetDragEvent* aDragEvent,
dom::DataTransfer* aDataTransfer,
nsIContent* aDragTarget, dom::Selection* aSelection,
const nsACString& aPrincipalURISpec);
nsIPrincipal* aPrincipal);
bool IsTrackingDragGesture() const { return mGestureDownContent != nullptr; }
/**

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

@ -568,7 +568,7 @@ parent:
OptionalShmem visualData,
uint32_t stride, SurfaceFormat format,
LayoutDeviceIntRect dragRect,
nsCString principalURISpec);
Principal principal);
// After a compositor reset, it is necessary to reconnect each layers ID to
// the compositor of the widget that will render those layers. Note that
@ -715,7 +715,7 @@ child:
* don't need support RealDragEvent with input priority.
*/
async RealDragEvent(WidgetDragEvent aEvent, uint32_t aDragAction,
uint32_t aDropEffect, nsCString aPrincipalURISpec);
uint32_t aDropEffect, Principal aPrincipal);
async PluginEvent(WidgetPluginEvent aEvent);

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

@ -1721,14 +1721,14 @@ mozilla::ipc::IPCResult TabChild::RecvNormalPriorityRealTouchMoveEvent(
mozilla::ipc::IPCResult TabChild::RecvRealDragEvent(
const WidgetDragEvent& aEvent, const uint32_t& aDragAction,
const uint32_t& aDropEffect, const nsCString& aPrincipalURISpec) {
const uint32_t& aDropEffect, const IPC::Principal& aPrincipal) {
WidgetDragEvent localEvent(aEvent);
localEvent.mWidget = mPuppetWidget;
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
if (dragSession) {
dragSession->SetDragAction(aDragAction);
dragSession->SetTriggeringPrincipalURISpec(aPrincipalURISpec);
dragSession->SetTriggeringPrincipal(aPrincipal);
RefPtr<DataTransfer> initialDataTransfer = dragSession->GetDataTransfer();
if (initialDataTransfer) {
initialDataTransfer->SetDropEffectInt(aDropEffect);

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

@ -332,7 +332,7 @@ class TabChild final : public TabChildBase,
virtual mozilla::ipc::IPCResult RecvRealDragEvent(
const WidgetDragEvent& aEvent, const uint32_t& aDragAction,
const uint32_t& aDropEffect, const nsCString& aPrincipalURISpec) override;
const uint32_t& aDropEffect, const IPC::Principal& aPrincipal) override;
virtual mozilla::ipc::IPCResult RecvRealKeyEvent(
const mozilla::WidgetKeyboardEvent& aEvent) override;

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

@ -1180,7 +1180,7 @@ bool TabParent::QueryDropLinksForVerification() {
void TabParent::SendRealDragEvent(WidgetDragEvent& aEvent, uint32_t aDragAction,
uint32_t aDropEffect,
const nsCString& aPrincipalURISpec) {
const IPC::Principal& aPrincipal) {
if (mIsDestroyed || !mIsReadyToHandleInputEvents) {
return;
}
@ -1192,7 +1192,7 @@ void TabParent::SendRealDragEvent(WidgetDragEvent& aEvent, uint32_t aDragAction,
}
}
DebugOnly<bool> ret = PBrowserParent::SendRealDragEvent(
aEvent, aDragAction, aDropEffect, aPrincipalURISpec);
aEvent, aDragAction, aDropEffect, aPrincipal);
NS_WARNING_ASSERTION(ret, "PBrowserParent::SendRealDragEvent() failed");
MOZ_ASSERT(!ret || aEvent.HasBeenPostedToRemoteProcess());
}
@ -3080,7 +3080,7 @@ mozilla::ipc::IPCResult TabParent::RecvInvokeDragSession(
nsTArray<IPCDataTransfer>&& aTransfers, const uint32_t& aAction,
const OptionalShmem& aVisualDnDData, const uint32_t& aStride,
const gfx::SurfaceFormat& aFormat, const LayoutDeviceIntRect& aDragRect,
const nsCString& aPrincipalURISpec) {
const IPC::Principal& aPrincipal) {
mInitialDataTransferItems.Clear();
nsIPresShell* shell = mFrameElement->OwnerDoc()->GetShell();
if (!shell) {
@ -3118,7 +3118,7 @@ mozilla::ipc::IPCResult TabParent::RecvInvokeDragSession(
mDragValid = true;
mDragRect = aDragRect;
mDragPrincipalURISpec = aPrincipalURISpec;
mDragPrincipal = aPrincipal;
esm->BeginTrackingRemoteDragGesture(mFrameElement);
@ -3130,19 +3130,8 @@ mozilla::ipc::IPCResult TabParent::RecvInvokeDragSession(
}
void TabParent::AddInitialDnDDataTo(DataTransfer* aDataTransfer,
nsACString& aPrincipalURISpec) {
aPrincipalURISpec.Assign(mDragPrincipalURISpec);
nsCOMPtr<nsIPrincipal> principal;
if (!mDragPrincipalURISpec.IsEmpty()) {
// If principal is given, try using it first.
principal = BasePrincipal::CreateCodebasePrincipal(mDragPrincipalURISpec);
}
if (!principal) {
// Fallback to system principal, to handle like the data is from browser
// chrome or OS.
principal = nsContentUtils::GetSystemPrincipal();
}
nsIPrincipal** aPrincipal) {
NS_IF_ADDREF(*aPrincipal = mDragPrincipal);
for (uint32_t i = 0; i < mInitialDataTransferItems.Length(); ++i) {
nsTArray<IPCDataTransferItem>& itemArray = mInitialDataTransferItems[i];
@ -3183,12 +3172,12 @@ void TabParent::AddInitialDnDDataTo(DataTransfer* aDataTransfer,
// from content in the parent process where there is no content.
// XXX: Nested Content Processes may change this
aDataTransfer->SetDataWithPrincipalFromOtherProcess(
NS_ConvertUTF8toUTF16(item.flavor()), variant, i, principal,
NS_ConvertUTF8toUTF16(item.flavor()), variant, i, mDragPrincipal,
/* aHidden = */ false);
}
}
mInitialDataTransferItems.Clear();
mDragPrincipalURISpec.Truncate(0);
mDragPrincipal = nullptr;
}
bool TabParent::TakeDragVisualization(

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

@ -410,7 +410,7 @@ class TabParent final : public PBrowserParent,
void SendRealDragEvent(WidgetDragEvent& aEvent, uint32_t aDragAction,
uint32_t aDropEffect,
const nsCString& aPrincipalURISpec);
const IPC::Principal& aPrincipal);
void SendMouseWheelEvent(WidgetWheelEvent& aEvent);
@ -531,10 +531,10 @@ class TabParent final : public PBrowserParent,
nsTArray<IPCDataTransfer>&& aTransfers, const uint32_t& aAction,
const OptionalShmem& aVisualDnDData, const uint32_t& aStride,
const gfx::SurfaceFormat& aFormat, const LayoutDeviceIntRect& aDragRect,
const nsCString& aPrincipalURISpec) override;
const IPC::Principal& aPrincipal) override;
void AddInitialDnDDataTo(DataTransfer* aDataTransfer,
nsACString& aPrincipalURISpec);
nsIPrincipal** aPrincipal);
bool TakeDragVisualization(RefPtr<mozilla::gfx::SourceSurface>& aSurface,
LayoutDeviceIntRect* aDragRect);
@ -662,7 +662,7 @@ class TabParent final : public PBrowserParent,
RefPtr<gfx::DataSourceSurface> mDnDVisualization;
bool mDragValid;
LayoutDeviceIntRect mDragRect;
nsCString mDragPrincipalURISpec;
nsCOMPtr<nsIPrincipal> mDragPrincipal;
nsCOMPtr<nsILoadContext> mLoadContext;

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

@ -976,13 +976,12 @@ nsresult MediaDevice::Allocate(const dom::MediaTrackConstraints& aConstraints,
aOutBadConstraint);
}
nsresult MediaDevice::SetTrack(const RefPtr<SourceMediaStream>& aStream,
TrackID aTrackID,
const PrincipalHandle& aPrincipalHandle) {
void MediaDevice::SetTrack(const RefPtr<SourceMediaStream>& aStream,
TrackID aTrackID,
const PrincipalHandle& aPrincipalHandle) {
MOZ_ASSERT(MediaManager::IsInMediaThread());
MOZ_ASSERT(mSource);
return mSource->SetTrack(mAllocationHandle, aStream, aTrackID,
aPrincipalHandle);
mSource->SetTrack(mAllocationHandle, aStream, aTrackID, aPrincipalHandle);
}
nsresult MediaDevice::Start() {
@ -4123,11 +4122,19 @@ SourceListener::InitializeAsync() {
mVideoDeviceState ? mVideoDeviceState->mDevice : nullptr](
MozPromiseHolder<SourceListenerPromise>& aHolder) {
if (audioDevice) {
nsresult rv =
audioDevice->SetTrack(stream, kAudioTrack, principal);
if (NS_SUCCEEDED(rv)) {
rv = audioDevice->Start();
}
audioDevice->SetTrack(stream, kAudioTrack, principal);
}
if (videoDevice) {
videoDevice->SetTrack(stream, kVideoTrack, principal);
}
// SetTrack() queued the tracks. We add them synchronously here
// to avoid races.
stream->FinishAddTracks();
if (audioDevice) {
nsresult rv = audioDevice->Start();
if (NS_FAILED(rv)) {
nsString log;
if (rv == NS_ERROR_NOT_AVAILABLE) {
@ -4147,11 +4154,7 @@ SourceListener::InitializeAsync() {
}
if (videoDevice) {
nsresult rv =
videoDevice->SetTrack(stream, kVideoTrack, principal);
if (NS_SUCCEEDED(rv)) {
rv = videoDevice->Start();
}
nsresult rv = videoDevice->Start();
if (NS_FAILED(rv)) {
if (audioDevice) {
if (NS_WARN_IF(NS_FAILED(audioDevice->Stop()))) {
@ -4167,9 +4170,6 @@ SourceListener::InitializeAsync() {
}
}
// Start() queued the tracks to be added synchronously to avoid
// races
stream->FinishAddTracks();
LOG("started all sources");
aHolder.Resolve(true, __func__);
})
@ -4193,15 +4193,8 @@ SourceListener::InitializeAsync() {
state->mTrackEnabled = true;
state->mTrackEnabledTime = TimeStamp::Now();
if (state->mDevice->GetMediaSource() !=
MediaSourceEnum::AudioCapture) {
// For AudioCapture mStream is a dummy stream, so we don't
// try to enable pulling - there won't be a track to enable
// it for.
mStream->SetPullingEnabled(state == mAudioDeviceState.get()
? kAudioTrack
: kVideoTrack,
true);
if (state == mVideoDeviceState.get()) {
mStream->SetPullingEnabled(kVideoTrack, true);
}
}
return SourceListenerPromise::CreateAndResolve(true, __func__);

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

@ -86,8 +86,8 @@ class MediaDevice : public nsIMediaDevice {
const MediaEnginePrefs& aPrefs,
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
const char** aOutBadConstraint);
nsresult SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal);
void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal);
nsresult Start();
nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
const MediaEnginePrefs& aPrefs,

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

@ -2543,10 +2543,6 @@ bool SourceMediaStream::PullNewData(GraphTime aDesiredUpToTime) {
// the stream at all.
StreamTime t = GraphTimeToStreamTime(aDesiredUpToTime);
StreamTime current = mTracks.GetEarliestTrackEnd();
LOG(LogLevel::Verbose,
("%p: Calling NotifyPull aStream=%p t=%f current end=%f", GraphImpl(),
this, GraphImpl()->MediaTimeToSeconds(t),
GraphImpl()->MediaTimeToSeconds(current)));
for (const TrackData& track : mUpdateTracks) {
if (!track.mPullingEnabled) {
continue;
@ -2558,6 +2554,10 @@ bool SourceMediaStream::PullNewData(GraphTime aDesiredUpToTime) {
if (t <= current) {
continue;
}
LOG(LogLevel::Verbose,
("%p: Calling NotifyPull stream=%p track=%d t=%f current end=%f",
GraphImpl(), this, track.mID, GraphImpl()->MediaTimeToSeconds(t),
GraphImpl()->MediaTimeToSeconds(current)));
MutexAutoUnlock unlock(mMutex);
for (TrackBound<MediaStreamTrackListener>& l : mTrackListeners) {
if (l.mTrackID == track.mID) {

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

@ -160,7 +160,7 @@ static void ReleaseFrame(layers::PlanarYCbCrData& aData) {
free(aData.mYChannel);
}
nsresult MediaEngineDefaultVideoSource::SetTrack(
void MediaEngineDefaultVideoSource::SetTrack(
const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) {
@ -177,7 +177,6 @@ nsresult MediaEngineDefaultVideoSource::SetTrack(
}
aStream->AddTrack(aTrackID, new VideoSegment(),
SourceMediaStream::ADDTRACK_QUEUED);
return NS_OK;
}
nsresult MediaEngineDefaultVideoSource::Start(
@ -424,7 +423,7 @@ nsresult MediaEngineDefaultAudioSource::Deallocate(
return NS_OK;
}
nsresult MediaEngineDefaultAudioSource::SetTrack(
void MediaEngineDefaultAudioSource::SetTrack(
const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) {
@ -439,7 +438,6 @@ nsresult MediaEngineDefaultAudioSource::SetTrack(
mTrackID = aTrackID;
aStream->AddAudioTrack(aTrackID, aStream->GraphRate(), new AudioSegment(),
SourceMediaStream::ADDTRACK_QUEUED);
return NS_OK;
}
nsresult MediaEngineDefaultAudioSource::Start(
@ -456,8 +454,16 @@ nsresult MediaEngineDefaultAudioSource::Start(
mSineGenerator = new SineWaveGenerator(mStream->GraphRate(), mFreq);
}
MutexAutoLock lock(mMutex);
mState = kStarted;
{
MutexAutoLock lock(mMutex);
mState = kStarted;
}
NS_DispatchToMainThread(
NS_NewRunnableFunction(__func__, [stream = mStream, track = mTrackID]() {
stream->SetPullingEnabled(track, true);
}));
return NS_OK;
}
@ -471,8 +477,15 @@ nsresult MediaEngineDefaultAudioSource::Stop(
MOZ_ASSERT(mState == kStarted);
MutexAutoLock lock(mMutex);
mState = kStopped;
{
MutexAutoLock lock(mMutex);
mState = kStopped;
}
NS_DispatchToMainThread(
NS_NewRunnableFunction(__func__, [stream = mStream, track = mTrackID]() {
stream->SetPullingEnabled(track, false);
}));
return NS_OK;
}

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

@ -47,9 +47,9 @@ class MediaEngineDefaultVideoSource : public MediaEngineSource {
const ipc::PrincipalInfo& aPrincipalInfo,
AllocationHandle** aOutHandle,
const char** aOutBadConstraint) override;
nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
void SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
nsresult Start(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Reconfigure(const RefPtr<AllocationHandle>& aHandle,
const dom::MediaTrackConstraints& aConstraints,
@ -114,9 +114,9 @@ class MediaEngineDefaultAudioSource : public MediaEngineSource {
const ipc::PrincipalInfo& aPrincipalInfo,
AllocationHandle** aOutHandle,
const char** aOutBadConstraint) override;
nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
void SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
nsresult Start(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Reconfigure(const RefPtr<AllocationHandle>& aHandle,
const dom::MediaTrackConstraints& aConstraints,

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

@ -259,7 +259,7 @@ nsresult MediaEngineRemoteVideoSource::Deallocate(
return NS_OK;
}
nsresult MediaEngineRemoteVideoSource::SetTrack(
void MediaEngineRemoteVideoSource::SetTrack(
const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) {
@ -285,7 +285,6 @@ nsresult MediaEngineRemoteVideoSource::SetTrack(
}
aStream->AddTrack(aTrackID, new VideoSegment(),
SourceMediaStream::ADDTRACK_QUEUED);
return NS_OK;
}
nsresult MediaEngineRemoteVideoSource::Start(

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

@ -124,9 +124,9 @@ class MediaEngineRemoteVideoSource : public MediaEngineSource,
AllocationHandle** aOutHandle,
const char** aOutBadConstraint) override;
nsresult Deallocate(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
void SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
nsresult Start(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Reconfigure(const RefPtr<AllocationHandle>& aHandle,
const dom::MediaTrackConstraints& aConstraints,

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

@ -145,10 +145,10 @@ class MediaEngineSourceInterface {
*
* This must be called before Start for the given AllocationHandle.
*/
virtual nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream,
TrackID aTrackID,
const PrincipalHandle& aPrincipal) = 0;
virtual void SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream,
TrackID aTrackID,
const PrincipalHandle& aPrincipal) = 0;
/**
* Called by MediaEngine to start feeding data to the track associated with
@ -156,6 +156,8 @@ class MediaEngineSourceInterface {
*
* If this is the first AllocationHandle to start, the underlying device
* will be started.
*
* NB: Audio sources handle the enabling of pulling themselves.
*/
virtual nsresult Start(const RefPtr<const AllocationHandle>& aHandle) = 0;
@ -204,6 +206,8 @@ class MediaEngineSourceInterface {
*
* Double-stopping a given allocation handle is allowed and will return NS_OK.
* This is necessary sometimes during shutdown.
*
* NB: Audio sources handle the disabling of pulling themselves.
*/
virtual nsresult Stop(const RefPtr<const AllocationHandle>& aHandle) = 0;

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

@ -193,7 +193,7 @@ nsresult MediaEngineTabVideoSource::Deallocate(
return NS_OK;
}
nsresult MediaEngineTabVideoSource::SetTrack(
void MediaEngineTabVideoSource::SetTrack(
const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const mozilla::PrincipalHandle& aPrincipal) {
@ -207,7 +207,6 @@ nsresult MediaEngineTabVideoSource::SetTrack(
mStream = aStream;
mTrackID = aTrackID;
mStream->AddTrack(mTrackID, new VideoSegment());
return NS_OK;
}
nsresult MediaEngineTabVideoSource::Start(

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

@ -30,9 +30,9 @@ class MediaEngineTabVideoSource : public MediaEngineSource {
AllocationHandle** aOutHandle,
const char** aOutBadConstraint) override;
nsresult Deallocate(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
void SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
nsresult Start(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Reconfigure(const RefPtr<AllocationHandle>& aHandle,
const dom::MediaTrackConstraints& aConstraints,

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

@ -203,9 +203,8 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAECSettings(
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
NS_DispatchToMainThread(
media::NewRunnableFrom([that, graph = std::move(gripGraph), aEnable,
aUseAecMobile, aLevel]() mutable {
NS_DispatchToMainThread(media::NewRunnableFrom(
[that, graph = std::move(gripGraph), aEnable, aUseAecMobile, aLevel]() {
class Message : public ControlMessage {
public:
Message(AudioInputProcessing* aInputProcessing, bool aEnable,
@ -243,7 +242,7 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAGCSettings(
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
NS_DispatchToMainThread(media::NewRunnableFrom(
[that, graph = std::move(gripGraph), aEnable, aMode]() mutable {
[that, graph = std::move(gripGraph), aEnable, aMode]() {
class Message : public ControlMessage {
public:
Message(AudioInputProcessing* aInputProcessing, bool aEnable,
@ -279,7 +278,7 @@ void MediaEngineWebRTCMicrophoneSource::UpdateNSSettings(
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
NS_DispatchToMainThread(media::NewRunnableFrom(
[that, graph = std::move(gripGraph), aEnable, aLevel]() mutable {
[that, graph = std::move(gripGraph), aEnable, aLevel]() {
class Message : public ControlMessage {
public:
Message(AudioInputProcessing* aInputProcessing, bool aEnable,
@ -314,9 +313,8 @@ void MediaEngineWebRTCMicrophoneSource::UpdateAPMExtraOptions(
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
NS_DispatchToMainThread(
media::NewRunnableFrom([that, graph = std::move(gripGraph),
aExtendedFilter, aDelayAgnostic]() mutable {
NS_DispatchToMainThread(media::NewRunnableFrom(
[that, graph = std::move(gripGraph), aExtendedFilter, aDelayAgnostic]() {
class Message : public ControlMessage {
public:
Message(AudioInputProcessing* aInputProcessing, bool aExtendedFilter,
@ -370,7 +368,7 @@ void MediaEngineWebRTCMicrophoneSource::ApplySettings(
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
RefPtr<MediaStreamGraphImpl> graphImpl = mStream->GraphImpl();
NS_DispatchToMainThread(media::NewRunnableFrom(
[that, graph = std::move(graphImpl), prefs = aPrefs]() mutable {
[that, graph = std::move(graphImpl), prefs = aPrefs]() {
that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
@ -428,14 +426,13 @@ nsresult MediaEngineWebRTCMicrophoneSource::Allocate(
}
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
NS_DispatchToMainThread(
media::NewRunnableFrom([that, prefs = outputPrefs]() mutable {
that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
that->mSettings->mChannelCount.Value() = prefs.mChannels;
return NS_OK;
}));
NS_DispatchToMainThread(media::NewRunnableFrom([that, prefs = outputPrefs]() {
that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
that->mSettings->mChannelCount.Value() = prefs.mChannels;
return NS_OK;
}));
mCurrentPrefs = outputPrefs;
@ -473,7 +470,7 @@ nsresult MediaEngineWebRTCMicrophoneSource::Deallocate(
NS_DispatchToMainThread(media::NewRunnableFrom(
[stream = std::move(sourceStream),
audioInputProcessing = std::move(inputProcessing),
trackID = mTrackID]() mutable {
trackID = mTrackID]() {
if (stream->IsDestroyed()) {
// This stream has already been destroyed on main thread by its
// DOMMediaStream. No cleanup left to do.
@ -503,7 +500,7 @@ nsresult MediaEngineWebRTCMicrophoneSource::Deallocate(
return NS_OK;
}
nsresult MediaEngineWebRTCMicrophoneSource::SetTrack(
void MediaEngineWebRTCMicrophoneSource::SetTrack(
const RefPtr<const AllocationHandle>&,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) {
@ -511,10 +508,6 @@ nsresult MediaEngineWebRTCMicrophoneSource::SetTrack(
MOZ_ASSERT(aStream);
MOZ_ASSERT(IsTrackIDExplicit(aTrackID));
if (mStream && mStream->Graph() != aStream->Graph()) {
return NS_ERROR_NOT_AVAILABLE;
}
MOZ_ASSERT(!mStream);
MOZ_ASSERT(mTrackID == TRACK_NONE);
MOZ_ASSERT(mPrincipal == PRINCIPAL_HANDLE_NONE);
@ -528,7 +521,6 @@ nsresult MediaEngineWebRTCMicrophoneSource::SetTrack(
SourceMediaStream::ADDTRACK_QUEUED);
LOG("Stream %p registered for microphone capture", aStream.get());
return NS_OK;
}
class StartStopMessage : public ControlMessage {
@ -579,14 +571,16 @@ nsresult MediaEngineWebRTCMicrophoneSource::Start(
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
NS_DispatchToMainThread(media::NewRunnableFrom(
[that, graph = std::move(gripGraph), deviceID]() mutable {
NS_DispatchToMainThread(
media::NewRunnableFrom([that, graph = std::move(gripGraph), deviceID,
stream = mStream, track = mTrackID]() {
if (graph) {
graph->AppendMessage(MakeUnique<StartStopMessage>(
that->mInputProcessing, StartStopMessage::Start));
}
that->mStream->OpenAudioInput(deviceID, that->mInputProcessing);
stream->OpenAudioInput(deviceID, that->mInputProcessing);
stream->SetPullingEnabled(track, true);
return NS_OK;
}));
@ -613,8 +607,9 @@ nsresult MediaEngineWebRTCMicrophoneSource::Stop(
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
NS_DispatchToMainThread(media::NewRunnableFrom(
[that, graph = std::move(gripGraph), stream = mStream]() mutable {
NS_DispatchToMainThread(
media::NewRunnableFrom([that, graph = std::move(gripGraph),
stream = mStream, track = mTrackID]() {
if (graph) {
graph->AppendMessage(MakeUnique<StartStopMessage>(
that->mInputProcessing, StartStopMessage::Stop));
@ -623,6 +618,7 @@ nsresult MediaEngineWebRTCMicrophoneSource::Stop(
CubebUtils::AudioDeviceID deviceID = that->mDeviceInfo->DeviceID();
Maybe<CubebUtils::AudioDeviceID> id = Some(deviceID);
stream->CloseAudioInput(id, that->mInputProcessing);
stream->SetPullingEnabled(track, false);
return NS_OK;
}));
@ -1164,13 +1160,12 @@ nsCString MediaEngineWebRTCAudioCaptureSource::GetUUID() const {
return nsCString(Substring(asciiString, 1, NSID_LENGTH - 3));
}
nsresult MediaEngineWebRTCAudioCaptureSource::SetTrack(
void MediaEngineWebRTCAudioCaptureSource::SetTrack(
const RefPtr<const AllocationHandle>&,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipalHandle) {
AssertIsOnOwningThread();
// Nothing to do here. aStream is a placeholder dummy and not exposed.
return NS_OK;
}
nsresult MediaEngineWebRTCAudioCaptureSource::Start(

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

@ -43,9 +43,9 @@ class MediaEngineWebRTCMicrophoneSource : public MediaEngineSource {
AllocationHandle** aOutHandle,
const char** aOutBadConstraint) override;
nsresult Deallocate(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
void SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
nsresult Start(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Stop(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Reconfigure(const RefPtr<AllocationHandle>& aHandle,
@ -269,9 +269,9 @@ class MediaEngineWebRTCAudioCaptureSource : public MediaEngineSource {
MOZ_ASSERT(!aHandle);
return NS_OK;
}
nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
void SetTrack(const RefPtr<const AllocationHandle>& aHandle,
const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
const PrincipalHandle& aPrincipal) override;
nsresult Start(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Stop(const RefPtr<const AllocationHandle>& aHandle) override;
nsresult Reconfigure(const RefPtr<AllocationHandle>& aHandle,

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

@ -1 +1 @@
4ff07fe75b0c28ee1987092b3eefed3017f5a25e
a5b036eced81dcfc012f1335277af595f931fb11

9
gfx/wr/Cargo.lock сгенерированный
Просмотреть файл

@ -1571,6 +1571,7 @@ dependencies = [
"thread_profiler 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_api 0.58.0",
"webrender_build 0.0.1",
"ws 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1607,6 +1608,14 @@ dependencies = [
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "webrender_build"
version = "0.0.1"
dependencies = [
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.8"

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

@ -16,7 +16,10 @@ capture = ["webrender_api/serialize", "ron", "serde", "debug_renderer"]
replay = ["webrender_api/deserialize", "ron", "serde"]
debug_renderer = []
pathfinder = ["pathfinder_font_renderer", "pathfinder_gfx_utils", "pathfinder_partitioner", "pathfinder_path_utils"]
serialize_program = ["serde"]
serialize_program = ["serde", "webrender_build/serialize_program"]
[build-dependencies]
webrender_build = { version = "0.0.1", path = "../webrender_build" }
[dependencies]
app_units = "0.7"
@ -42,6 +45,7 @@ smallvec = "0.6"
thread_profiler = "0.1.1"
time = "0.1"
webrender_api = { version = "0.58.0", path = "../webrender_api" }
webrender_build = { version = "0.0.1", path = "../webrender_build" }
ws = { optional = true, version = "0.7.3" }
[dependencies.pathfinder_font_renderer]

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

@ -2,36 +2,63 @@
* 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/. */
extern crate webrender_build;
use std::borrow::Cow;
use std::env;
use std::fs::{canonicalize, read_dir, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use webrender_build::shader::*;
fn write_shaders(glsl_files: Vec<PathBuf>, shader_file_path: &Path) {
let mut shader_file = File::create(shader_file_path).unwrap();
write!(shader_file, "/// AUTO GENERATED BY build.rs\n\n").unwrap();
write!(shader_file, "use std::collections::HashMap;\n").unwrap();
write!(shader_file, "use std::collections::HashMap;\n\n").unwrap();
write!(shader_file, "pub struct SourceWithDigest {{ pub source: &'static str, pub digest: &'static str }}\n\n")
.unwrap();
write!(shader_file, "lazy_static! {{\n").unwrap();
write!(
shader_file,
" pub static ref SHADERS: HashMap<&'static str, &'static str> = {{\n"
" pub static ref SHADERS: HashMap<&'static str, SourceWithDigest> = {{\n"
).unwrap();
write!(shader_file, " let mut h = HashMap::new();\n").unwrap();
for glsl in glsl_files {
// Compute the shader name.
assert!(glsl.is_file());
let shader_name = glsl.file_name().unwrap().to_str().unwrap();
// strip .glsl
let shader_name = shader_name.replace(".glsl", "");
// Compute a digest of the #include-expanded shader source. We store
// this as a literal alongside the source string so that we don't need
// to hash large strings at runtime.
let mut hasher = Sha256::new();
let base = glsl.parent().unwrap();
assert!(base.is_dir());
parse_shader_source(
Cow::Owned(shader_source_from_file(&glsl)),
&|f| Cow::Owned(shader_source_from_file(&base.join(&format!("{}.glsl", f)))),
&mut |s| hasher.input(s.as_bytes()),
);
let digest: ProgramSourceDigest = hasher.into();
// Compute the shader path for insertion into the include_str!() macro.
// This makes for more compact generated code than inserting the literal
// shader source into the generated file.
//
// If someone is building on a network share, I'm sorry.
let full_path = canonicalize(&glsl).unwrap();
let full_name = full_path.as_os_str().to_str().unwrap();
// if someone is building on a network share, I'm sorry.
let full_name = full_name.replace("\\\\?\\", "");
let full_name = full_name.replace("\\", "/");
write!(
shader_file,
" h.insert(\"{}\", include_str!(\"{}\"));\n",
" h.insert(\"{}\", SourceWithDigest {{ source: include_str!(\"{}\"), digest: \"{}\"}});\n",
shader_name,
full_name
full_name,
digest,
).unwrap();
}
write!(shader_file, " h\n").unwrap();

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

@ -2,7 +2,7 @@
* 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/. */
use super::super::shader_source;
use super::super::shader_source::SHADERS;
use api::{ColorF, ImageFormat, MemoryReport};
use api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
use api::TextureTarget;
@ -19,8 +19,6 @@ use std::borrow::Cow;
use std::cell::{Cell, RefCell};
use std::cmp;
use std::collections::hash_map::Entry;
use std::fs::File;
use std::io::Read;
use std::marker::PhantomData;
use std::mem;
use std::os::raw::c_void;
@ -32,6 +30,8 @@ use std::slice;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::thread;
use webrender_build::shader::ProgramSourceDigest;
use webrender_build::shader::{parse_shader_source, shader_source_from_file};
/// Sequence number for frames, as tracked by the device layer.
#[derive(Debug, Copy, Clone, PartialEq, Ord, Eq, PartialOrd)]
@ -82,7 +82,6 @@ const SHADER_VERSION_GLES: &str = "#version 300 es\n";
const SHADER_KIND_VERTEX: &str = "#define WR_VERTEX_SHADER\n";
const SHADER_KIND_FRAGMENT: &str = "#define WR_FRAGMENT_SHADER\n";
const SHADER_IMPORT: &str = "#include ";
pub struct TextureSlot(pub usize);
@ -184,41 +183,17 @@ fn get_shader_version(gl: &gl::Gl) -> &'static str {
// Get a shader string by name, from the built in resources or
// an override path, if supplied.
fn get_shader_source(shader_name: &str, base_path: Option<&PathBuf>) -> Option<Cow<'static, str>> {
fn get_shader_source(shader_name: &str, base_path: Option<&PathBuf>) -> Cow<'static, str> {
if let Some(ref base) = base_path {
let shader_path = base.join(&format!("{}.glsl", shader_name));
if shader_path.exists() {
let mut source = String::new();
File::open(&shader_path)
.unwrap()
.read_to_string(&mut source)
.unwrap();
return Some(Cow::Owned(source));
}
}
shader_source::SHADERS
.get(shader_name)
.map(|s| Cow::Borrowed(*s))
}
// Parse a shader string for imports. Imports are recursively processed, and
// prepended to the output stream.
fn parse_shader_source<F: FnMut(&str)>(source: Cow<'static, str>, base_path: Option<&PathBuf>, output: &mut F) {
for line in source.lines() {
if line.starts_with(SHADER_IMPORT) {
let imports = line[SHADER_IMPORT.len() ..].split(',');
// For each import, get the source, and recurse.
for import in imports {
if let Some(include) = get_shader_source(import, base_path) {
parse_shader_source(include, base_path, output);
}
}
} else {
output(line);
output("\n");
}
Cow::Owned(shader_source_from_file(&shader_path))
} else {
Cow::Borrowed(
SHADERS
.get(shader_name)
.expect("Shader not found")
.source
)
}
}
@ -263,6 +238,19 @@ fn do_build_shader_string<F: FnMut(&str)>(
base_filename: &str,
override_path: Option<&PathBuf>,
mut output: F,
) {
build_shader_prefix_string(gl_version_string, features, kind, base_filename, &mut output);
build_shader_main_string(base_filename, override_path, &mut output);
}
/// Walks the prefix section of the shader string, which manages the various
/// defines for features etc.
fn build_shader_prefix_string<F: FnMut(&str)>(
gl_version_string: &str,
features: &str,
kind: &str,
base_filename: &str,
output: &mut F,
) {
// GLSL requires that the version number comes first.
output(gl_version_string);
@ -276,12 +264,16 @@ fn do_build_shader_string<F: FnMut(&str)>(
// Add any defines that were passed by the caller.
output(features);
}
// Parse the main .glsl file, including any imports
// and append them to the list of sources.
if let Some(shared_source) = get_shader_source(base_filename, override_path) {
parse_shader_source(shared_source, override_path, &mut output);
}
/// Walks the main .glsl file, including any imports.
fn build_shader_main_string<F: FnMut(&str)>(
base_filename: &str,
override_path: Option<&PathBuf>,
output: &mut F,
) {
let shared_source = get_shader_source(base_filename, override_path);
parse_shader_source(shared_source, &|f| get_shader_source(f, override_path), output);
}
pub trait FileWatcherHandler: Send {
@ -691,19 +683,6 @@ pub struct VBOId(gl::GLuint);
#[derive(PartialEq, Eq, Hash, Debug, Copy, Clone)]
struct IBOId(gl::GLuint);
#[derive(PartialEq, Eq, Hash, Debug, Clone, Default)]
#[cfg_attr(feature = "serialize_program", derive(Deserialize, Serialize))]
pub struct ProgramSourceDigest([u8; 32]);
impl ::std::fmt::Display for ProgramSourceDigest {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
for byte in self.0.iter() {
f.write_fmt(format_args!("{:02x}", byte))?;
}
Ok(())
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct ProgramSourceInfo {
base_filename: &'static str,
@ -714,7 +693,7 @@ pub struct ProgramSourceInfo {
impl ProgramSourceInfo {
fn new(
device: &Device,
base_filename: &'static str,
name: &'static str,
features: String,
) -> Self {
// Compute the digest. Assuming the device has a `ProgramCache`, this
@ -722,37 +701,49 @@ impl ProgramSourceInfo {
// we compute the hash by walking the static strings in the same order
// as we would when concatenating the source, to avoid heap-allocating
// in the common case.
//
// Note that we cheat a bit to make the hashing more efficient. First,
// the only difference between the vertex and fragment shader is a
// single deterministic define, so we don't need to hash both. Second,
// we precompute the digest of the expanded source file at build time,
// and then just hash that digest here.
// Construct the hasher.
// Setup.
let mut hasher = Sha256::new();
let version_str = get_shader_version(&*device.gl());
let override_path = device.resource_override_path.as_ref();
let source_and_digest = SHADERS.get(&name).expect("Shader not found");
// Hash the renderer name.
hasher.input(device.renderer_name.as_bytes());
// Hash the vertex shader.
device.build_shader_string(
// Hash the prefix string.
build_shader_prefix_string(
version_str,
&features,
SHADER_KIND_VERTEX,
&base_filename,
|s| hasher.input(s.as_bytes()),
&"DUMMY",
&name,
&mut |s| hasher.input(s.as_bytes()),
);
// Hash the fragment shader.
device.build_shader_string(
&features,
SHADER_KIND_FRAGMENT,
base_filename,
|s| hasher.input(s.as_bytes()),
);
// Hash the shader file contents. We use a precomputed digest, and
// verify it in debug builds.
if override_path.is_some() || cfg!(debug_assertions) {
let mut h = Sha256::new();
build_shader_main_string(&name, override_path, &mut |s| h.input(s.as_bytes()));
let d: ProgramSourceDigest = h.into();
let digest = format!("{}", d);
debug_assert!(override_path.is_some() || digest == source_and_digest.digest);
hasher.input(digest.as_bytes());
} else {
hasher.input(source_and_digest.digest.as_bytes());
};
// Finish.
let mut digest = ProgramSourceDigest::default();
digest.0.copy_from_slice(hasher.result().as_slice());
ProgramSourceInfo {
base_filename,
base_filename: name,
features,
digest,
digest: hasher.into(),
}
}

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

@ -194,6 +194,7 @@ extern crate png;
extern crate rand;
pub extern crate webrender_api;
extern crate webrender_build;
#[doc(hidden)]
pub use device::{build_shader_strings, ReadPixelsFormat, UploadMethod, VertexUsageHint};

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

@ -0,0 +1,13 @@
[package]
name = "webrender_build"
version = "0.0.1"
license = "MPL-2.0"
repository = "https://github.com/servo/webrender"
description = "Code shared between precompilation (build.rs) and the rest of WebRender"
[features]
serialize_program = ["serde"]
[dependencies]
serde = { optional = true, version = "1.0", features = ["serde_derive"] }
sha2 = "0.8"

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

@ -0,0 +1,11 @@
/* 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/. */
#[cfg(any(feature = "serde"))]
#[macro_use]
extern crate serde;
extern crate sha2;
pub mod shader;

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

@ -0,0 +1,71 @@
/* 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/. */
//! Functionality for managing source code for shaders.
//!
//! This module is used during precompilation (build.rs) and regular compilation,
//! so it has minimal dependencies.
pub use sha2::{Digest, Sha256};
use std::borrow::Cow;
use std::fs::File;
use std::io::Read;
use std::path::Path;
#[derive(PartialEq, Eq, Hash, Debug, Clone, Default)]
#[cfg_attr(feature = "serialize_program", derive(Deserialize, Serialize))]
pub struct ProgramSourceDigest([u8; 32]);
impl ::std::fmt::Display for ProgramSourceDigest {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
for byte in self.0.iter() {
f.write_fmt(format_args!("{:02x}", byte))?;
}
Ok(())
}
}
impl From<Sha256> for ProgramSourceDigest {
fn from(hasher: Sha256) -> Self {
let mut digest = Self::default();
digest.0.copy_from_slice(hasher.result().as_slice());
digest
}
}
const SHADER_IMPORT: &str = "#include ";
/// Parses a shader string for imports. Imports are recursively processed, and
/// prepended to the output stream.
pub fn parse_shader_source<F: FnMut(&str), G: Fn(&str) -> Cow<'static, str>>(
source: Cow<'static, str>,
get_source: &G,
output: &mut F,
) {
for line in source.lines() {
if line.starts_with(SHADER_IMPORT) {
let imports = line[SHADER_IMPORT.len() ..].split(',');
// For each import, get the source, and recurse.
for import in imports {
let include = get_source(import);
parse_shader_source(include, get_source, output);
}
} else {
output(line);
output("\n");
}
}
}
/// Reads a shader source file from disk into a String.
pub fn shader_source_from_file(shader_path: &Path) -> String {
assert!(shader_path.exists(), "Shader not found");
let mut source = String::new();
File::open(&shader_path)
.expect("Shader not found")
.read_to_string(&mut source)
.unwrap();
source
}

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

@ -41,6 +41,13 @@ if CONFIG['CPU_ARCH'] == 'arm':
'arm/filter_neon.S'
]
if CONFIG['CPU_ARCH'] == 'aarch64' and CONFIG['CC_TYPE'] in ('clang', 'gcc'):
DEFINES['MOZ_PNG_USE_ARM_NEON'] = True
UNIFIED_SOURCES += [
'arm/arm_init.c',
'arm/filter_neon_intrinsics.c'
]
if CONFIG['INTEL_ARCHITECTURE']:
DEFINES['MOZ_PNG_USE_INTEL_SSE'] = True
UNIFIED_SOURCES += [

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

@ -285,8 +285,8 @@ static GtkWindow *GetGtkWindow(dom::Document *aDocument) {
NS_IMETHODIMP
nsDragService::InvokeDragSession(
nsINode *aDOMNode, const nsACString &aPrincipalURISpec,
nsIArray *aArrayTransferables, uint32_t aActionType,
nsINode *aDOMNode, nsIPrincipal *aPrincipal, nsIArray *aArrayTransferables,
uint32_t aActionType,
nsContentPolicyType aContentPolicyType = nsIContentPolicy::TYPE_OTHER) {
MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::InvokeDragSession"));
@ -296,7 +296,7 @@ nsDragService::InvokeDragSession(
// know whether or not the drag succeeded.
if (mSourceNode) return NS_ERROR_NOT_AVAILABLE;
return nsBaseDragService::InvokeDragSession(aDOMNode, aPrincipalURISpec,
return nsBaseDragService::InvokeDragSession(aDOMNode, aPrincipal,
aArrayTransferables, aActionType,
aContentPolicyType);
}

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

@ -63,8 +63,7 @@ class nsDragService final : public nsBaseDragService, public nsIObserver {
const mozilla::Maybe<mozilla::CSSIntRegion> &aRegion,
uint32_t aActionType) override;
// nsIDragService
NS_IMETHOD InvokeDragSession(nsINode *aDOMNode,
const nsACString &aPrincipalURISpec,
NS_IMETHOD InvokeDragSession(nsINode *aDOMNode, nsIPrincipal *aPrincipal,
nsIArray *anArrayTransferables,
uint32_t aActionType,
nsContentPolicyType aContentPolicyType) override;

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

@ -150,16 +150,14 @@ nsBaseDragService::GetSourceNode(nsINode** aSourceNode) {
}
NS_IMETHODIMP
nsBaseDragService::GetTriggeringPrincipalURISpec(
nsACString& aPrincipalURISpec) {
aPrincipalURISpec = mTriggeringPrincipalURISpec;
nsBaseDragService::GetTriggeringPrincipal(nsIPrincipal** aPrincipal) {
NS_IF_ADDREF(*aPrincipal = mTriggeringPrincipal);
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::SetTriggeringPrincipalURISpec(
const nsACString& aPrincipalURISpec) {
mTriggeringPrincipalURISpec = aPrincipalURISpec;
nsBaseDragService::SetTriggeringPrincipal(nsIPrincipal* aPrincipal) {
mTriggeringPrincipal = aPrincipal;
return NS_OK;
}
@ -201,8 +199,8 @@ void nsBaseDragService::SetDataTransfer(DataTransfer* aDataTransfer) {
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::InvokeDragSession(
nsINode* aDOMNode, const nsACString& aPrincipalURISpec,
nsIArray* aTransferableArray, uint32_t aActionType,
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIArray* aTransferableArray,
uint32_t aActionType,
nsContentPolicyType aContentPolicyType = nsIContentPolicy::TYPE_OTHER) {
AUTO_PROFILER_LABEL("nsBaseDragService::InvokeDragSession", OTHER);
@ -211,7 +209,7 @@ nsBaseDragService::InvokeDragSession(
// stash the document of the dom node
mSourceDocument = aDOMNode->OwnerDoc();
mTriggeringPrincipalURISpec.Assign(aPrincipalURISpec);
mTriggeringPrincipal = aPrincipal;
mSourceNode = aDOMNode;
mContentPolicyType = aContentPolicyType;
mEndDragPoint = LayoutDeviceIntPoint(0, 0);
@ -247,10 +245,9 @@ nsBaseDragService::InvokeDragSession(
NS_IMETHODIMP
nsBaseDragService::InvokeDragSessionWithImage(
nsINode* aDOMNode, const nsACString& aPrincipalURISpec,
nsIArray* aTransferableArray, uint32_t aActionType, nsINode* aImage,
int32_t aImageX, int32_t aImageY, DragEvent* aDragEvent,
DataTransfer* aDataTransfer) {
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIArray* aTransferableArray,
uint32_t aActionType, nsINode* aImage, int32_t aImageX, int32_t aImageY,
DragEvent* aDragEvent, DataTransfer* aDataTransfer) {
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aDataTransfer, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
@ -286,17 +283,19 @@ nsBaseDragService::InvokeDragSessionWithImage(
#endif
nsresult rv =
InvokeDragSession(aDOMNode, aPrincipalURISpec, aTransferableArray,
aActionType, nsIContentPolicy::TYPE_INTERNAL_IMAGE);
InvokeDragSession(aDOMNode, aPrincipal, aTransferableArray, aActionType,
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
mRegion = Nothing();
return rv;
}
NS_IMETHODIMP
nsBaseDragService::InvokeDragSessionWithSelection(
Selection* aSelection, const nsACString& aPrincipalURISpec,
nsIArray* aTransferableArray, uint32_t aActionType, DragEvent* aDragEvent,
DataTransfer* aDataTransfer) {
nsBaseDragService::InvokeDragSessionWithSelection(Selection* aSelection,
nsIPrincipal* aPrincipal,
nsIArray* aTransferableArray,
uint32_t aActionType,
DragEvent* aDragEvent,
DataTransfer* aDataTransfer) {
NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
@ -318,8 +317,8 @@ nsBaseDragService::InvokeDragSessionWithSelection(
// endpoints of the selection
nsCOMPtr<nsINode> node = aSelection->GetFocusNode();
return InvokeDragSession(node, aPrincipalURISpec, aTransferableArray,
aActionType, nsIContentPolicy::TYPE_OTHER);
return InvokeDragSession(node, aPrincipal, aTransferableArray, aActionType,
nsIContentPolicy::TYPE_OTHER);
}
//-------------------------------------------------------------------------
@ -414,7 +413,7 @@ nsBaseDragService::EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) {
// release the source we've been holding on to.
mSourceDocument = nullptr;
mSourceNode = nullptr;
mTriggeringPrincipalURISpec.Truncate(0);
mTriggeringPrincipal = nullptr;
mSelection = nullptr;
mDataTransfer = nullptr;
mHasImage = false;

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

@ -159,7 +159,7 @@ class nsBaseDragService : public nsIDragService, public nsIDragSession {
uint32_t mDragActionFromChildProcess;
nsCOMPtr<nsINode> mSourceNode;
nsCString mTriggeringPrincipalURISpec;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
// the document at the drag source. will be null if it came from outside the
// app.

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

@ -27,22 +27,6 @@ nsDragServiceProxy::nsDragServiceProxy() {}
nsDragServiceProxy::~nsDragServiceProxy() {}
static void GetPrincipalURIFromNode(nsCOMPtr<nsINode>& sourceNode,
nsCString& aPrincipalURISpec) {
if (!sourceNode) {
return;
}
nsCOMPtr<nsIPrincipal> principal = sourceNode->NodePrincipal();
nsCOMPtr<nsIURI> principalURI;
nsresult rv = principal->GetURI(getter_AddRefs(principalURI));
if (NS_FAILED(rv) || !principalURI) {
return;
}
principalURI->GetSpec(aPrincipalURISpec);
}
nsresult nsDragServiceProxy::InvokeDragSessionImpl(
nsIArray* aArrayTransferables, const Maybe<CSSIntRegion>& aRegion,
uint32_t aActionType) {
@ -53,8 +37,10 @@ nsresult nsDragServiceProxy::InvokeDragSessionImpl(
nsContentUtils::TransferablesToIPCTransferables(
aArrayTransferables, dataTransfers, false, child->Manager(), nullptr);
nsCString principalURISpec;
GetPrincipalURIFromNode(mSourceNode, principalURISpec);
nsCOMPtr<nsIPrincipal> principal;
if (mSourceNode) {
principal = mSourceNode->NodePrincipal();
}
LayoutDeviceIntRect dragRect;
if (mHasImage || mSelection) {
@ -83,7 +69,7 @@ nsresult nsDragServiceProxy::InvokeDragSessionImpl(
mozilla::Unused << child->SendInvokeDragSession(
dataTransfers, aActionType, surfaceData, stride,
dataSurface->GetFormat(), dragRect, principalURISpec);
dataSurface->GetFormat(), dragRect, IPC::Principal(principal));
StartDragSession();
return NS_OK;
}
@ -92,7 +78,7 @@ nsresult nsDragServiceProxy::InvokeDragSessionImpl(
mozilla::Unused << child->SendInvokeDragSession(
dataTransfers, aActionType, mozilla::void_t(), 0,
static_cast<SurfaceFormat>(0), dragRect, principalURISpec);
static_cast<SurfaceFormat>(0), dragRect, IPC::Principal(principal));
StartDragSession();
return NS_OK;
}

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

@ -42,8 +42,8 @@ interface nsIDragService : nsISupports
*
* Note: This method is deprecated for non-native code.
*
* @param aPrincipalURISpec - the URI of the triggering principal of the
* drag, or an empty string if it's from browser chrome or OS
* @param aPrincipal - the triggering principal of the drag, or null if
* it's from browser chrome or OS
* @param aTransferables - an array of transferables to be dragged
* @param aActionType - specified which of copy/move/link are allowed
* @param aContentPolicyType - the contentPolicyType that will be
@ -51,7 +51,7 @@ interface nsIDragService : nsISupports
* (defaults to TYPE_OTHER)
*/
void invokeDragSession (in Node aDOMNode,
in AUTF8String aPrincipalURISpec,
in nsIPrincipal aPrincipal,
in nsIArray aTransferables,
in unsigned long aActionType,
[optional] in nsContentPolicyType aContentPolicyType);
@ -85,7 +85,7 @@ interface nsIDragService : nsISupports
*/
[noscript]
void invokeDragSessionWithImage(in Node aDOMNode,
in AUTF8String aPrincipalURISpec,
in nsIPrincipal aPrincipal,
in nsIArray aTransferableArray,
in unsigned long aActionType,
in Node aImage,
@ -102,7 +102,7 @@ interface nsIDragService : nsISupports
* Note: This method is deprecated for non-native code.
*/
void invokeDragSessionWithSelection(in Selection aSelection,
in AUTF8String aPrincipalURISpec,
in nsIPrincipal aPrincipal,
in nsIArray aTransferableArray,
in unsigned long aActionType,
in DragEvent aDragEvent,

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

@ -56,11 +56,11 @@ interface nsIDragSession : nsISupports
readonly attribute Node sourceNode;
/**
* The URI spec of the triggering principal. This may be different than
* sourceNode's principal when sourceNode is xul:browser and the drag is
* the triggering principal. This may be different than sourceNode's
* principal when sourceNode is xul:browser and the drag is
* triggered in a browsing context inside it.
*/
attribute AUTF8String triggeringPrincipalURISpec;
attribute nsIPrincipal triggeringPrincipal;
/**
* The data transfer object for the current drag.