mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1774300 - Implement VideoColorSpace r=padenot,jgilbert
This patch implements the VideoColorSpace created in D144771. Depends on D144772 Differential Revision: https://phabricator.services.mozilla.com/D145395
This commit is contained in:
parent
aa78f11d8d
commit
c608970241
@ -314,6 +314,7 @@ const extraMochitestTestPaths = [
|
||||
"dom/media/mediasession/test/",
|
||||
"dom/media/mediasource/test/",
|
||||
"dom/media/test/",
|
||||
"dom/media/webcodecs/test/",
|
||||
"dom/media/webspeech/recognition/test/",
|
||||
"dom/media/webspeech/synth/test/",
|
||||
"dom/messagechannel/tests/",
|
||||
|
@ -6,11 +6,12 @@
|
||||
|
||||
#include "mozilla/dom/VideoColorSpace.h"
|
||||
#include "mozilla/dom/VideoColorSpaceBinding.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
// Only needed for refcounted objects.
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(VideoColorSpace)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VideoColorSpace, mParent)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(VideoColorSpace)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(VideoColorSpace)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VideoColorSpace)
|
||||
@ -18,47 +19,30 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VideoColorSpace)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
VideoColorSpace::VideoColorSpace() {
|
||||
// Add |MOZ_COUNT_CTOR(VideoColorSpace);| for a non-refcounted object.
|
||||
VideoColorSpace::VideoColorSpace(nsIGlobalObject* aParent,
|
||||
const VideoColorSpaceInit& aInit)
|
||||
: mParent(aParent), mInit(aInit) {
|
||||
MOZ_ASSERT(mParent);
|
||||
}
|
||||
|
||||
VideoColorSpace::~VideoColorSpace() {
|
||||
// Add |MOZ_COUNT_DTOR(VideoColorSpace);| for a non-refcounted object.
|
||||
}
|
||||
|
||||
// Add to make it buildable.
|
||||
nsIGlobalObject* VideoColorSpace::GetParentObject() const { return nullptr; }
|
||||
nsIGlobalObject* VideoColorSpace::GetParentObject() const { return mParent; }
|
||||
|
||||
JSObject* VideoColorSpace::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return VideoColorSpace_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
// The followings are added to make it buildable.
|
||||
|
||||
/* static */
|
||||
already_AddRefed<VideoColorSpace> VideoColorSpace::Constructor(
|
||||
const GlobalObject& global, const VideoColorSpaceInit& init,
|
||||
const GlobalObject& aGlobal, const VideoColorSpaceInit& aInit,
|
||||
ErrorResult& aRv) {
|
||||
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
return nullptr;
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<VideoColorSpace> videoColorSpace(new VideoColorSpace(global, aInit));
|
||||
return aRv.Failed() ? nullptr : videoColorSpace.forget();
|
||||
}
|
||||
|
||||
Nullable<VideoColorPrimaries> VideoColorSpace::GetPrimaries() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Nullable<VideoTransferCharacteristics> VideoColorSpace::GetTransfer() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Nullable<VideoMatrixCoefficients> VideoColorSpace::GetMatrix() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Nullable<bool> VideoColorSpace::GetFullRange() const { return nullptr; }
|
||||
|
||||
void VideoColorSpace::ToJSON(JSContext* cx,
|
||||
JS::MutableHandle<JSObject*> aRetVal) {}
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
@ -11,40 +11,33 @@
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/VideoColorSpaceBinding.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsIGlobalObject; // Add to make it buildable.
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
enum class VideoColorPrimaries : uint8_t; // Add to make it buildable.
|
||||
enum class VideoTransferCharacteristics : uint8_t; // Add to make it buildable.
|
||||
enum class VideoMatrixCoefficients : uint8_t; // Add to make it buildable.
|
||||
struct VideoColorSpaceInit; // Add to make it buildable.
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
class nsIGlobalObject;
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
class VideoColorSpace final
|
||||
: public nsISupports /* or NonRefcountedDOMObject if this is a
|
||||
non-refcounted object */
|
||||
,
|
||||
public nsWrapperCache /* Change wrapperCache in the binding configuration
|
||||
if you don't want this */
|
||||
{
|
||||
class VideoColorSpace final : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(VideoColorSpace)
|
||||
|
||||
public:
|
||||
VideoColorSpace();
|
||||
VideoColorSpace(nsIGlobalObject* aParent, const VideoColorSpaceInit& aInit);
|
||||
|
||||
protected:
|
||||
~VideoColorSpace();
|
||||
~VideoColorSpace() = default;
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
static Nullable<T> ToNullable(const Optional<T>& aInput) {
|
||||
if (aInput.WasPassed()) {
|
||||
return Nullable<T>(aInput.Value());
|
||||
}
|
||||
return Nullable<T>();
|
||||
}
|
||||
|
||||
public:
|
||||
// This should return something that eventually allows finding a
|
||||
@ -56,18 +49,26 @@ class VideoColorSpace final
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
static already_AddRefed<VideoColorSpace> Constructor(
|
||||
const GlobalObject& global, const VideoColorSpaceInit& init,
|
||||
const GlobalObject& aGlobal, const VideoColorSpaceInit& aInit,
|
||||
ErrorResult& aRv);
|
||||
|
||||
Nullable<VideoColorPrimaries> GetPrimaries() const;
|
||||
Nullable<VideoColorPrimaries> GetPrimaries() const {
|
||||
return ToNullable(mInit.mPrimaries);
|
||||
}
|
||||
|
||||
Nullable<VideoTransferCharacteristics> GetTransfer() const;
|
||||
Nullable<VideoTransferCharacteristics> GetTransfer() const {
|
||||
return ToNullable(mInit.mTransfer);
|
||||
}
|
||||
|
||||
Nullable<VideoMatrixCoefficients> GetMatrix() const;
|
||||
Nullable<VideoMatrixCoefficients> GetMatrix() const {
|
||||
return ToNullable(mInit.mMatrix);
|
||||
}
|
||||
|
||||
Nullable<bool> GetFullRange() const;
|
||||
Nullable<bool> GetFullRange() const { return ToNullable(mInit.mFullRange); }
|
||||
|
||||
void ToJSON(JSContext* cx, JS::MutableHandle<JSObject*> aRetVal);
|
||||
private:
|
||||
nsCOMPtr<nsIGlobalObject> mParent;
|
||||
const VideoColorSpaceInit mInit;
|
||||
};
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
@ -4,6 +4,8 @@
|
||||
# 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/.
|
||||
|
||||
MOCHITEST_MANIFESTS += ["test/mochitest.ini"]
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
"VideoColorSpace.h",
|
||||
"VideoFrame.h",
|
||||
|
7
dom/media/webcodecs/test/mochitest.ini
Normal file
7
dom/media/webcodecs/test/mochitest.ini
Normal file
@ -0,0 +1,7 @@
|
||||
[DEFAULT]
|
||||
subsuite = media
|
||||
tags = webcodecs
|
||||
prefs =
|
||||
dom.media.webcodecs.enabled=true
|
||||
|
||||
[test_videoColorSpace.html]
|
63
dom/media/webcodecs/test/test_videoColorSpace.html
Normal file
63
dom/media/webcodecs/test/test_videoColorSpace.html
Normal file
@ -0,0 +1,63 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
let defaultVideoColorSpaceInit = {
|
||||
primaries: "bt709",
|
||||
transfer: "bt709",
|
||||
matrix: "bt709",
|
||||
fullRange: true,
|
||||
};
|
||||
let VCSIs = generateAllCombinations(defaultVideoColorSpaceInit);
|
||||
for (let VCSI of VCSIs) {
|
||||
check(VCSI);
|
||||
}
|
||||
|
||||
function generateAllCombinations(obj) {
|
||||
let keySets = getAllSubsets(Object.keys(obj));
|
||||
let combinations = [];
|
||||
for (let set of keySets) {
|
||||
let element = {};
|
||||
for (let key of set) {
|
||||
element[key] = obj[key];
|
||||
}
|
||||
combinations.push(element);
|
||||
}
|
||||
return combinations;
|
||||
}
|
||||
|
||||
function getAllSubsets(set) {
|
||||
let sebsets = [];
|
||||
let upperbound = 1 << set.length;
|
||||
for (let bitmask = 0; bitmask < upperbound; ++bitmask) {
|
||||
let subset = [];
|
||||
for (let i = 0; i < set.length; ++i) {
|
||||
if (bitmask & (1 << i)) {
|
||||
subset.push(set[i]);
|
||||
}
|
||||
}
|
||||
sebsets.push(subset);
|
||||
}
|
||||
return sebsets;
|
||||
}
|
||||
|
||||
function check(VCSI) {
|
||||
let vcs = new VideoColorSpace(VCSI);
|
||||
let json = vcs.toJSON();
|
||||
const VCSIKeys = Object.keys(VCSI);
|
||||
for (const k of Object.keys(json)) {
|
||||
is(
|
||||
json[k],
|
||||
VCSIKeys.includes(k) ? VCSI[k] : null,
|
||||
"VideoColorSpace.ToJSON()'s property should match the given VideoColorSpaceInit's one"
|
||||
);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user