зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1259248. Add an ArrayView class. r=botond
This commit is contained in:
Родитель
90029b5133
Коммит
96d3663f32
|
@ -0,0 +1,46 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* 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/. */
|
||||
|
||||
#ifndef MOZILLA_GFX_ARRAY_VIEW_H_
|
||||
#define MOZILLA_GFX_ARRAY_VIEW_H_
|
||||
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
template<typename T>
|
||||
class ArrayView
|
||||
{
|
||||
public:
|
||||
ArrayView(const nsTArray<T>& aData) :
|
||||
mData(aData.Elements()), mLength(aData.Length())
|
||||
{
|
||||
}
|
||||
ArrayView(const T* aData, const size_t aLength) :
|
||||
mData(aData), mLength(aLength)
|
||||
{
|
||||
}
|
||||
const T& operator[](const size_t aIdx) const
|
||||
{
|
||||
return mData[aIdx];
|
||||
}
|
||||
size_t Length() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
const T* Data() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
private:
|
||||
const T* mData;
|
||||
const size_t mLength;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* MOZILLA_GFX_ARRAY_VIEW_H_ */
|
|
@ -43,6 +43,7 @@ EXPORTS += [
|
|||
|
||||
EXPORTS.mozilla += [
|
||||
'AppUnits.h',
|
||||
'ArrayView.h',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_X11']:
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include "nsMargin.h" // for nsIntMargin
|
||||
#include "nsRegionFwd.h" // for nsIntRegion
|
||||
#include "nsStringGlue.h" // for nsCString
|
||||
#include "nsTArray.h" // for nsTArray, nsTArray_Impl
|
||||
#include "xpcom-config.h" // for CPP_THROW_NEW
|
||||
#include "mozilla/ArrayView.h" // for ArrayView
|
||||
#include "mozilla/Move.h" // for mozilla::Move
|
||||
#include "mozilla/gfx/MatrixFwd.h" // for mozilla::gfx::Matrix4x4
|
||||
|
||||
|
@ -60,9 +60,9 @@ public:
|
|||
aRect.y,
|
||||
aRect.width,
|
||||
aRect.height); }
|
||||
explicit nsRegion (const nsTArray<pixman_box32_t>& aRects)
|
||||
explicit nsRegion (mozilla::gfx::ArrayView<pixman_box32_t> aRects)
|
||||
{
|
||||
pixman_region32_init_rects(&mImpl, aRects.Elements(), aRects.Length());
|
||||
pixman_region32_init_rects(&mImpl, aRects.Data(), aRects.Length());
|
||||
}
|
||||
nsRegion (const nsRegion& aRegion) { pixman_region32_init(&mImpl); pixman_region32_copy(&mImpl,aRegion.Impl()); }
|
||||
nsRegion (nsRegion&& aRegion) { mImpl = aRegion.mImpl; pixman_region32_init(&aRegion.mImpl); }
|
||||
|
@ -480,7 +480,7 @@ public:
|
|||
|
||||
BaseIntRegion () {}
|
||||
MOZ_IMPLICIT BaseIntRegion (const Rect& aRect) : mImpl (ToRect(aRect)) {}
|
||||
explicit BaseIntRegion (const nsTArray<pixman_box32_t>& aRects) : mImpl (aRects) {}
|
||||
explicit BaseIntRegion (mozilla::gfx::ArrayView<pixman_box32_t> aRects) : mImpl (aRects) {}
|
||||
BaseIntRegion (const BaseIntRegion& aRegion) : mImpl (aRegion.mImpl) {}
|
||||
BaseIntRegion (BaseIntRegion&& aRegion) : mImpl (mozilla::Move(aRegion.mImpl)) {}
|
||||
Derived& operator = (const Rect& aRect) { mImpl = ToRect (aRect); return This(); }
|
||||
|
@ -832,7 +832,7 @@ public:
|
|||
IntRegionTyped() {}
|
||||
MOZ_IMPLICIT IntRegionTyped(const IntRectTyped<units>& aRect) : Super(aRect) {}
|
||||
IntRegionTyped(const IntRegionTyped& aRegion) : Super(aRegion) {}
|
||||
explicit IntRegionTyped(const nsTArray<pixman_box32_t>& aRects) : Super(aRects) {}
|
||||
explicit IntRegionTyped(mozilla::gfx::ArrayView<pixman_box32_t> aRects) : Super(aRects) {}
|
||||
IntRegionTyped(IntRegionTyped&& aRegion) : Super(mozilla::Move(aRegion)) {}
|
||||
|
||||
// Assignment operators need to be forwarded as well, otherwise the compiler
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 <limits>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "mozilla/ArrayView.h"
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
TEST(Gfx, ArrayView) {
|
||||
nsTArray<int> p = {5, 6};
|
||||
ArrayView<int> pv(p);
|
||||
ASSERT_EQ(pv[1], 6);
|
||||
ASSERT_EQ(*pv.Data(), 5);
|
||||
}
|
|
@ -9,6 +9,7 @@ UNIFIED_SOURCES += [
|
|||
# Disabled on suspicion of causing bug 904227
|
||||
#'gfxWordCacheTest.cpp',
|
||||
'TestArena.cpp',
|
||||
'TestArrayView.cpp',
|
||||
'TestBufferRotation.cpp',
|
||||
'TestColorNames.cpp',
|
||||
'TestCompositor.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче