blob: 95dcd18867d994837871a8f7bfb5d30ca6620a09 [file] [log] [blame]
Chris Craik65fe5ee2015-01-26 18:06:29 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Chris Craik96a5c4c2015-01-27 15:46:35 -080016#include "renderstate/Scissor.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080017
Chris Craik117bdbc2015-02-05 10:12:38 -080018#include <utils/Log.h>
19
Chris Craik65fe5ee2015-01-26 18:06:29 -080020namespace android {
21namespace uirenderer {
22
23Scissor::Scissor()
24 : mEnabled(false)
25 , mScissorX(0)
26 , mScissorY(0)
27 , mScissorWidth(0)
28 , mScissorHeight(0) {
29}
30
31bool Scissor::setEnabled(bool enabled) {
32 if (mEnabled != enabled) {
33 if (enabled) {
34 glEnable(GL_SCISSOR_TEST);
35 } else {
36 glDisable(GL_SCISSOR_TEST);
37 }
38 mEnabled = enabled;
39 return true;
40 }
41 return false;
42}
43
44bool Scissor::set(GLint x, GLint y, GLint width, GLint height) {
45 if (mEnabled && (x != mScissorX || y != mScissorY
46 || width != mScissorWidth || height != mScissorHeight)) {
47
48 if (x < 0) {
49 width += x;
50 x = 0;
51 }
52 if (y < 0) {
53 height += y;
54 y = 0;
55 }
56 if (width < 0) {
57 width = 0;
58 }
59 if (height < 0) {
60 height = 0;
61 }
62 glScissor(x, y, width, height);
63
64 mScissorX = x;
65 mScissorY = y;
66 mScissorWidth = width;
67 mScissorHeight = height;
68
69 return true;
70 }
71 return false;
72}
73
74void Scissor::reset() {
75 mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
76}
77
78void Scissor::invalidate() {
79 mEnabled = glIsEnabled(GL_SCISSOR_TEST);
80 setEnabled(true);
81 reset();
82}
83
Chris Craik117bdbc2015-02-05 10:12:38 -080084void Scissor::dump() {
85 ALOGD("Scissor: enabled %d, %d %d %d %d",
86 mEnabled, mScissorX, mScissorY, mScissorWidth, mScissorHeight);
87}
88
Chris Craik65fe5ee2015-01-26 18:06:29 -080089} /* namespace uirenderer */
90} /* namespace android */
91