Skip to content

Commit 0baaac5

Browse files
author
Romain Guy
committed
Revert "Revert "Add more support for transformed clip rects and paths""
This reverts commit a8557d2. Change-Id: I36d4883d548fc47ba6c0b4a42012107d0d2f85a6
1 parent a8557d2 commit 0baaac5

File tree

9 files changed

+189
-77
lines changed

9 files changed

+189
-77
lines changed

core/jni/android_view_GLES20Canvas.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <OpenGLRenderer.h>
4747
#include <SkiaShader.h>
4848
#include <SkiaColorFilter.h>
49+
#include <Stencil.h>
4950
#include <Rect.h>
5051

5152
#include <TextLayout.h>
@@ -150,7 +151,7 @@ static void android_view_GLES20Canvas_finish(JNIEnv* env, jobject clazz,
150151
}
151152

152153
static jint android_view_GLES20Canvas_getStencilSize(JNIEnv* env, jobject clazz) {
153-
return OpenGLRenderer::getStencilSize();
154+
return Stencil::getStencilSize();
154155
}
155156

156157
// ----------------------------------------------------------------------------

libs/hwui/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ifeq ($(USE_OPENGL_RENDERER),true)
2828
SkiaColorFilter.cpp \
2929
SkiaShader.cpp \
3030
Snapshot.cpp \
31+
Stencil.cpp \
3132
TextureCache.cpp \
3233
TextDropShadowCache.cpp
3334

libs/hwui/Caches.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "TextDropShadowCache.h"
3939
#include "FboCache.h"
4040
#include "ResourceCache.h"
41+
#include "Stencil.h"
4142
#include "Dither.h"
4243

