Clean up GrGLIRect
Renames fLeft/fBottom to fX/fY, removes the GL calls, and adds static "MakeRelativeTo" methods. Bug: skia: Change-Id: I7a09673f29a771a35cc52ec049421591d6077659 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/239413 Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
parent
f0b8bf35a8
commit
76500e5d0a
@ -1808,13 +1808,12 @@ sk_sp<GrGpuBuffer> GrGLGpu::onCreateBuffer(size_t size, GrGpuBufferType intended
|
||||
void GrGLGpu::flushScissor(const GrScissorState& scissorState, int rtWidth, int rtHeight,
|
||||
GrSurfaceOrigin rtOrigin) {
|
||||
if (scissorState.enabled()) {
|
||||
GrGLIRect scissor;
|
||||
scissor.setRelativeTo(rtHeight, scissorState.rect(), rtOrigin);
|
||||
auto scissor = GrGLIRect::MakeRelativeTo(rtOrigin, rtHeight, scissorState.rect());
|
||||
// if the scissor fully contains the viewport then we fall through and
|
||||
// disable the scissor test.
|
||||
if (!scissor.contains(rtWidth, rtHeight)) {
|
||||
if (fHWScissorSettings.fRect != scissor) {
|
||||
scissor.pushToGLScissor(this->glInterface());
|
||||
GL_CALL(Scissor(scissor.fX, scissor.fY, scissor.fWidth, scissor.fHeight));
|
||||
fHWScissorSettings.fRect = scissor;
|
||||
}
|
||||
if (kYes_TriState != fHWScissorSettings.fEnabled) {
|
||||
@ -1849,7 +1848,7 @@ void GrGLGpu::flushWindowRectangles(const GrWindowRectsState& windowState,
|
||||
GrGLIRect glwindows[GrWindowRectangles::kMaxWindows];
|
||||
const SkIRect* skwindows = windowState.windows().data();
|
||||
for (int i = 0; i < numWindows; ++i) {
|
||||
glwindows[i].setRelativeTo(rt->height(), skwindows[i], origin);
|
||||
glwindows[i].setRelativeTo(origin, rt->height(), skwindows[i]);
|
||||
}
|
||||
|
||||
GrGLenum glmode = (Mode::kExclusive == windowState.mode()) ? GR_GL_EXCLUSIVE : GR_GL_INCLUSIVE;
|
||||
@ -2183,8 +2182,7 @@ bool GrGLGpu::readOrTransferPixelsFrom(GrSurface* surface, int left, int top, in
|
||||
}
|
||||
|
||||
// the read rect is viewport-relative
|
||||
GrGLIRect readRect;
|
||||
readRect.setRelativeTo(surface->height(), left, top, width, height, kTopLeft_GrSurfaceOrigin);
|
||||
GrGLIRect readRect = {left, top, width, height};
|
||||
|
||||
// determine if GL can read using the passed rowBytes or if we need a scratch buffer.
|
||||
if (rowWidthInPixels != width) {
|
||||
@ -2204,7 +2202,7 @@ bool GrGLGpu::readOrTransferPixelsFrom(GrSurface* surface, int left, int top, in
|
||||
GR_GL_RENDERBUFFER, 0));
|
||||
}
|
||||
|
||||
GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, readRect.fWidth, readRect.fHeight,
|
||||
GL_CALL(ReadPixels(readRect.fX, readRect.fY, readRect.fWidth, readRect.fHeight,
|
||||
externalFormat, externalType, offsetOrPtr));
|
||||
|
||||
if (reattachStencil) {
|
||||
@ -2309,7 +2307,7 @@ void GrGLGpu::flushFramebufferSRGB(bool enable) {
|
||||
void GrGLGpu::flushViewport(int width, int height) {
|
||||
GrGLIRect viewport = {0, 0, width, height};
|
||||
if (fHWViewport != viewport) {
|
||||
viewport.pushToGLViewport(this->glInterface());
|
||||
GL_CALL(Viewport(viewport.fX, viewport.fY, viewport.fWidth, viewport.fHeight));
|
||||
fHWViewport = viewport;
|
||||
}
|
||||
}
|
||||
@ -2527,12 +2525,12 @@ void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) {
|
||||
r = target->width();
|
||||
t = target->height();
|
||||
} else {
|
||||
GrGLIRect rect;
|
||||
rect.setRelativeTo(rt->height(), dirtyRect, kDirtyRectOrigin);
|
||||
l = rect.fLeft;
|
||||
b = rect.fBottom;
|
||||
r = rect.fLeft + rect.fWidth;
|
||||
t = rect.fBottom + rect.fHeight;
|
||||
auto rect = GrGLIRect::MakeRelativeTo(
|
||||
kDirtyRectOrigin, rt->height(), dirtyRect);
|
||||
l = rect.fX;
|
||||
b = rect.fY;
|
||||
r = rect.fX + rect.fWidth;
|
||||
t = rect.fY + rect.fHeight;
|
||||
}
|
||||
|
||||
// BlitFrameBuffer respects the scissor, so disable it.
|
||||
@ -3090,7 +3088,8 @@ void GrGLGpu::bindFramebuffer(GrGLenum target, GrGLuint fboid) {
|
||||
if (this->caps()->workarounds().restore_scissor_on_fbo_change) {
|
||||
// The driver forgets the correct scissor when modifying the FBO binding.
|
||||
if (!fHWScissorSettings.fRect.isInvalid()) {
|
||||
fHWScissorSettings.fRect.pushToGLScissor(this->glInterface());
|
||||
const GrGLIRect& r = fHWScissorSettings.fRect;
|
||||
GL_CALL(Scissor(r.fX, r.fY, r.fWidth, r.fHeight));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,45 +10,47 @@
|
||||
#ifndef GrGLIRect_DEFINED
|
||||
#define GrGLIRect_DEFINED
|
||||
|
||||
#include "include/gpu/gl/GrGLInterface.h"
|
||||
#include "src/gpu/gl/GrGLUtil.h"
|
||||
#include "include/core/SkRect.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
|
||||
/**
|
||||
* Helper struct for dealing with the fact that Ganesh and GL use different
|
||||
* window coordinate systems (top-down vs bottom-up)
|
||||
*/
|
||||
struct GrGLIRect {
|
||||
GrGLint fLeft;
|
||||
GrGLint fBottom;
|
||||
GrGLsizei fWidth;
|
||||
GrGLsizei fHeight;
|
||||
int fX;
|
||||
int fY;
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
|
||||
static GrGLIRect MakeRelativeTo(GrSurfaceOrigin org, int rtHeight, const SkIRect& devRect) {
|
||||
GrGLIRect glRect;
|
||||
glRect.setRelativeTo(org, rtHeight, devRect);
|
||||
return glRect;
|
||||
}
|
||||
|
||||
static GrGLIRect MakeRelativeTo(GrSurfaceOrigin origin, int surfaceHeight, int leftOffset,
|
||||
int topOffset, int width, int height) {
|
||||
GrGLIRect glRect;
|
||||
glRect.setRelativeTo(origin, surfaceHeight, leftOffset, topOffset, width, height);
|
||||
return glRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* cast-safe way to treat the rect as an array of (4) ints.
|
||||
*/
|
||||
const int* asInts() const {
|
||||
return &fLeft;
|
||||
return &fX;
|
||||
|
||||
GR_STATIC_ASSERT(0 == offsetof(GrGLIRect, fLeft));
|
||||
GR_STATIC_ASSERT(4 == offsetof(GrGLIRect, fBottom));
|
||||
GR_STATIC_ASSERT(0 == offsetof(GrGLIRect, fX));
|
||||
GR_STATIC_ASSERT(4 == offsetof(GrGLIRect, fY));
|
||||
GR_STATIC_ASSERT(8 == offsetof(GrGLIRect, fWidth));
|
||||
GR_STATIC_ASSERT(12 == offsetof(GrGLIRect, fHeight));
|
||||
GR_STATIC_ASSERT(16 == sizeof(GrGLIRect)); // For an array of GrGLIRect.
|
||||
GR_STATIC_ASSERT(16 == sizeof(GrGLIRect)); // For an array of GrGLIRect.
|
||||
}
|
||||
int* asInts() { return &fLeft; }
|
||||
int* asInts() { return &fX; }
|
||||
|
||||
void pushToGLViewport(const GrGLInterface* gl) const {
|
||||
GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight));
|
||||
}
|
||||
|
||||
void pushToGLScissor(const GrGLInterface* gl) const {
|
||||
GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight));
|
||||
}
|
||||
|
||||
void setFromGLViewport(const GrGLInterface* gl) {
|
||||
GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint));
|
||||
GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this);
|
||||
}
|
||||
SkIRect asSkIRect() const { return SkIRect::MakeXYWH(fX, fY, fWidth, fHeight); }
|
||||
|
||||
// sometimes we have a SkIRect from the client that we
|
||||
// want to simultaneously make relative to GL's viewport
|
||||
@ -56,23 +58,19 @@ struct GrGLIRect {
|
||||
// The GL's viewport will always be the full size of the
|
||||
// current render target so we just pass in the rtHeight
|
||||
// here.
|
||||
void setRelativeTo(int rtHeight, const SkIRect& devRect, GrSurfaceOrigin org) {
|
||||
this->setRelativeTo(rtHeight, devRect.x(), devRect.y(), devRect.width(), devRect.height(),
|
||||
org);
|
||||
void setRelativeTo(GrSurfaceOrigin org, int rtHeight, const SkIRect& devRect) {
|
||||
this->setRelativeTo(org, rtHeight, devRect.x(), devRect.y(), devRect.width(),
|
||||
devRect.height());
|
||||
}
|
||||
|
||||
void setRelativeTo(int fullHeight,
|
||||
int leftOffset,
|
||||
int topOffset,
|
||||
int width,
|
||||
int height,
|
||||
GrSurfaceOrigin origin) {
|
||||
fLeft = leftOffset;
|
||||
void setRelativeTo(GrSurfaceOrigin origin, int surfaceHeight, int leftOffset, int topOffset,
|
||||
int width, int height) {
|
||||
fX = leftOffset;
|
||||
fWidth = width;
|
||||
if (kBottomLeft_GrSurfaceOrigin == origin) {
|
||||
fBottom = fullHeight - topOffset - height;
|
||||
fY = surfaceHeight - topOffset - height;
|
||||
} else {
|
||||
fBottom = topOffset;
|
||||
fY = topOffset;
|
||||
}
|
||||
fHeight = height;
|
||||
|
||||
@ -81,14 +79,14 @@ struct GrGLIRect {
|
||||
}
|
||||
|
||||
bool contains(int width, int height) const {
|
||||
return fLeft <= 0 &&
|
||||
fBottom <= 0 &&
|
||||
fLeft + fWidth >= width &&
|
||||
fBottom + fHeight >= height;
|
||||
return fX <= 0 &&
|
||||
fY <= 0 &&
|
||||
fX + fWidth >= width &&
|
||||
fY + fHeight >= height;
|
||||
}
|
||||
|
||||
void invalidate() {fLeft = fWidth = fBottom = fHeight = -1;}
|
||||
bool isInvalid() const { return fLeft == -1 && fWidth == -1 && fBottom == -1
|
||||
void invalidate() {fX = fWidth = fY = fHeight = -1;}
|
||||
bool isInvalid() const { return fX == -1 && fWidth == -1 && fY == -1
|
||||
&& fHeight == -1; }
|
||||
|
||||
bool operator ==(const GrGLIRect& glRect) const {
|
||||
|
Loading…
Reference in New Issue
Block a user