Files
palemoon27/mfbt/PodOperations.h
T
roytam1 a988f766e4 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1157984 - Part 1: Extend gfx::2d classes to support both float and double precision,r=jrmuizel (d8d0cadcb0)
- Bug 1157984 - Part 2: Implement double precision clipping functions in Matrix4x4,r=vlad (f31c243a9d)
- Bug 1157984 - Part 3: Correct bounding box transformations to support projections and correct clipping when transforming behind the camera,r=vlad (c9c678905b)
- Bug 1157984 - Part 4: Remove gfxRect::TransformBounds,r=vlad (71d076d48b)
- Bug 1157984 - Part 5: Test,r=vlad (1c9c711745)
- Bug 1159985 - In APZ gtests, allow panning in both directions. r=kats (b4a42c580a)
- Bug 1166871 - Add a test. r=botond (b08332347f)
- Bug 1159985 - Gtest. r=kats (ad41b809ff)
- Bug 1169695 - Make the test timestamp privately held by the MockContentControllerDelayed. r=botond (4f898a778c)
- Bug 1169695 - Advance the stored time when sampling the transform for a future frame. r=botond (77d029383e)
- Bug 1169695 - Store task run-at times in the task queue. r=botond (4bc228d713)
- Bug 1171312 - Add generic tree search algorithms for layers-related data structures. r=botond (675806f3e1)
- Bug 1200063 - Make APZCTreeManager the place where GetFrameTime() can be overridden. r=kats (32ba198192)
- Bug 1200063 - Share a paint throttler between APZCs in the same layers id. r=kats (a2147d25e6)
- Bug 1200063 - Add a generic implementation of nsITimerCallback that's usable with a lambda or other function object. r=kats (6d7ef71d44)
- Bug 1200063 - Make sure TaskThrottler sends its pending repaint request eventually, even if it never receives a notification from the previous request. r=kats (6eceede1e2)
- Bug 1200063 - Rename MakeAPZCInstance to NewAPZCInstance for consistency. r=kats (6927e90644)
- Bug 1144374 - Fix APZ code to deal with layers getting moved to another LayerManager. r=botond (eb682a58cd)
- Bug 1193930 - Allow the user to start a pinch while an overscroll animation is still in progress. r=kats (44c2e57123)
- Bug 1169690 - Gtests. r=kats (3c206d1cb2)
- Bug 1201098 - Consume fling and overscroll velocity per-axis. r=botond (1e05677586)
- Bug 1158424 - Clean up uses of HasNoParentWithSameLayersId() in overscroll handoff chain building. r=kats (0ed1ddee59)
- Bug 1201277 - Replace functors with lambdas in APZCTreeManager. r=botond (ec5476a598)
- Bug 1180030 - Request a fling snap when an overscroll animation completes. r=kats (e789a2ebb3)
- Bug 1159985 - If only one component of a fling is in overscroll, continue the fling in the other component. r=kats (81998d723f)
- Bug 1031443 - Allow panning in the pinching state even if zooming is disabled;r=botond (4c90350cc6)
- Fix APZ not starting and updating wheel animations within an APZC lock. (bug 1152011 part 1, r=botond) (ae0d4d0aa8)
- Bug 1145089 - Update documentation for nsEventStatus_eConsumeNoDefault. r=botond (7ca605ad96)
- bug 1170988 - Fix skia to build for iOS. r=gw280 (fb375def29)
- bug 1171642 - Disable some skia arm assembly for iOS. r=gw280 (004245c173)
- fix build on gcc 11 (1c511ac81b)
- missing bit of Bug 1188462 - Rename gfx/skia/trunk directory to gfx/skia/skia. (ca8f138b28)
- Bug 1180030 - Do not request a fling snap if the fling will overscroll on its first sample. r=kats (55f89d55b5)
- Bug 1167721 - Ensure we trigger a repaint when dropping velocity to zero in CancelAnimation. r=botond (d04fbb2a50)
- Bug 1158340 - Refactor RedistributeDisplayPortExcess. r=kats (27725c3ee4)
- Bug 1189565 - Only factor in the async zoom change. r=kats (57e357a038)
- Bug 1192466 - Prune header includes for SkiaGLGlue.h - r=bgirard (37d31a1238)
- Bug 1004489 - propagate Cairo font AA settings to Skia font. r=gw280 (9adc439b19)
- Bug 1171528 - Remove overflowed nscoord_MAX warnings from nsRect. r=dholbert (08599b00e9)
- Bug 1202430 - remove NS_GFX and related macros; r=jrmuizel (cb0b79951e)
- Bug 1181317 - Switch drawing order of filter feBlend inputs. r=mstange (4914444219)
- Bug 1180379. Split out GMAX4500 and block those devices from D2D. r=Bas (c8d1a755ea)
- Bug 1073117 - Theme issues with GTK 3.14 - fix gtk button and entry size, r=karlt (0df9ac5c7f)
- Bug 1187237 - Correct range slider drawing on GTK3. r=karlt (0d671487da)
- Bug 1171696 - Require room for scrollbar sliders and draw troughs only when there is room for a slider or buttons on GTK. r=karlt (71710baeaa)
- Bug 1202317. Optimize away identity ColorMatrix nodes. r=mstange (6c57a71e0c)
- Bug 1202317. Support PodEqual over fixed-length arrays. r=Waldo (060f20b429)
- Bug 1203078 - whitelist gdk-pixbuf image formats. r=dan (5eb43e4235)
- Bug 1202317. Optimize feComposite type="arithmetic" with all-zero k values to transparent black. r=mstange (47b2d40678)
- Bug 1189443 - Don't round down the margin amounts when inflating the displayport. r=dvander (4afcf087ab)
- Bug 1205741 - add xpm and svg to supported gdk-pixbuf formats. r=acomminos,dveditz (4c356c961a)
- Bug 1166741 - Workaround for GTK3 bug where file choosers' delegate refcount is not incremented. r=karlt (9d59be7b05)
- Bug 1166741 followup: Guard GTK file-picker member-var decl/init statements with same #ifdef that its usages are guarded with, to avoid -Wunused-private-field warning. r=karlt (25bbf34486)
- fix build on 10.5/10.6 (9acd104c9f)
- namespaces (358de9591c)
- Bug 1178842 - Fix unified build for nsDisplayList.cpp when a new file is added to layout/base. r=mstange (aa8ff77615)
2022-02-04 12:07:47 +08:00

