Files
roytam1 886c0a2723 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1215411 - Define MOZ_FALLTHROUGH annotation to suppress clang's -Wimplicit-fallthrough warnings. r=botond (5549d55e8b)
- Bug 1202794 - Explicitly clear array in SortChildrenBy3DZOrder to satisfy the move analysis, r=mattwoodrow (0c53a3db36)
- Bug 1217168 - Respect layer clip rects during plugin visibility computation. r=jimm (6289d35ff1)
- Bug 1220693 - Make mozilla::Atomic<enum class> work even on compilers that don't have <atomic>. r=froydnj (ef1b490ffd)
- Bug 947062 - Make background-position inline-style changes and CSS animations trigger layer activity. r=roc (44bc576960)
- Bug 1201330 - Refactor LayerActivity property management. r=roc (92528b8765)
- Bug 1201330 - Keep scroll handler induced layer activity active until the scroll frame becomes inactive. r=roc (08670902ec)
- Bug 1147707 - Intersect correctly in DisplayItemClip::ApplyNonRoundedIntersection. r=roc (66991b6be6)
- better attempt at 10.5 compaitbility, avoiding out-of-bounds array access (18f481ff6b)
- Bug 1217662 - part 1 - make LayerManagerUserDataDestroy a static function of LayerManager; r=mattwoodrow (f2d34451e0)
- Bug 1217662 - part 2 - move mozilla::layers::LayerUserData to a separate header; r=mattwoodrow (036d7327fa)
- Bug 1217662 - part 3 - move nsDisplayBlendContainer::GetLayerState out-of-line; r=mattwoodrow (fb2bd6bd20)
- Bug 1217662 - part 4 - move {LayerManager,Layer}::RemoveUserData out-of-line; r=mattwoodrow (86836f2a9b)
- Bug 1217662 - part 5 - move FrameLayerBuilder and helper classes's ctors/dtors out-of-line; r=mattwoodrow (e838bde0ec)
- Bug 1217662 - part 6 - remove Layers.h #include from FrameListBuilder.h; r=mattwoodrow (8aea4cb842)
- Bug 1216288 - Disable warning when we don't build an active layer for RenderFrameParent within an opacity:0 subtree. r=roc (2c5e70760a)
- Bug 1169996 - Don't lose eEditorMailMask; r=ehsan (b4647557bb)
- Bug 1211654 - Force opacity layers that were only created for APZ hit-testing information to always be inactive. r=mstange (4c56d440cf)
- Bug 1154336 - Convert nsTextEditorState::mRestoringSelection into a strong reference; r=baku (3e24a6ad18)
- Bug 549674 part.1 Commit composition string at setting value of <input> or <textarea> r=smaug (e6a6471370)
- Bug 1109410 Resolve CSS transform in ContentEventHandler::ConvertToRootViewRelativeOffset() r=roc (5ff3388f28)
- Bug 1180589 part 3 - Rename shadowed variable name; r=bholley (7194cda020)
- Bug 1222145 - Bump maximum video size to 8k. r=jya (056778dda9)
- Bug 1180589 part 1 - Add simulator code for TV Manager API; r=seanlin (dd78a38a27)
- Bug 1180589 part 2 - Add code to create a simulated mediastream; r=se# (c255e0dd07)
- spacing (856ee42504)
- missing bit of Bug 1136827 - Stop synchronously (befed33dbe)
- bit of Bug 1204401 (c1f98ed982)
- bits of 1142527 (dc39662797)
- Bug 1212220 - cache pref values so they are safe to access off the main thread. r=roc. (adb186836b)
- Bug 1194918 - Add VideoSink which contains either AudioSinkWrapper or DecodedStreamSink as a default operating MediaSink in MDSM. r=jwwang. (7ccda9b055)
- Bug 1194918 - Move av-sync and video frame rendering logic from MDSM to VideoSink. r=jwwang. (ba56ae120b)
- Bug 1202533 - Fix naming convention of MediaSink::PlaybackParams. (eed5ed3839)
- Bug 1194918 - Override function SetVolume/SetPreservesPitch in VideoSink for the contained AudioSink. r=jwwang. (0d96e6a395)
- Bug 1198663. Skip null Images in VideoSink::RenderVideoFrames instead of treating them as valid. r=jwwang (aaac235c1f)
- Bug 1207198: P2. Defer dormant request while ReadMetadata is pending in MDSM. r=sotaro (0a8e1f4bb0)
- Bug 1209850: Only attempt to initialize decoders as they are required. r=alfredo (615e41b66b)
- Bug 1192733: fix the MediaFormatReader can not back from dormant state. r=jya (c266107d33)
- Bug 1207198: P1. Do not initialize decoders during ReadMetadata. r=cpearce (4174dbc409)
- missing bit of 1196696 (7b1c0fbe95)
- Bug 1208922. Part 6 - IsWaitingOnCDMResource() is not used by MDSM anymore. Remove it from MediaDecoderReader and make it private in MediaFormatReader. r=cpearce. (db67939710)
- adapted of Bug 1208922. Part 3 - forward the CDMProxy from MediaDecoder (a5dca2f89d)
2022-12-09 12:38:41 +08:00

