CanvasState.cpp revision 139088228faa7f3c446af7387e017933998a5570
114e513058ed4168c94e015638d16f5f87fd8063aChris Craik/*
214e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Copyright (C) 2014 The Android Open Source Project
314e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
414e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Licensed under the Apache License, Version 2.0 (the "License");
514e513058ed4168c94e015638d16f5f87fd8063aChris Craik * you may not use this file except in compliance with the License.
614e513058ed4168c94e015638d16f5f87fd8063aChris Craik * You may obtain a copy of the License at
714e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
814e513058ed4168c94e015638d16f5f87fd8063aChris Craik *      http://www.apache.org/licenses/LICENSE-2.0
914e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
1014e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Unless required by applicable law or agreed to in writing, software
1114e513058ed4168c94e015638d16f5f87fd8063aChris Craik * distributed under the License is distributed on an "AS IS" BASIS,
1214e513058ed4168c94e015638d16f5f87fd8063aChris Craik * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1314e513058ed4168c94e015638d16f5f87fd8063aChris Craik * See the License for the specific language governing permissions and
1414e513058ed4168c94e015638d16f5f87fd8063aChris Craik * limitations under the License.
1514e513058ed4168c94e015638d16f5f87fd8063aChris Craik */
1614e513058ed4168c94e015638d16f5f87fd8063aChris Craik
17deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik#define LOG_TAG "OpenGLRenderer"
18deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
1914e513058ed4168c94e015638d16f5f87fd8063aChris Craik#include <SkCanvas.h>
2014e513058ed4168c94e015638d16f5f87fd8063aChris Craik
2114e513058ed4168c94e015638d16f5f87fd8063aChris Craik#include "StatefulBaseRenderer.h"
2214e513058ed4168c94e015638d16f5f87fd8063aChris Craik
2314e513058ed4168c94e015638d16f5f87fd8063aChris Craiknamespace android {
2414e513058ed4168c94e015638d16f5f87fd8063aChris Craiknamespace uirenderer {
2514e513058ed4168c94e015638d16f5f87fd8063aChris Craik
2614e513058ed4168c94e015638d16f5f87fd8063aChris CraikStatefulBaseRenderer::StatefulBaseRenderer() :
27d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        mDirtyClip(false), mWidth(-1), mHeight(-1),
28797b95b26bbb7557678af78b9a2a61830158920fChris Craik        mSaveCount(1), mFirstSnapshot(new Snapshot), mSnapshot(mFirstSnapshot),
29797b95b26bbb7557678af78b9a2a61830158920fChris Craik        mLightCenter(FLT_MIN, FLT_MIN, FLT_MIN), mLightRadius(FLT_MIN) {
3014e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
3114e513058ed4168c94e015638d16f5f87fd8063aChris Craik
3214e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::initializeSaveStack(float clipLeft, float clipTop,
3314e513058ed4168c94e015638d16f5f87fd8063aChris Craik        float clipRight, float clipBottom) {
3414e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot = new Snapshot(mFirstSnapshot,
3514e513058ed4168c94e015638d16f5f87fd8063aChris Craik            SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
3614e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->setClip(clipLeft, clipTop, clipRight, clipBottom);
3714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->fbo = getTargetFbo();
3814e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSaveCount = 1;
3914e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
4014e513058ed4168c94e015638d16f5f87fd8063aChris Craik
41797b95b26bbb7557678af78b9a2a61830158920fChris Craikvoid StatefulBaseRenderer::setViewport(int width, int height) {
4214e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mWidth = width;
4314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mHeight = height;
44a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    mFirstSnapshot->initializeViewport(width, height);
45797b95b26bbb7557678af78b9a2a61830158920fChris Craik    onViewportInitialized();
46797b95b26bbb7557678af78b9a2a61830158920fChris Craik}
47797b95b26bbb7557678af78b9a2a61830158920fChris Craik
48797b95b26bbb7557678af78b9a2a61830158920fChris Craikvoid StatefulBaseRenderer::initializeLight(const Vector3& lightCenter, float lightRadius) {
49797b95b26bbb7557678af78b9a2a61830158920fChris Craik    mLightCenter = lightCenter;
50797b95b26bbb7557678af78b9a2a61830158920fChris Craik    mLightRadius = lightRadius;
5114e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
5214e513058ed4168c94e015638d16f5f87fd8063aChris Craik
5314e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
5414e513058ed4168c94e015638d16f5f87fd8063aChris Craik// Save (layer)
5514e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
5614e513058ed4168c94e015638d16f5f87fd8063aChris Craik
5714e513058ed4168c94e015638d16f5f87fd8063aChris Craik/**
5814e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Non-virtual implementation of save, guaranteed to save without side-effects
5914e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
6014e513058ed4168c94e015638d16f5f87fd8063aChris Craik * The approach here and in restoreSnapshot(), allows subclasses to directly manipulate the save
6114e513058ed4168c94e015638d16f5f87fd8063aChris Craik * stack, and ensures restoreToCount() doesn't call back into subclass overrides.
6214e513058ed4168c94e015638d16f5f87fd8063aChris Craik */
6314e513058ed4168c94e015638d16f5f87fd8063aChris Craikint StatefulBaseRenderer::saveSnapshot(int flags) {
6414e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot = new Snapshot(mSnapshot, flags);
6514e513058ed4168c94e015638d16f5f87fd8063aChris Craik    return mSaveCount++;
6614e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
6714e513058ed4168c94e015638d16f5f87fd8063aChris Craik
6814e513058ed4168c94e015638d16f5f87fd8063aChris Craikint StatefulBaseRenderer::save(int flags) {
6914e513058ed4168c94e015638d16f5f87fd8063aChris Craik    return saveSnapshot(flags);
7014e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
7114e513058ed4168c94e015638d16f5f87fd8063aChris Craik
7214e513058ed4168c94e015638d16f5f87fd8063aChris Craik/**
7314e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Non-virtual implementation of restore, guaranteed to restore without side-effects.
7414e513058ed4168c94e015638d16f5f87fd8063aChris Craik */
7514e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::restoreSnapshot() {
7614e513058ed4168c94e015638d16f5f87fd8063aChris Craik    sp<Snapshot> toRemove = mSnapshot;
7714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    sp<Snapshot> toRestore = mSnapshot->previous;
7814e513058ed4168c94e015638d16f5f87fd8063aChris Craik
7914e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSaveCount--;
8014e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot = toRestore;
8114e513058ed4168c94e015638d16f5f87fd8063aChris Craik
8214e513058ed4168c94e015638d16f5f87fd8063aChris Craik    // subclass handles restore implementation
8314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    onSnapshotRestored(*toRemove, *toRestore);
8414e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
8514e513058ed4168c94e015638d16f5f87fd8063aChris Craik
8614e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::restore() {
8714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    if (mSaveCount > 1) {
8814e513058ed4168c94e015638d16f5f87fd8063aChris Craik        restoreSnapshot();
8914e513058ed4168c94e015638d16f5f87fd8063aChris Craik    }
9014e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
9114e513058ed4168c94e015638d16f5f87fd8063aChris Craik
9214e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::restoreToCount(int saveCount) {
9314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    if (saveCount < 1) saveCount = 1;
9414e513058ed4168c94e015638d16f5f87fd8063aChris Craik
9514e513058ed4168c94e015638d16f5f87fd8063aChris Craik    while (mSaveCount > saveCount) {
9614e513058ed4168c94e015638d16f5f87fd8063aChris Craik        restoreSnapshot();
9714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    }
9814e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
9914e513058ed4168c94e015638d16f5f87fd8063aChris Craik
10014e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
10114e513058ed4168c94e015638d16f5f87fd8063aChris Craik// Matrix
10214e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
10314e513058ed4168c94e015638d16f5f87fd8063aChris Craik
10414e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::getMatrix(SkMatrix* matrix) const {
10514e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->copyTo(*matrix);
10614e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
10714e513058ed4168c94e015638d16f5f87fd8063aChris Craik
10814e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::translate(float dx, float dy, float dz) {
10914e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->translate(dx, dy, dz);
11014e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
11114e513058ed4168c94e015638d16f5f87fd8063aChris Craik
11214e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::rotate(float degrees) {
11314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->rotate(degrees, 0.0f, 0.0f, 1.0f);
11414e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
11514e513058ed4168c94e015638d16f5f87fd8063aChris Craik
11614e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::scale(float sx, float sy) {
11714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->scale(sx, sy, 1.0f);
11814e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
11914e513058ed4168c94e015638d16f5f87fd8063aChris Craik
12014e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::skew(float sx, float sy) {
12114e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->skew(sx, sy);
12214e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
12314e513058ed4168c94e015638d16f5f87fd8063aChris Craik
124139088228faa7f3c446af7387e017933998a5570Derek Sollenbergervoid StatefulBaseRenderer::setMatrix(const SkMatrix& matrix) {
125139088228faa7f3c446af7387e017933998a5570Derek Sollenberger    mSnapshot->transform->load(matrix);
12614e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
12714e513058ed4168c94e015638d16f5f87fd8063aChris Craik
12814e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::setMatrix(const Matrix4& matrix) {
12914e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->load(matrix);
13014e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
13114e513058ed4168c94e015638d16f5f87fd8063aChris Craik
132139088228faa7f3c446af7387e017933998a5570Derek Sollenbergervoid StatefulBaseRenderer::concatMatrix(const SkMatrix& matrix) {
133139088228faa7f3c446af7387e017933998a5570Derek Sollenberger    mat4 transform(matrix);
13414e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->multiply(transform);
13514e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
13614e513058ed4168c94e015638d16f5f87fd8063aChris Craik
13714e513058ed4168c94e015638d16f5f87fd8063aChris Craikvoid StatefulBaseRenderer::concatMatrix(const Matrix4& matrix) {
13814e513058ed4168c94e015638d16f5f87fd8063aChris Craik    mSnapshot->transform->multiply(matrix);
13914e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
14014e513058ed4168c94e015638d16f5f87fd8063aChris Craik
14114e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
14214e513058ed4168c94e015638d16f5f87fd8063aChris Craik// Clip
14314e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
14414e513058ed4168c94e015638d16f5f87fd8063aChris Craik
145d6b65f67717025b1162f86f04e2caa5723566cacChris Craikbool StatefulBaseRenderer::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
146d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    if (CC_LIKELY(currentTransform()->rectToRect())) {
147d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        mDirtyClip |= mSnapshot->clip(left, top, right, bottom, op);
148d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        return !mSnapshot->clipRect->isEmpty();
149d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    }
150d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
151d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    SkPath path;
152d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    path.addRect(left, top, right, bottom);
153d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
154d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    return StatefulBaseRenderer::clipPath(&path, op);
155d6b65f67717025b1162f86f04e2caa5723566cacChris Craik}
156d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
157d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craikbool StatefulBaseRenderer::clipPath(const SkPath* path, SkRegion::Op op) {
158d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    SkMatrix transform;
159d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    currentTransform()->copyTo(transform);
160d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
161d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    SkPath transformed;
162d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    path->transform(transform, &transformed);
163d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
164d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    SkRegion clip;
165d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    if (!mSnapshot->previous->clipRegion->isEmpty()) {
166d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        clip.setRegion(*mSnapshot->previous->clipRegion);
167d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    } else {
168d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        if (mSnapshot->previous == firstSnapshot()) {
169d6b65f67717025b1162f86f04e2caa5723566cacChris Craik            clip.setRect(0, 0, getWidth(), getHeight());
170d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        } else {
171d6b65f67717025b1162f86f04e2caa5723566cacChris Craik            Rect* bounds = mSnapshot->previous->clipRect;
172d6b65f67717025b1162f86f04e2caa5723566cacChris Craik            clip.setRect(bounds->left, bounds->top, bounds->right, bounds->bottom);
173d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        }
174d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    }
175d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
176d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    SkRegion region;
177d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    region.setPath(transformed, clip);
178d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
179d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    mDirtyClip |= mSnapshot->clipRegionTransformed(region, op);
180d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    return !mSnapshot->clipRect->isEmpty();
181d6b65f67717025b1162f86f04e2caa5723566cacChris Craik}
182d6b65f67717025b1162f86f04e2caa5723566cacChris Craik
183d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craikbool StatefulBaseRenderer::clipRegion(const SkRegion* region, SkRegion::Op op) {
184d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    mDirtyClip |= mSnapshot->clipRegionTransformed(*region, op);
185d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    return !mSnapshot->clipRect->isEmpty();
186d6b65f67717025b1162f86f04e2caa5723566cacChris Craik}
18714e513058ed4168c94e015638d16f5f87fd8063aChris Craik
188deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craikvoid StatefulBaseRenderer::setClippingOutline(LinearAllocator& allocator, const Outline* outline) {
189deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    mSnapshot->setClippingOutline(allocator, outline);
190deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik}
191deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
19214e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
19314e513058ed4168c94e015638d16f5f87fd8063aChris Craik// Quick Rejection
19414e513058ed4168c94e015638d16f5f87fd8063aChris Craik///////////////////////////////////////////////////////////////////////////////
19514e513058ed4168c94e015638d16f5f87fd8063aChris Craik
19614e513058ed4168c94e015638d16f5f87fd8063aChris Craik/**
19714e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Calculates whether content drawn within the passed bounds would be outside of, or intersect with
19814e513058ed4168c94e015638d16f5f87fd8063aChris Craik * the clipRect. Does not modify the scissor.
19914e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
20014e513058ed4168c94e015638d16f5f87fd8063aChris Craik * @param clipRequired if not null, will be set to true if element intersects clip
20114e513058ed4168c94e015638d16f5f87fd8063aChris Craik *         (and wasn't rejected)
20214e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
20314e513058ed4168c94e015638d16f5f87fd8063aChris Craik * @param snapOut if set, the geometry will be treated as having an AA ramp.
20414e513058ed4168c94e015638d16f5f87fd8063aChris Craik *         See Rect::snapGeometryToPixelBoundaries()
20514e513058ed4168c94e015638d16f5f87fd8063aChris Craik */
20614e513058ed4168c94e015638d16f5f87fd8063aChris Craikbool StatefulBaseRenderer::calculateQuickRejectForScissor(float left, float top,
207deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        float right, float bottom,
208deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        bool* clipRequired, bool* roundRectClipRequired,
209deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        bool snapOut) const {
21014e513058ed4168c94e015638d16f5f87fd8063aChris Craik    if (mSnapshot->isIgnored() || bottom <= top || right <= left) {
21114e513058ed4168c94e015638d16f5f87fd8063aChris Craik        return true;
21214e513058ed4168c94e015638d16f5f87fd8063aChris Craik    }
21314e513058ed4168c94e015638d16f5f87fd8063aChris Craik
21414e513058ed4168c94e015638d16f5f87fd8063aChris Craik    Rect r(left, top, right, bottom);
215d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    currentTransform()->mapRect(r);
21614e513058ed4168c94e015638d16f5f87fd8063aChris Craik    r.snapGeometryToPixelBoundaries(snapOut);
21714e513058ed4168c94e015638d16f5f87fd8063aChris Craik
218d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    Rect clipRect(*currentClipRect());
21914e513058ed4168c94e015638d16f5f87fd8063aChris Craik    clipRect.snapToPixelBoundaries();
22014e513058ed4168c94e015638d16f5f87fd8063aChris Craik
22114e513058ed4168c94e015638d16f5f87fd8063aChris Craik    if (!clipRect.intersects(r)) return true;
22214e513058ed4168c94e015638d16f5f87fd8063aChris Craik
22314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    // clip is required if geometry intersects clip rect
224deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    if (clipRequired) {
225deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        *clipRequired = !clipRect.contains(r);
226deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    }
227deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
228deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    // round rect clip is required if RR clip exists, and geometry intersects its corners
229deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    if (roundRectClipRequired) {
230deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        *roundRectClipRequired = mSnapshot->roundRectClipState != NULL
231deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik                && mSnapshot->roundRectClipState->areaRequiresRoundRectClip(r);
232deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    }
23314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    return false;
23414e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
23514e513058ed4168c94e015638d16f5f87fd8063aChris Craik
23614e513058ed4168c94e015638d16f5f87fd8063aChris Craik/**
23714e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Returns false if drawing won't be clipped out.
23814e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
23914e513058ed4168c94e015638d16f5f87fd8063aChris Craik * Makes the decision conservatively, by rounding out the mapped rect before comparing with the
24014e513058ed4168c94e015638d16f5f87fd8063aChris Craik * clipRect. To be used when perfect, pixel accuracy is not possible (esp. with tessellation) but
24114e513058ed4168c94e015638d16f5f87fd8063aChris Craik * rejection is still desired.
24214e513058ed4168c94e015638d16f5f87fd8063aChris Craik *
24314e513058ed4168c94e015638d16f5f87fd8063aChris Craik * This function, unlike quickRejectSetupScissor, should be used where precise geometry information
24414e513058ed4168c94e015638d16f5f87fd8063aChris Craik * isn't known (esp. when geometry adjusts based on scale). Generally, this will be first pass
24514e513058ed4168c94e015638d16f5f87fd8063aChris Craik * rejection where precise rejection isn't important, or precise information isn't available.
24614e513058ed4168c94e015638d16f5f87fd8063aChris Craik */
24714e513058ed4168c94e015638d16f5f87fd8063aChris Craikbool StatefulBaseRenderer::quickRejectConservative(float left, float top,
24814e513058ed4168c94e015638d16f5f87fd8063aChris Craik        float right, float bottom) const {
24914e513058ed4168c94e015638d16f5f87fd8063aChris Craik    if (mSnapshot->isIgnored() || bottom <= top || right <= left) {
25014e513058ed4168c94e015638d16f5f87fd8063aChris Craik        return true;
25114e513058ed4168c94e015638d16f5f87fd8063aChris Craik    }
25214e513058ed4168c94e015638d16f5f87fd8063aChris Craik
25314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    Rect r(left, top, right, bottom);
254d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    currentTransform()->mapRect(r);
25514e513058ed4168c94e015638d16f5f87fd8063aChris Craik    r.roundOut(); // rounded out to be conservative
25614e513058ed4168c94e015638d16f5f87fd8063aChris Craik
257d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    Rect clipRect(*currentClipRect());
25814e513058ed4168c94e015638d16f5f87fd8063aChris Craik    clipRect.snapToPixelBoundaries();
25914e513058ed4168c94e015638d16f5f87fd8063aChris Craik
26014e513058ed4168c94e015638d16f5f87fd8063aChris Craik    if (!clipRect.intersects(r)) return true;
26114e513058ed4168c94e015638d16f5f87fd8063aChris Craik
26214e513058ed4168c94e015638d16f5f87fd8063aChris Craik    return false;
26314e513058ed4168c94e015638d16f5f87fd8063aChris Craik}
26414e513058ed4168c94e015638d16f5f87fd8063aChris Craik
26514e513058ed4168c94e015638d16f5f87fd8063aChris Craik}; // namespace uirenderer
26614e513058ed4168c94e015638d16f5f87fd8063aChris Craik}; // namespace android
267