197 lines
5.4 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/. */
/*
* Operations for zeroing POD types, arrays, and so on.
*
* These operations are preferable to memset, memcmp, and the like because they
* don't require remembering to multiply by sizeof(T), array lengths, and so on
* everywhere.
*/
#ifndef mozilla_PodOperations_h
#define mozilla_PodOperations_h
#include "mozilla/Array.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Attributes.h"
#include <stdint.h>
#include <string.h>
namespace mozilla {
/** Set the contents of |aT| to 0. */
template<typename T>
static MOZ_ALWAYS_INLINE void
PodZero(T* aT)
{
memset(aT, 0, sizeof(T));
}
/** Set the contents of |aNElem| elements starting at |aT| to 0. */
template<typename T>
static MOZ_ALWAYS_INLINE void
PodZero(T* aT, size_t aNElem)
{
/*
* This function is often called with 'aNElem' small; we use an inline loop
* instead of calling 'memset' with a non-constant length. The compiler
* should inline the memset call with constant size, though.
*/
for (T* end = aT + aNElem; aT < end; aT++) {
memset(aT, 0, sizeof(T));
}
}
/*
* Arrays implicitly convert to pointers to their first element, which is
* dangerous when combined with the above PodZero definitions. Adding an
* overload for arrays is ambiguous, so we need another identifier. The
* ambiguous overload is left to catch mistaken uses of PodZero; if you get a
* compile error involving PodZero and array types, use PodArrayZero instead.
*/
template<typename T, size_t N>
static void PodZero(T (&aT)[N]) = delete;
template<typename T, size_t N>
static void PodZero(T (&aT)[N], size_t aNElem) = delete;
/** Set the contents of the array |aT| to zero. */
template <class T, size_t N>
static MOZ_ALWAYS_INLINE void
PodArrayZero(T (&aT)[N])
{
memset(aT, 0, N * sizeof(T));
}
template <typename T, size_t N>
static MOZ_ALWAYS_INLINE void
PodArrayZero(Array<T, N>& aArr)
{
memset(&aArr[0], 0, N * sizeof(T));
}
/**
* Assign |*aSrc| to |*aDst|. The locations must not be the same and must not
* overlap.
*/
template<typename T>
static MOZ_ALWAYS_INLINE void
PodAssign(T* aDst, const T* aSrc)
{
MOZ_ASSERT(aDst + 1 <= aSrc || aSrc + 1 <= aDst,
"destination and source must not overlap");
memcpy(reinterpret_cast<char*>(aDst), reinterpret_cast<const char*>(aSrc),
sizeof(T));
}
/**
* Copy |aNElem| T elements from |aSrc| to |aDst|. The two memory ranges must
* not overlap!
*/
template<typename T>
static MOZ_ALWAYS_INLINE void
PodCopy(T* aDst, const T* aSrc, size_t aNElem)
{
MOZ_ASSERT(aDst + aNElem <= aSrc || aSrc + aNElem <= aDst,
"destination and source must not overlap");
if (aNElem < 128) {
/*
* Avoid using operator= in this loop, as it may have been
* intentionally deleted by the POD type.
*/
for (const T* srcend = aSrc + aNElem; aSrc < srcend; aSrc++, aDst++) {
PodAssign(aDst, aSrc);
}
} else {
memcpy(aDst, aSrc, aNElem * sizeof(T));
}
}
template<typename T>
static MOZ_ALWAYS_INLINE void
PodCopy(volatile T* aDst, const volatile T* aSrc, size_t aNElem)
{
MOZ_ASSERT(aDst + aNElem <= aSrc || aSrc + aNElem <= aDst,
"destination and source must not overlap");
/*
* Volatile |aDst| requires extra work, because it's undefined behavior to
* modify volatile objects using the mem* functions. Just write out the
* loops manually, using operator= rather than memcpy for the same reason,
* and let the compiler optimize to the extent it can.
*/
for (const volatile T* srcend = aSrc + aNElem;
aSrc < srcend;
aSrc++, aDst++) {
*aDst = *aSrc;
}
}
/*
* Copy the contents of the array |aSrc| into the array |aDst|, both of size N.
* The arrays must not overlap!
*/
template <class T, size_t N>
static MOZ_ALWAYS_INLINE void
PodArrayCopy(T (&aDst)[N], const T (&aSrc)[N])
{
PodCopy(aDst, aSrc, N);
}
/**
* Copy the memory for |aNElem| T elements from |aSrc| to |aDst|. If the two
* memory ranges overlap, then the effect is as if the |aNElem| elements are
* first copied from |aSrc| to a temporary array, and then from the temporary
* array to |aDst|.
*/
template<typename T>
static MOZ_ALWAYS_INLINE void
PodMove(T* aDst, const T* aSrc, size_t aNElem)
{
MOZ_ASSERT(aNElem <= SIZE_MAX / sizeof(T),
"trying to move an impossible number of elements");
memmove(aDst, aSrc, aNElem * sizeof(T));
}
/**
* Determine whether the |len| elements at |one| are memory-identical to the
* |len| elements at |two|.
*/
template<typename T>
static MOZ_ALWAYS_INLINE bool
PodEqual(const T* one, const T* two, size_t len)
{
if (len < 128) {
const T* p1end = one + len;
const T* p1 = one;
const T* p2 = two;
for (; p1 < p1end; p1++, p2++) {
if (*p1 != *p2) {
return false;
}
}
return true;
}
return !memcmp(one, two, len * sizeof(T));
}
/*
* Determine whether the |N| elements at |one| are memory-identical to the
* |N| elements at |two|.
*/
template <class T, size_t N>
static MOZ_ALWAYS_INLINE bool
PodEqual(const T (&one)[N], const T (&two)[N])
{
return PodEqual(one, two, N);
}
} // namespace mozilla
#endif /* mozilla_PodOperations_h */