296 lines
8.8 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Assertions.h"
#include "mozilla/Atomics.h"
#include <stdint.h>
using mozilla::Atomic;
using mozilla::MemoryOrdering;
using mozilla::Relaxed;
using mozilla::ReleaseAcquire;
using mozilla::SequentiallyConsistent;
#define A(a,b) MOZ_RELEASE_ASSERT(a,b)
template <typename T, MemoryOrdering Order>
static void
TestTypeWithOrdering()
{
Atomic<T, Order> atomic(5);
A(atomic == 5, "Atomic variable did not initialize");
// Test atomic increment
A(++atomic == T(6), "Atomic increment did not work");
A(atomic++ == T(6), "Atomic post-increment did not work");
A(atomic == T(7), "Atomic post-increment did not work");
// Test atomic decrement
A(--atomic == 6, "Atomic decrement did not work");
A(atomic-- == 6, "Atomic post-decrement did not work");
A(atomic == 5, "Atomic post-decrement did not work");
// Test other arithmetic.
T result;
result = (atomic += T(5));
A(atomic == T(10), "Atomic += did not work");
A(result == T(10), "Atomic += returned the wrong value");
result = (atomic -= T(3));
A(atomic == T(7), "Atomic -= did not work");
A(result == T(7), "Atomic -= returned the wrong value");
// Test assignment
result = (atomic = T(5));
A(atomic == T(5), "Atomic assignment failed");
A(result == T(5), "Atomic assignment returned the wrong value");
// Test logical operations.
result = (atomic ^= T(2));
A(atomic == T(7), "Atomic ^= did not work");
A(result == T(7), "Atomic ^= returned the wrong value");
result = (atomic ^= T(4));
A(atomic == T(3), "Atomic ^= did not work");
A(result == T(3), "Atomic ^= returned the wrong value");
result = (atomic |= T(8));
A(atomic == T(11), "Atomic |= did not work");
A(result == T(11), "Atomic |= returned the wrong value");
result = (atomic |= T(8));
A(atomic == T(11), "Atomic |= did not work");
A(result == T(11), "Atomic |= returned the wrong value");
result = (atomic &= T(12));
A(atomic == T(8), "Atomic &= did not work");
A(result == T(8), "Atomic &= returned the wrong value");
// Test exchange.
atomic = T(30);
result = atomic.exchange(42);
A(atomic == T(42), "Atomic exchange did not work");
A(result == T(30), "Atomic exchange returned the wrong value");
// Test CAS.
atomic = T(1);
bool boolResult = atomic.compareExchange(0, 2);
A(!boolResult, "CAS should have returned false.");
A(atomic == T(1), "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(1, 42);
A(boolResult, "CAS should have succeeded.");
A(atomic == T(42), "CAS should have changed atomic's value.");
}
template<typename T, MemoryOrdering Order>
static void
TestPointerWithOrdering()
{
T array1[10];
Atomic<T*, Order> atomic(array1);
A(atomic == array1, "Atomic variable did not initialize");
// Test atomic increment
A(++atomic == array1 + 1, "Atomic increment did not work");
A(atomic++ == array1 + 1, "Atomic post-increment did not work");
A(atomic == array1 + 2, "Atomic post-increment did not work");
// Test atomic decrement
A(--atomic == array1 + 1, "Atomic decrement did not work");
A(atomic-- == array1 + 1, "Atomic post-decrement did not work");
A(atomic == array1, "Atomic post-decrement did not work");
// Test other arithmetic operations
T* result;
result = (atomic += 2);
A(atomic == array1 + 2, "Atomic += did not work");
A(result == array1 + 2, "Atomic += returned the wrong value");
result = (atomic -= 1);
A(atomic == array1 + 1, "Atomic -= did not work");
A(result == array1 + 1, "Atomic -= returned the wrong value");
// Test stores
result = (atomic = array1);
A(atomic == array1, "Atomic assignment did not work");
A(result == array1, "Atomic assignment returned the wrong value");
// Test exchange
atomic = array1 + 2;
result = atomic.exchange(array1);
A(atomic == array1, "Atomic exchange did not work");
A(result == array1 + 2, "Atomic exchange returned the wrong value");
atomic = array1;
bool boolResult = atomic.compareExchange(array1 + 1, array1 + 2);
A(!boolResult, "CAS should have returned false.");
A(atomic == array1, "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(array1, array1 + 3);
A(boolResult, "CAS should have succeeded.");
A(atomic == array1 + 3, "CAS should have changed atomic's value.");
}
enum EnumType
{
EnumType_0 = 0,
EnumType_1 = 1,
EnumType_2 = 2,
EnumType_3 = 3
};
template<MemoryOrdering Order>
static void
TestEnumWithOrdering()
{
Atomic<EnumType, Order> atomic(EnumType_2);
A(atomic == EnumType_2, "Atomic variable did not initialize");
// Test assignment
EnumType result;
result = (atomic = EnumType_3);
A(atomic == EnumType_3, "Atomic assignment failed");
A(result == EnumType_3, "Atomic assignment returned the wrong value");
// Test exchange.
atomic = EnumType_1;
result = atomic.exchange(EnumType_2);
A(atomic == EnumType_2, "Atomic exchange did not work");
A(result == EnumType_1, "Atomic exchange returned the wrong value");
// Test CAS.
atomic = EnumType_1;
bool boolResult = atomic.compareExchange(EnumType_0, EnumType_2);
A(!boolResult, "CAS should have returned false.");
A(atomic == EnumType_1, "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(EnumType_1, EnumType_3);
A(boolResult, "CAS should have succeeded.");
A(atomic == EnumType_3, "CAS should have changed atomic's value.");
}
enum class EnumClass : uint32_t
{
Value0 = 0,
Value1 = 1,
Value2 = 2,
Value3 = 3
};
template<MemoryOrdering Order>
static void
TestEnumClassWithOrdering()
{
Atomic<EnumClass, Order> atomic(EnumClass::Value2);
A(atomic == EnumClass::Value2, "Atomic variable did not initialize");
// Test assignment
EnumClass result;
result = (atomic = EnumClass::Value3);
A(atomic == EnumClass::Value3, "Atomic assignment failed");
A(result == EnumClass::Value3, "Atomic assignment returned the wrong value");
// Test exchange.
atomic = EnumClass::Value1;
result = atomic.exchange(EnumClass::Value2);
A(atomic == EnumClass::Value2, "Atomic exchange did not work");
A(result == EnumClass::Value1, "Atomic exchange returned the wrong value");
// Test CAS.
atomic = EnumClass::Value1;
bool boolResult = atomic.compareExchange(EnumClass::Value0, EnumClass::Value2);
A(!boolResult, "CAS should have returned false.");
A(atomic == EnumClass::Value1, "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(EnumClass::Value1, EnumClass::Value3);
A(boolResult, "CAS should have succeeded.");
A(atomic == EnumClass::Value3, "CAS should have changed atomic's value.");
}
template <MemoryOrdering Order>
static void
TestBoolWithOrdering()
{
Atomic<bool, Order> atomic(false);
A(atomic == false, "Atomic variable did not initialize");
// Test assignment
bool result;
result = (atomic = true);
A(atomic == true, "Atomic assignment failed");
A(result == true, "Atomic assignment returned the wrong value");
// Test exchange.
atomic = false;
result = atomic.exchange(true);
A(atomic == true, "Atomic exchange did not work");
A(result == false, "Atomic exchange returned the wrong value");
// Test CAS.
atomic = false;
bool boolResult = atomic.compareExchange(true, false);
A(!boolResult, "CAS should have returned false.");
A(atomic == false, "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(false, true);
A(boolResult, "CAS should have succeeded.");
A(atomic == true, "CAS should have changed atomic's value.");
}
template <typename T>
static void
TestType()
{
TestTypeWithOrdering<T, SequentiallyConsistent>();
TestTypeWithOrdering<T, ReleaseAcquire>();
TestTypeWithOrdering<T, Relaxed>();
}
template<typename T>
static void
TestPointer()
{
TestPointerWithOrdering<T, SequentiallyConsistent>();
TestPointerWithOrdering<T, ReleaseAcquire>();
TestPointerWithOrdering<T, Relaxed>();
}
static void
TestEnum()
{
TestEnumWithOrdering<SequentiallyConsistent>();
TestEnumWithOrdering<ReleaseAcquire>();
TestEnumWithOrdering<Relaxed>();
TestEnumClassWithOrdering<SequentiallyConsistent>();
TestEnumClassWithOrdering<ReleaseAcquire>();
TestEnumClassWithOrdering<Relaxed>();
}
static void
TestBool()
{
TestBoolWithOrdering<SequentiallyConsistent>();
TestBoolWithOrdering<ReleaseAcquire>();
TestBoolWithOrdering<Relaxed>();
}
#undef A
int
main()
{
TestType<uint32_t>();
TestType<int32_t>();
TestType<uint64_t>();
TestType<int64_t>();
TestType<intptr_t>();
TestType<uintptr_t>();
TestPointer<int>();
TestPointer<float>();
TestPointer<uint16_t*>();
TestPointer<uint32_t*>();
TestEnum();
TestBool();
return 0;
}