mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1772947 - Remove dead code DecomposeIntoNoRepeatTriangles. r=gfx-reviewers,jgilbert
Differential Revision: https://phabricator.services.mozilla.com/D148455
This commit is contained in:
parent
b521809418
commit
2879b04886
@ -1,128 +0,0 @@
|
||||
/* -*- 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 "DecomposeIntoNoRepeatTriangles.h"
|
||||
#include "gfxMatrix.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
void RectTriangles::AppendRectToCoordArray(nsTArray<coord>& array, GLfloat x0,
|
||||
GLfloat y0, GLfloat x1, GLfloat y1) {
|
||||
coord* v = array.AppendElements(6);
|
||||
|
||||
v[0].x = x0;
|
||||
v[0].y = y0;
|
||||
v[1].x = x1;
|
||||
v[1].y = y0;
|
||||
v[2].x = x0;
|
||||
v[2].y = y1;
|
||||
v[3].x = x0;
|
||||
v[3].y = y1;
|
||||
v[4].x = x1;
|
||||
v[4].y = y0;
|
||||
v[5].x = x1;
|
||||
v[5].y = y1;
|
||||
}
|
||||
|
||||
void RectTriangles::addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
|
||||
GLfloat tx0, GLfloat ty0, GLfloat tx1, GLfloat ty1,
|
||||
bool flip_y /* = false */) {
|
||||
if (flip_y) {
|
||||
std::swap(ty0, ty1);
|
||||
}
|
||||
AppendRectToCoordArray(mVertexCoords, x0, y0, x1, y1);
|
||||
AppendRectToCoordArray(mTexCoords, tx0, ty0, tx1, ty1);
|
||||
}
|
||||
|
||||
static GLfloat WrapTexCoord(GLfloat v) {
|
||||
// This should return values in range [0, 1.0)
|
||||
return v - floorf(v);
|
||||
}
|
||||
|
||||
void DecomposeIntoNoRepeatTriangles(const gfx::IntRect& aTexCoordRect,
|
||||
const gfx::IntSize& aTexSize,
|
||||
RectTriangles& aRects,
|
||||
bool aFlipY /* = false */) {
|
||||
// normalize this
|
||||
gfx::IntRect tcr(aTexCoordRect);
|
||||
while (tcr.X() >= aTexSize.width) tcr.MoveByX(-aTexSize.width);
|
||||
while (tcr.Y() >= aTexSize.height) tcr.MoveByY(-aTexSize.height);
|
||||
|
||||
// Compute top left and bottom right tex coordinates
|
||||
GLfloat tl[2] = {GLfloat(tcr.X()) / GLfloat(aTexSize.width),
|
||||
GLfloat(tcr.Y()) / GLfloat(aTexSize.height)};
|
||||
GLfloat br[2] = {GLfloat(tcr.XMost()) / GLfloat(aTexSize.width),
|
||||
GLfloat(tcr.YMost()) / GLfloat(aTexSize.height)};
|
||||
|
||||
// then check if we wrap in either the x or y axis; if we do,
|
||||
// then also use fmod to figure out the "true" non-wrapping
|
||||
// texture coordinates.
|
||||
|
||||
bool xwrap = false, ywrap = false;
|
||||
if (tcr.X() < 0 || tcr.X() > aTexSize.width || tcr.XMost() < 0 ||
|
||||
tcr.XMost() > aTexSize.width) {
|
||||
xwrap = true;
|
||||
tl[0] = WrapTexCoord(tl[0]);
|
||||
br[0] = WrapTexCoord(br[0]);
|
||||
}
|
||||
|
||||
if (tcr.Y() < 0 || tcr.Y() > aTexSize.height || tcr.YMost() < 0 ||
|
||||
tcr.YMost() > aTexSize.height) {
|
||||
ywrap = true;
|
||||
tl[1] = WrapTexCoord(tl[1]);
|
||||
br[1] = WrapTexCoord(br[1]);
|
||||
}
|
||||
|
||||
NS_ASSERTION(tl[0] >= 0.0f && tl[0] <= 1.0f && tl[1] >= 0.0f &&
|
||||
tl[1] <= 1.0f && br[0] >= 0.0f && br[0] <= 1.0f &&
|
||||
br[1] >= 0.0f && br[1] <= 1.0f,
|
||||
"Somehow generated invalid texture coordinates");
|
||||
|
||||
// If xwrap is false, the texture will be sampled from tl[0]
|
||||
// .. br[0]. If xwrap is true, then it will be split into tl[0]
|
||||
// .. 1.0, and 0.0 .. br[0]. Same for the Y axis. The
|
||||
// destination rectangle is also split appropriately, according
|
||||
// to the calculated xmid/ymid values.
|
||||
|
||||
// There isn't a 1:1 mapping between tex coords and destination coords;
|
||||
// when computing midpoints, we have to take that into account. We
|
||||
// need to map the texture coords, which are (in the wrap case):
|
||||
// |tl->1| and |0->br| to the |0->1| range of the vertex coords. So
|
||||
// we have the length (1-tl)+(br) that needs to map into 0->1.
|
||||
// These are only valid if there is wrap involved, they won't be used
|
||||
// otherwise.
|
||||
GLfloat xlen = (1.0f - tl[0]) + br[0];
|
||||
GLfloat ylen = (1.0f - tl[1]) + br[1];
|
||||
|
||||
NS_ASSERTION(!xwrap || xlen > 0.0f, "xlen isn't > 0, what's going on?");
|
||||
NS_ASSERTION(!ywrap || ylen > 0.0f, "ylen isn't > 0, what's going on?");
|
||||
NS_ASSERTION(aTexCoordRect.Width() <= aTexSize.width &&
|
||||
aTexCoordRect.Height() <= aTexSize.height,
|
||||
"tex coord rect would cause tiling!");
|
||||
|
||||
if (!xwrap && !ywrap) {
|
||||
aRects.addRect(0.0f, 0.0f, 1.0f, 1.0f, tl[0], tl[1], br[0], br[1], aFlipY);
|
||||
} else if (!xwrap && ywrap) {
|
||||
GLfloat ymid = (1.0f - tl[1]) / ylen;
|
||||
aRects.addRect(0.0f, 0.0f, 1.0f, ymid, tl[0], tl[1], br[0], 1.0f, aFlipY);
|
||||
aRects.addRect(0.0f, ymid, 1.0f, 1.0f, tl[0], 0.0f, br[0], br[1], aFlipY);
|
||||
} else if (xwrap && !ywrap) {
|
||||
GLfloat xmid = (1.0f - tl[0]) / xlen;
|
||||
aRects.addRect(0.0f, 0.0f, xmid, 1.0f, tl[0], tl[1], 1.0f, br[1], aFlipY);
|
||||
aRects.addRect(xmid, 0.0f, 1.0f, 1.0f, 0.0f, tl[1], br[0], br[1], aFlipY);
|
||||
} else {
|
||||
GLfloat xmid = (1.0f - tl[0]) / xlen;
|
||||
GLfloat ymid = (1.0f - tl[1]) / ylen;
|
||||
aRects.addRect(0.0f, 0.0f, xmid, ymid, tl[0], tl[1], 1.0f, 1.0f, aFlipY);
|
||||
aRects.addRect(xmid, 0.0f, 1.0f, ymid, 0.0f, tl[1], br[0], 1.0f, aFlipY);
|
||||
aRects.addRect(0.0f, ymid, xmid, 1.0f, tl[0], 0.0f, 1.0f, br[1], aFlipY);
|
||||
aRects.addRect(xmid, ymid, 1.0f, 1.0f, 0.0f, 0.0f, br[0], br[1], aFlipY);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gl
|
||||
} // namespace mozilla
|
@ -1,72 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#ifndef DecomposeIntoNoRepeatTriangles_h_
|
||||
#define DecomposeIntoNoRepeatTriangles_h_
|
||||
|
||||
#include "GLTypes.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
/** Helper for DecomposeIntoNoRepeatTriangles
|
||||
*/
|
||||
class RectTriangles {
|
||||
public:
|
||||
typedef struct {
|
||||
GLfloat x, y;
|
||||
} coord;
|
||||
|
||||
// Always pass texture coordinates upright. If you want to flip the
|
||||
// texture coordinates emitted to the tex_coords array, set flip_y to
|
||||
// true.
|
||||
void addRect(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat tx0,
|
||||
GLfloat ty0, GLfloat tx1, GLfloat ty1, bool flip_y = false);
|
||||
|
||||
/**
|
||||
* these return a float pointer to the start of each array respectively.
|
||||
* Use it for glVertexAttribPointer calls.
|
||||
* We can return nullptr if we choose to use Vertex Buffer Objects here.
|
||||
*/
|
||||
nsTArray<coord>& vertCoords() { return mVertexCoords; }
|
||||
|
||||
nsTArray<coord>& texCoords() { return mTexCoords; }
|
||||
|
||||
unsigned int elements() { return mVertexCoords.Length(); }
|
||||
|
||||
private:
|
||||
// Reserve inline storage for one quad (2 triangles, 3 coords).
|
||||
AutoTArray<coord, 6> mVertexCoords;
|
||||
AutoTArray<coord, 6> mTexCoords;
|
||||
|
||||
static void AppendRectToCoordArray(nsTArray<coord>& array, GLfloat x0,
|
||||
GLfloat y0, GLfloat x1, GLfloat y1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Decompose drawing the possibly-wrapped aTexCoordRect rectangle
|
||||
* of a texture of aTexSize into one or more rectangles (represented
|
||||
* as 2 triangles) and associated tex coordinates, such that
|
||||
* we don't have to use the REPEAT wrap mode. If aFlipY is true, the
|
||||
* texture coordinates will be specified vertically flipped.
|
||||
*
|
||||
* The resulting triangle vertex coordinates will be in the space of
|
||||
* (0.0, 0.0) to (1.0, 1.0) -- transform the coordinates appropriately
|
||||
* if you need a different space.
|
||||
*
|
||||
* The resulting vertex coordinates should be drawn using GL_TRIANGLES,
|
||||
* and rects.numRects * 3 * 6
|
||||
*/
|
||||
void DecomposeIntoNoRepeatTriangles(const gfx::IntRect& aTexCoordRect,
|
||||
const gfx::IntSize& aTexSize,
|
||||
RectTriangles& aRects, bool aFlipY = false);
|
||||
|
||||
} // namespace gl
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // DecomposeIntoNoRepeatTriangles_h_
|
@ -22,7 +22,6 @@ if CONFIG["MOZ_GL_PROVIDER"]:
|
||||
|
||||
EXPORTS += [
|
||||
"AndroidSurfaceTexture.h",
|
||||
"DecomposeIntoNoRepeatTriangles.h",
|
||||
"ForceDiscreteGPUHelperCGL.h",
|
||||
"GfxTexturesReporter.h",
|
||||
"GLBlitHelper.h",
|
||||
@ -118,7 +117,6 @@ if CONFIG["MOZ_WAYLAND"]:
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"AndroidSurfaceTexture.cpp",
|
||||
"DecomposeIntoNoRepeatTriangles.cpp",
|
||||
"GfxTexturesReporter.cpp",
|
||||
"GLBlitHelper.cpp",
|
||||
"GLContext.cpp",
|
||||
|
Loading…
Reference in New Issue
Block a user