зеркало из https://github.com/AvaloniaUI/angle.git
Template gl::Rectangle so it can be used for float
Bug: angleproject:6598 Change-Id: I8cf5894f0e34c56a6ad856c978be93ea9d5ae113 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3253131 Commit-Queue: Gregg Tavares <gman@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Родитель
a7b3551ef2
Коммит
ab42673590
|
@ -22,6 +22,7 @@
|
|||
#include "libANGLE/Observer.h"
|
||||
#include "libANGLE/RefCountObject.h"
|
||||
#include "libANGLE/State.h"
|
||||
#include "libANGLE/angletypes.h"
|
||||
|
||||
namespace rx
|
||||
{
|
||||
|
@ -44,10 +45,7 @@ class Context;
|
|||
struct Extensions;
|
||||
class Framebuffer;
|
||||
class ImageIndex;
|
||||
struct Rectangle;
|
||||
class Renderbuffer;
|
||||
class State;
|
||||
class Texture;
|
||||
class TextureCapsMap;
|
||||
|
||||
struct FramebufferStatus
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "libANGLE/VertexArray.h"
|
||||
#include "libANGLE/VertexAttribute.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace gl
|
||||
{
|
||||
namespace
|
||||
|
@ -624,30 +626,17 @@ static void MinMax(int a, int b, int *minimum, int *maximum)
|
|||
}
|
||||
}
|
||||
|
||||
Rectangle Rectangle::flip(bool flipX, bool flipY) const
|
||||
template <>
|
||||
bool RectangleImpl<int>::empty() const
|
||||
{
|
||||
Rectangle flipped = *this;
|
||||
if (flipX)
|
||||
{
|
||||
flipped.x = flipped.x + flipped.width;
|
||||
flipped.width = -flipped.width;
|
||||
}
|
||||
if (flipY)
|
||||
{
|
||||
flipped.y = flipped.y + flipped.height;
|
||||
flipped.height = -flipped.height;
|
||||
}
|
||||
return flipped;
|
||||
return width == 0 && height == 0;
|
||||
}
|
||||
|
||||
Rectangle Rectangle::removeReversal() const
|
||||
template <>
|
||||
bool RectangleImpl<float>::empty() const
|
||||
{
|
||||
return flip(isReversedX(), isReversedY());
|
||||
}
|
||||
|
||||
bool Rectangle::encloses(const gl::Rectangle &inside) const
|
||||
{
|
||||
return x0() <= inside.x0() && y0() <= inside.y0() && x1() >= inside.x1() && y1() >= inside.y1();
|
||||
return std::abs(width) < std::numeric_limits<float>::epsilon() &&
|
||||
std::abs(height) < std::numeric_limits<float>::epsilon();
|
||||
}
|
||||
|
||||
bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection)
|
||||
|
|
|
@ -49,39 +49,72 @@ enum class InitState
|
|||
Initialized,
|
||||
};
|
||||
|
||||
struct Rectangle
|
||||
template <typename T>
|
||||
struct RectangleImpl
|
||||
{
|
||||
Rectangle() : x(0), y(0), width(0), height(0) {}
|
||||
constexpr Rectangle(int x_in, int y_in, int width_in, int height_in)
|
||||
RectangleImpl() : x(T(0)), y(T(0)), width(T(0)), height(T(0)) {}
|
||||
constexpr RectangleImpl(T x_in, T y_in, T width_in, T height_in)
|
||||
: x(x_in), y(y_in), width(width_in), height(height_in)
|
||||
{}
|
||||
explicit constexpr RectangleImpl(const T corners[4])
|
||||
: x(corners[0]),
|
||||
y(corners[1]),
|
||||
width(corners[2] - corners[0]),
|
||||
height(corners[3] - corners[1])
|
||||
{}
|
||||
template <typename S>
|
||||
explicit constexpr RectangleImpl(const RectangleImpl<S> rect)
|
||||
: x(rect.x), y(rect.y), width(rect.width), height(rect.height)
|
||||
{}
|
||||
|
||||
int x0() const { return x; }
|
||||
int y0() const { return y; }
|
||||
int x1() const { return x + width; }
|
||||
int y1() const { return y + height; }
|
||||
T x0() const { return x; }
|
||||
T y0() const { return y; }
|
||||
T x1() const { return x + width; }
|
||||
T y1() const { return y + height; }
|
||||
|
||||
bool isReversedX() const { return width < 0; }
|
||||
bool isReversedY() const { return height < 0; }
|
||||
bool isReversedX() const { return width < T(0); }
|
||||
bool isReversedY() const { return height < T(0); }
|
||||
|
||||
// Returns a rectangle with the same area but flipped in X, Y, neither or both.
|
||||
Rectangle flip(bool flipX, bool flipY) const;
|
||||
RectangleImpl<T> flip(bool flipX, bool flipY) const
|
||||
{
|
||||
RectangleImpl flipped = *this;
|
||||
if (flipX)
|
||||
{
|
||||
flipped.x = flipped.x + flipped.width;
|
||||
flipped.width = -flipped.width;
|
||||
}
|
||||
if (flipY)
|
||||
{
|
||||
flipped.y = flipped.y + flipped.height;
|
||||
flipped.height = -flipped.height;
|
||||
}
|
||||
return flipped;
|
||||
}
|
||||
|
||||
// Returns a rectangle with the same area but with height and width guaranteed to be positive.
|
||||
Rectangle removeReversal() const;
|
||||
RectangleImpl<T> removeReversal() const { return flip(isReversedX(), isReversedY()); }
|
||||
|
||||
bool encloses(const gl::Rectangle &inside) const;
|
||||
bool encloses(const RectangleImpl<T> &inside) const
|
||||
{
|
||||
return x0() <= inside.x0() && y0() <= inside.y0() && x1() >= inside.x1() &&
|
||||
y1() >= inside.y1();
|
||||
}
|
||||
|
||||
bool empty() const { return width == 0 && height == 0; }
|
||||
bool empty() const;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
T x;
|
||||
T y;
|
||||
T width;
|
||||
T height;
|
||||
};
|
||||
|
||||
bool operator==(const Rectangle &a, const Rectangle &b);
|
||||
bool operator!=(const Rectangle &a, const Rectangle &b);
|
||||
template <typename T>
|
||||
bool operator==(const RectangleImpl<T> &a, const RectangleImpl<T> &b);
|
||||
template <typename T>
|
||||
bool operator!=(const RectangleImpl<T> &a, const RectangleImpl<T> &b);
|
||||
|
||||
using Rectangle = RectangleImpl<int>;
|
||||
|
||||
enum class ClipSpaceOrigin
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "libANGLE/Error.h"
|
||||
#include "libANGLE/Framebuffer.h"
|
||||
#include "libANGLE/State.h"
|
||||
#include "libANGLE/angletypes.h"
|
||||
|
||||
namespace gl
|
||||
{
|
||||
|
@ -21,8 +22,6 @@ class Buffer;
|
|||
class Framebuffer;
|
||||
class FramebufferAttachment;
|
||||
struct PixelPackState;
|
||||
struct Rectangle;
|
||||
class State;
|
||||
} // namespace gl
|
||||
|
||||
namespace rx
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "libANGLE/ImageIndex.h"
|
||||
#include "libANGLE/Stream.h"
|
||||
#include "libANGLE/Texture.h"
|
||||
#include "libANGLE/angletypes.h"
|
||||
#include "libANGLE/renderer/FramebufferAttachmentObjectImpl.h"
|
||||
|
||||
namespace egl
|
||||
|
@ -27,10 +28,6 @@ class Image;
|
|||
|
||||
namespace gl
|
||||
{
|
||||
struct Box;
|
||||
struct Extents;
|
||||
struct Offset;
|
||||
struct Rectangle;
|
||||
class Framebuffer;
|
||||
class MemoryObject;
|
||||
struct PixelUnpackState;
|
||||
|
|
|
@ -15,16 +15,13 @@
|
|||
|
||||
#include "common/PackedEnums.h"
|
||||
#include "libANGLE/Error.h"
|
||||
#include "libANGLE/angletypes.h"
|
||||
|
||||
namespace gl
|
||||
{
|
||||
class Context;
|
||||
class Framebuffer;
|
||||
class ImageIndex;
|
||||
struct Box;
|
||||
struct Extents;
|
||||
struct Offset;
|
||||
struct Rectangle;
|
||||
struct PixelUnpackState;
|
||||
} // namespace gl
|
||||
|
||||
|
|
|
@ -270,64 +270,7 @@ angle::Result FramebufferMtl::readPixels(const gl::Context *context,
|
|||
namespace
|
||||
{
|
||||
|
||||
// Naming FloatRectangle instead of Rectangle because it seems like it would be confused with
|
||||
// gl::Rectangle
|
||||
struct FloatRectangle
|
||||
{
|
||||
FloatRectangle() : x(0.0f), y(0.0f), width(0.0f), height(0.0f) {}
|
||||
constexpr FloatRectangle(int x_in, int y_in, int width_in, int height_in)
|
||||
: x(x_in), y(y_in), width(width_in), height(height_in)
|
||||
{}
|
||||
explicit constexpr FloatRectangle(const gl::Rectangle &rect)
|
||||
: x(rect.x), y(rect.y), width(rect.width), height(rect.height)
|
||||
{}
|
||||
explicit constexpr FloatRectangle(const float corners[4])
|
||||
: x(corners[0]),
|
||||
y(corners[1]),
|
||||
width(corners[2] - corners[0]),
|
||||
height(corners[3] - corners[1])
|
||||
{}
|
||||
|
||||
float x0() const { return x; }
|
||||
float y0() const { return y; }
|
||||
float x1() const { return x + width; }
|
||||
float y1() const { return y + height; }
|
||||
|
||||
bool isReversedX() const { return width < 0.0f; }
|
||||
bool isReversedY() const { return height < 0.0f; }
|
||||
|
||||
// Returns a rectangle with the same area but flipped in X, Y, neither or both.
|
||||
FloatRectangle flip(bool flipX, bool flipY) const;
|
||||
|
||||
// Returns a rectangle with the same area but with height and width guaranteed to be positive.
|
||||
FloatRectangle removeReversal() const;
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float width;
|
||||
float height;
|
||||
};
|
||||
|
||||
FloatRectangle FloatRectangle::flip(bool flipX, bool flipY) const
|
||||
{
|
||||
FloatRectangle flipped = *this;
|
||||
if (flipX)
|
||||
{
|
||||
flipped.x = flipped.x + flipped.width;
|
||||
flipped.width = -flipped.width;
|
||||
}
|
||||
if (flipY)
|
||||
{
|
||||
flipped.y = flipped.y + flipped.height;
|
||||
flipped.height = -flipped.height;
|
||||
}
|
||||
return flipped;
|
||||
}
|
||||
|
||||
FloatRectangle FloatRectangle::removeReversal() const
|
||||
{
|
||||
return flip(isReversedX(), isReversedY());
|
||||
}
|
||||
using FloatRectangle = gl::RectangleImpl<float>;
|
||||
|
||||
float clamp0Max(float v, float max)
|
||||
{
|
||||
|
|
|
@ -95,7 +95,6 @@ class Surface;
|
|||
|
||||
namespace gl
|
||||
{
|
||||
struct Rectangle;
|
||||
ANGLE_GL_OBJECTS_X(ANGLE_PRE_DECLARE_OBJECT)
|
||||
} // namespace gl
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "common/debug.h"
|
||||
#include "libANGLE/Error.h"
|
||||
#include "libANGLE/Observer.h"
|
||||
#include "libANGLE/angletypes.h"
|
||||
#include "libANGLE/renderer/serial_utils.h"
|
||||
#include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h"
|
||||
#include "libANGLE/renderer/vulkan/VulkanSecondaryCommandBuffer.h"
|
||||
|
@ -53,12 +54,8 @@ class ShareGroup;
|
|||
|
||||
namespace gl
|
||||
{
|
||||
struct Box;
|
||||
class MockOverlay;
|
||||
struct Extents;
|
||||
struct RasterizerState;
|
||||
struct Rectangle;
|
||||
class State;
|
||||
struct SwizzleState;
|
||||
struct VertexAttribute;
|
||||
class VertexBinding;
|
||||
|
|
Загрузка…
Ссылка в новой задаче