4344
namespace android {
@@ -252,10 +253,14 @@ class ANDROID_API Caches: public Singleton<Caches> {
252253
TextDropShadowCache dropShadowCache;
253254
FboCache fboCache;
254255
ResourceCache resourceCache;
255-
Dither dither;
256256

257257
GammaFontRenderer* fontRenderer;
258258

259+
Dither dither;
260+
#if STENCIL_BUFFER_SIZE
261+
Stencil stencil;
262+
#endif
263+
259264
// Debug methods
260265
PFNGLINSERTEVENTMARKEREXTPROC eventMark;
261266
PFNGLPUSHGROUPMARKEREXTPROC startMark;

libs/hwui/OpenGLRenderer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ void OpenGLRenderer::endMark() const {
139139
// Setup
140140
///////////////////////////////////////////////////////////////////////////////
141141

142-
uint32_t OpenGLRenderer::getStencilSize() {
143-
return STENCIL_BUFFER_SIZE;
144-
}
145-
146142
bool OpenGLRenderer::isDeferred() {
147143
return false;
148144
}

libs/hwui/OpenGLRenderer.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,6 @@ class OpenGLRenderer {
207207

208208
SkPaint* filterPaint(SkPaint* paint);
209209

210-
/**
211-
* Returns the desired size for the stencil buffer. If the returned value
212-
* is 0, then no stencil buffer is required.
213-
*/
214-
ANDROID_API static uint32_t getStencilSize();
215-
216210
/**
217211
* Sets the alpha on the current snapshot. This alpha value will be modulated
218212
* with other alpha values when drawing primitives.

libs/hwui/Snapshot.cpp

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Snapshot::Snapshot(const sp<Snapshot>& s, int saveFlags):
5757
clipRect = &mClipRectRoot;
5858
#if STENCIL_BUFFER_SIZE
5959
if (s->clipRegion) {
60-
mClipRegionRoot.merge(*s->clipRegion);
60+
mClipRegionRoot.op(*s->clipRegion, SkRegion::kUnion_Op);
6161
clipRegion = &mClipRegionRoot;
6262
}
6363
#endif
@@ -84,20 +84,19 @@ void Snapshot::ensureClipRegion() {
8484
#if STENCIL_BUFFER_SIZE
8585
if (!clipRegion) {
8686
clipRegion = &mClipRegionRoot;
87-
android::Rect tmp(clipRect->left, clipRect->top, clipRect->right, clipRect->bottom);
88-
clipRegion->set(tmp);
87+
clipRegion->setRect(clipRect->left, clipRect->top, clipRect->right, clipRect->bottom);
8988
}
9089
#endif
9190
}
9291

9392
void Snapshot::copyClipRectFromRegion() {
9493
#if STENCIL_BUFFER_SIZE
9594
if (!clipRegion->isEmpty()) {
96-
android::Rect bounds(clipRegion->bounds());
97-
clipRect->set(bounds.left, bounds.top, bounds.right, bounds.bottom);
95+
const SkIRect& bounds = clipRegion->getBounds();
96+
clipRect->set(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
9897

9998
if (clipRegion->isRect()) {
100-
clipRegion->clear();
99+
clipRegion->setEmpty();
101100
clipRegion = NULL;
102101
}
103102
} else {
@@ -107,43 +106,11 @@ void Snapshot::copyClipRectFromRegion() {
107106
#endif
108107
}
109108

110-
bool Snapshot::clipRegionOr(float left, float top, float right, float bottom) {
109+
bool Snapshot::clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op) {
111110
#if STENCIL_BUFFER_SIZE
112-
android::Rect tmp(left, top, right, bottom);
113-
clipRegion->orSelf(tmp);
114-
copyClipRectFromRegion();
115-
return true;
116-
#else
117-
return false;
118-
#endif
119-
}
120-
121-
bool Snapshot::clipRegionXor(float left, float top, float right, float bottom) {
122-
#if STENCIL_BUFFER_SIZE
123-
android::Rect tmp(left, top, right, bottom);
124-
clipRegion->xorSelf(tmp);
125-
copyClipRectFromRegion();
126-
return true;
127-
#else
128-
return false;
129-
#endif
130-
}
131-
132-
bool Snapshot::clipRegionAnd(float left, float top, float right, float bottom) {
133-
#if STENCIL_BUFFER_SIZE
134-
android::Rect tmp(left, top, right, bottom);
135-
clipRegion->andSelf(tmp);
136-
copyClipRectFromRegion();
137-
return true;
138-
#else
139-
return false;
140-
#endif
141-
}
142-
143-
bool Snapshot::clipRegionNand(float left, float top, float right, float bottom) {
144-
#if STENCIL_BUFFER_SIZE
145-
android::Rect tmp(left, top, right, bottom);
146-
clipRegion->subtractSelf(tmp);
111+
SkIRect tmp;
112+
tmp.set(left, top, right, bottom);
113+
clipRegion->op(tmp, op);
147114
copyClipRectFromRegion();
148115
return true;
149116
#else
@@ -161,14 +128,9 @@ bool Snapshot::clipTransformed(const Rect& r, SkRegion::Op op) {
161128
bool clipped = false;
162129

163130
switch (op) {
164-
case SkRegion::kDifference_Op: {
165-
ensureClipRegion();
166-
clipped = clipRegionNand(r.left, r.top, r.right, r.bottom);
167-
break;
168-
}
169131
case SkRegion::kIntersect_Op: {
170132
if (CC_UNLIKELY(clipRegion)) {
171-
clipped = clipRegionOr(r.left, r.top, r.right, r.bottom);
133+
clipped = clipRegionOp(r.left, r.top, r.right, r.bottom, SkRegion::kIntersect_Op);
172134
} else {
173135
clipped = clipRect->intersect(r);
174136
if (!clipped) {
@@ -180,26 +142,22 @@ bool Snapshot::clipTransformed(const Rect& r, SkRegion::Op op) {
180142
}
181143
case SkRegion::kUnion_Op: {
182144
if (CC_UNLIKELY(clipRegion)) {
183-
clipped = clipRegionAnd(r.left, r.top, r.right, r.bottom);
145+
clipped = clipRegionOp(r.left, r.top, r.right, r.bottom, SkRegion::kUnion_Op);
184146
} else {
185147
clipped = clipRect->unionWith(r);
186148
}
187149
break;
188150
}
189-
case SkRegion::kXOR_Op: {
190-
ensureClipRegion();
191-
clipped = clipRegionXor(r.left, r.top, r.right, r.bottom);
192-
break;
193-
}
194-
case SkRegion::kReverseDifference_Op: {
195-
// TODO!!!!!!!
196-
break;
197-
}
198151
case SkRegion::kReplace_Op: {
199152
setClip(r.left, r.top, r.right, r.bottom);
200153
clipped = true;
201154
break;
202155
}
156+
default: {
157+
ensureClipRegion();
158+
clipped = clipRegionOp(r.left, r.top, r.right, r.bottom, op);
159+
break;
160+
}
203161
}
204162

205163
if (clipped) {
@@ -213,7 +171,7 @@ void Snapshot::setClip(float left, float top, float right, float bottom) {
213171
clipRect->set(left, top, right, bottom);
214172
#if STENCIL_BUFFER_SIZE
215173
if (clipRegion) {
216-
clipRegion->clear();
174+
clipRegion->setEmpty();
217175
clipRegion = NULL;
218176
}
219177
#endif

libs/hwui/Snapshot.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class Snapshot: public LightRefBase<Snapshot> {
198198
*
199199
* This field is used only if STENCIL_BUFFER_SIZE is > 0.
200200
*/
201-
Region* clipRegion;
201+
SkRegion* clipRegion;
202202

203203
/**
204204
* The ancestor layer's dirty region.
@@ -223,17 +223,14 @@ class Snapshot: public LightRefBase<Snapshot> {
223223
void ensureClipRegion();
224224
void copyClipRectFromRegion();
225225

226-
bool clipRegionOr(float left, float top, float right, float bottom);
227-
bool clipRegionXor(float left, float top, float right, float bottom);
228-
bool clipRegionAnd(float left, float top, float right, float bottom);
229-
bool clipRegionNand(float left, float top, float right, float bottom);
226+
bool clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op);
230227

231228
mat4 mTransformRoot;
232229
Rect mClipRectRoot;
233230
Rect mLocalClip;
234231

235232
#if STENCIL_BUFFER_SIZE
236-
Region mClipRegionRoot;
233+
SkRegion mClipRegionRoot;
237234
#endif
238235

239236
}; // class Snapshot

libs/hwui/Stencil.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2012 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+
*/
16+
17+
#include <GLES2/gl2.h>
18+
19+
#include "Properties.h"
20+
#include "Stencil.h"
21+
22+
namespace android {
23+
namespace uirenderer {
24+
25+
Stencil::Stencil(): mState(kDisabled) {
26+
}
27+
28+
uint32_t Stencil::getStencilSize() {
29+
return STENCIL_BUFFER_SIZE;
30+
}
31+
32+
void Stencil::clear() {
33+
glClearStencil(0);
34+
glClear(GL_STENCIL_BUFFER_BIT);
35+
}
36+
37+
void Stencil::enableTest() {
38+
if (mState != kTest) {
39+
enable();
40+
glStencilFunc(GL_LESS, 0x0, 0x1);
41+
// We only want to test, let's keep everything
42+
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
43+
mState = kTest;
44+
}
45+
}
46+
47+
void Stencil::enableWrite() {
48+
if (mState != kWrite) {
49+
enable();
50+
glStencilFunc(GL_ALWAYS, 0x1, 0x1);
51+
// The test always passes so the first two values are meaningless
52+
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
53+
mState = kWrite;
54+
}
55+
}
56+
57+
void Stencil::enable() {
58+
if (!mState == kDisabled) {
59+
glEnable(GL_STENCIL_TEST);
60+
}
61+
}
62+
63+
void Stencil::disable() {
64+
if (mState != kDisabled) {
65+
glDisable(GL_STENCIL_TEST);
66+
mState = kDisabled;
67+
}
68+
}
69+
70+
}; // namespace uirenderer
71+
}; // namespace android

0 commit comments

Comments
 (0)