skia2/tests/ClipBoundsTest.cpp
Michael Ludwig e06a8972f0 GrClips know their device dimensions
If GrClips know their dimensions then getConservativeBounds() does not
need any arguments and isRRect() can remove its rtBounds argument.

I also updated GrFixedClip to report the render target bounds as a
degenerate rrect in its isRRect implementation if it was wide open. Its
apply() function was also simplified to take advantage of the prior
GrScissorState work where the rectangle was always valid to access and
contained within the render target bounds.

Change-Id: I627b97976cb176b1c80627462027034b06ad2cb2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290957
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-11 22:41:24 +00:00

51 lines
1.6 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "src/core/SkClipOpPriv.h"
#include "src/core/SkClipStack.h"
#include "src/gpu/GrClipStackClip.h"
#include "tests/Test.h"
// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
// to the render target
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) {
static const int kXSize = 100;
static const int kYSize = 100;
const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
const SkRect screen = SkRect::Make(intScreen);
SkRect clipRect(screen);
clipRect.outset(10, 10);
// create a clip stack that will (trivially) reduce to a single rect that
// is larger than the screen
SkClipStack stack;
stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false);
bool isIntersectionOfRects = true;
SkRect devStackBounds;
stack.getConservativeBounds(0, 0, kXSize, kYSize,
&devStackBounds,
&isIntersectionOfRects);
// make sure that the SkClipStack is behaving itself
REPORTER_ASSERT(reporter, screen == devStackBounds);
REPORTER_ASSERT(reporter, isIntersectionOfRects);
// wrap the SkClipStack in a GrClip
GrClipStackClip clipData({kXSize, kYSize}, &stack);
SkIRect devGrClipBound = clipData.getConservativeBounds();
// make sure that GrClip is behaving itself
REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
}