2015-10-05 13:00:52 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BakedOpRenderer.h"
|
|
|
|
|
|
|
|
#include "Caches.h"
|
|
|
|
#include "Glop.h"
|
|
|
|
#include "GlopBuilder.h"
|
2015-11-11 16:42:34 -08:00
|
|
|
#include "renderstate/OffscreenBufferPool.h"
|
2015-10-05 13:00:52 -07:00
|
|
|
#include "renderstate/RenderState.h"
|
|
|
|
#include "utils/GLUtils.h"
|
2015-11-11 16:42:34 -08:00
|
|
|
#include "VertexBuffer.h"
|
2015-10-05 13:00:52 -07:00
|
|
|
|
2015-11-19 13:02:43 -08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2015-10-05 13:00:52 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2015-11-06 10:59:56 -08:00
|
|
|
OffscreenBuffer* BakedOpRenderer::startTemporaryLayer(uint32_t width, uint32_t height) {
|
2015-11-11 16:42:34 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF(mRenderTarget.offscreenBuffer, "already has layer...");
|
|
|
|
|
2017-06-13 18:25:32 -07:00
|
|
|
OffscreenBuffer* buffer = mRenderState.layerPool().get(
|
|
|
|
mRenderState, width, height, mWideColorGamut);
|
2015-11-13 10:55:30 -08:00
|
|
|
startRepaintLayer(buffer, Rect(width, height));
|
2015-10-28 16:50:44 -07:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2016-04-05 13:18:56 -07:00
|
|
|
void BakedOpRenderer::recycleTemporaryLayer(OffscreenBuffer* offscreenBuffer) {
|
|
|
|
mRenderState.layerPool().putOrDelete(offscreenBuffer);
|
|
|
|
}
|
|
|
|
|
2015-11-13 10:55:30 -08:00
|
|
|
void BakedOpRenderer::startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect) {
|
2015-11-06 10:59:56 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF(mRenderTarget.offscreenBuffer, "already has layer...");
|
|
|
|
|
2016-03-11 19:16:21 -08:00
|
|
|
// subtract repaintRect from region, since it will be regenerated
|
|
|
|
if (repaintRect.contains(0, 0,
|
|
|
|
offscreenBuffer->viewportWidth, offscreenBuffer->viewportHeight)) {
|
|
|
|
// repaint full layer, so throw away entire region
|
|
|
|
offscreenBuffer->region.clear();
|
|
|
|
} else {
|
|
|
|
offscreenBuffer->region.subtractSelf(android::Rect(repaintRect.left, repaintRect.top,
|
|
|
|
repaintRect.right, repaintRect.bottom));
|
|
|
|
}
|
|
|
|
|
2015-10-28 16:50:44 -07:00
|
|
|
mRenderTarget.offscreenBuffer = offscreenBuffer;
|
2016-05-12 17:48:51 -07:00
|
|
|
mRenderTarget.offscreenBuffer->hasRenderedSinceRepaint = false;
|
2015-10-23 14:33:42 -07:00
|
|
|
|
2015-10-26 15:49:56 -07:00
|
|
|
// create and bind framebuffer
|
2016-01-29 14:18:22 -08:00
|
|
|
mRenderTarget.frameBufferId = mRenderState.createFramebuffer();
|
2015-10-26 15:49:56 -07:00
|
|
|
mRenderState.bindFramebuffer(mRenderTarget.frameBufferId);
|
2015-10-23 14:33:42 -07:00
|
|
|
|
|
|
|
// attach the texture to the FBO
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
2015-11-10 12:19:17 -08:00
|
|
|
offscreenBuffer->texture.id(), 0);
|
2016-01-22 16:28:07 -08:00
|
|
|
GL_CHECKPOINT(LOW);
|
|
|
|
|
2016-06-09 16:57:11 -07:00
|
|
|
int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
LOG_ALWAYS_FATAL_IF(status != GL_FRAMEBUFFER_COMPLETE,
|
|
|
|
"framebuffer incomplete, status %d, textureId %d, size %dx%d",
|
|
|
|
status,
|
|
|
|
offscreenBuffer->texture.id(),
|
|
|
|
offscreenBuffer->texture.width(),
|
|
|
|
offscreenBuffer->texture.height());
|
2015-10-23 14:33:42 -07:00
|
|
|
|
|
|
|
// Change the viewport & ortho projection
|
2015-10-28 16:50:44 -07:00
|
|
|
setViewport(offscreenBuffer->viewportWidth, offscreenBuffer->viewportHeight);
|
2015-11-13 10:55:30 -08:00
|
|
|
|
|
|
|
clearColorBuffer(repaintRect);
|
2015-10-23 14:33:42 -07:00
|
|
|
}
|
|
|
|
|
2015-10-26 15:49:56 -07:00
|
|
|
void BakedOpRenderer::endLayer() {
|
2016-01-04 15:09:19 -08:00
|
|
|
if (mRenderTarget.stencil) {
|
|
|
|
// if stencil was used for clipping, detach it and return it to pool
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
|
2016-01-22 16:28:07 -08:00
|
|
|
GL_CHECKPOINT(MODERATE);
|
2016-01-04 15:09:19 -08:00
|
|
|
mCaches.renderBufferCache.put(mRenderTarget.stencil);
|
|
|
|
mRenderTarget.stencil = nullptr;
|
|
|
|
}
|
2015-12-22 16:32:23 -08:00
|
|
|
mRenderTarget.lastStencilClip = nullptr;
|
2015-10-23 14:33:42 -07:00
|
|
|
|
2016-01-04 15:09:19 -08:00
|
|
|
mRenderTarget.offscreenBuffer->updateMeshFromRegion();
|
|
|
|
mRenderTarget.offscreenBuffer = nullptr; // It's in drawLayerOp's hands now.
|
|
|
|
|
2015-10-23 14:33:42 -07:00
|
|
|
// Detach the texture from the FBO
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
2016-01-22 16:28:07 -08:00
|
|
|
GL_CHECKPOINT(LOW);
|
2015-10-26 15:49:56 -07:00
|
|
|
mRenderState.deleteFramebuffer(mRenderTarget.frameBufferId);
|
2015-12-22 16:32:23 -08:00
|
|
|
mRenderTarget.frameBufferId = 0;
|
2015-10-23 14:33:42 -07:00
|
|
|
}
|
|
|
|
|
2016-01-07 17:41:40 -08:00
|
|
|
OffscreenBuffer* BakedOpRenderer::copyToLayer(const Rect& area) {
|
2016-06-01 14:53:35 -07:00
|
|
|
const uint32_t width = area.getWidth();
|
|
|
|
const uint32_t height = area.getHeight();
|
2017-06-13 18:25:32 -07:00
|
|
|
OffscreenBuffer* buffer = mRenderState.layerPool().get(
|
|
|
|
mRenderState, width, height, mWideColorGamut);
|
2016-06-01 14:53:35 -07:00
|
|
|
if (!area.isEmpty() && width != 0 && height != 0) {
|
2016-01-07 17:41:40 -08:00
|
|
|
mCaches.textureState().activateTexture(0);
|
2015-11-10 12:19:17 -08:00
|
|
|
mCaches.textureState().bindTexture(buffer->texture.id());
|
2016-01-07 17:41:40 -08:00
|
|
|
|
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
|
2016-06-01 14:53:35 -07:00
|
|
|
area.left, mRenderTarget.viewportHeight - area.bottom, width, height);
|
2016-01-07 17:41:40 -08:00
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2015-11-13 10:55:30 -08:00
|
|
|
void BakedOpRenderer::startFrame(uint32_t width, uint32_t height, const Rect& repaintRect) {
|
2015-12-22 16:32:23 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF(mRenderTarget.frameBufferId != 0, "primary framebufferId must be 0");
|
2015-10-26 15:49:56 -07:00
|
|
|
mRenderState.bindFramebuffer(0);
|
|
|
|
setViewport(width, height);
|
2015-10-05 13:00:52 -07:00
|
|
|
|
2015-10-26 15:49:56 -07:00
|
|
|
if (!mOpaque) {
|
2015-11-13 10:55:30 -08:00
|
|
|
clearColorBuffer(repaintRect);
|
2015-10-05 13:00:52 -07:00
|
|
|
}
|
2015-12-22 16:32:23 -08:00
|
|
|
|
|
|
|
mRenderState.debugOverdraw(true, true);
|
2015-10-05 13:00:52 -07:00
|
|
|
}
|
2015-10-26 15:49:56 -07:00
|
|
|
|
2015-12-22 16:32:23 -08:00
|
|
|
void BakedOpRenderer::endFrame(const Rect& repaintRect) {
|
|
|
|
if (CC_UNLIKELY(Properties::debugOverdraw)) {
|
|
|
|
ClipRect overdrawClip(repaintRect);
|
|
|
|
Rect viewportRect(mRenderTarget.viewportWidth, mRenderTarget.viewportHeight);
|
|
|
|
// overdraw visualization
|
|
|
|
for (int i = 1; i <= 4; i++) {
|
|
|
|
if (i < 4) {
|
|
|
|
// nth level of overdraw tests for n+1 draws per pixel
|
|
|
|
mRenderState.stencil().enableDebugTest(i + 1, false);
|
|
|
|
} else {
|
|
|
|
// 4th level tests for 4 or higher draws per pixel
|
|
|
|
mRenderState.stencil().enableDebugTest(4, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(mCaches.getOverdrawColor(i));
|
|
|
|
Glop glop;
|
|
|
|
GlopBuilder(mRenderState, mCaches, &glop)
|
|
|
|
.setRoundRectClipState(nullptr)
|
|
|
|
.setMeshUnitQuad()
|
|
|
|
.setFillPaint(paint, 1.0f)
|
|
|
|
.setTransform(Matrix4::identity(), TransformFlags::None)
|
|
|
|
.setModelViewMapUnitToRect(viewportRect)
|
|
|
|
.build();
|
|
|
|
renderGlop(nullptr, &overdrawClip, glop);
|
|
|
|
}
|
|
|
|
mRenderState.stencil().disable();
|
|
|
|
}
|
|
|
|
|
2016-03-04 15:59:24 -08:00
|
|
|
// Note: we leave FBO 0 renderable here, for post-frame-content decoration
|
2015-10-05 13:00:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-26 15:49:56 -07:00
|
|
|
void BakedOpRenderer::setViewport(uint32_t width, uint32_t height) {
|
|
|
|
mRenderTarget.viewportWidth = width;
|
|
|
|
mRenderTarget.viewportHeight = height;
|
|
|
|
mRenderTarget.orthoMatrix.loadOrtho(width, height);
|
|
|
|
|
|
|
|
mRenderState.setViewport(width, height);
|
|
|
|
mRenderState.blend().syncEnabled();
|
|
|
|
}
|
|
|
|
|
2015-11-13 10:55:30 -08:00
|
|
|
void BakedOpRenderer::clearColorBuffer(const Rect& rect) {
|
2016-01-12 12:09:19 -08:00
|
|
|
if (rect.contains(Rect(mRenderTarget.viewportWidth, mRenderTarget.viewportHeight))) {
|
2015-11-13 10:55:30 -08:00
|
|
|
// Full viewport is being cleared - disable scissor
|
|
|
|
mRenderState.scissor().setEnabled(false);
|
|
|
|
} else {
|
|
|
|
// Requested rect is subset of viewport - scissor to it to avoid over-clearing
|
|
|
|
mRenderState.scissor().setEnabled(true);
|
|
|
|
mRenderState.scissor().set(rect.left, mRenderTarget.viewportHeight - rect.bottom,
|
|
|
|
rect.getWidth(), rect.getHeight());
|
|
|
|
}
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
if (!mRenderTarget.frameBufferId) mHasDrawn = true;
|
|
|
|
}
|
|
|
|
|
2016-10-20 18:39:04 -07:00
|
|
|
Texture* BakedOpRenderer::getTexture(Bitmap* bitmap) {
|
Linear blending, step 1
NOTE: Linear blending is currently disabled in this CL as the
feature is still a work in progress
Android currently performs all blending (any kind of linear math
on colors really) on gamma-encoded colors. Since Android assumes
that the default color space is sRGB, all bitmaps and colors
are encoded with the sRGB Opto-Electronic Conversion Function
(OECF, which can be approximated with a power function). Since
the power curve is not linear, our linear math is incorrect.
The result is that we generate colors that tend to be too dark;
this affects blending but also anti-aliasing, gradients, blurs,
etc.
The solution is to convert gamma-encoded colors back to linear
space before doing any math on them, using the sRGB Electo-Optical
Conversion Function (EOCF). This is achieved in different
ways in different parts of the pipeline:
- Using hardware conversions when sampling from OpenGL textures
or writing into OpenGL frame buffers
- Using software conversion functions, to translate app-supplied
colors to and from sRGB
- Using Skia's color spaces
Any type of processing on colors must roughly ollow these steps:
[sRGB input]->EOCF->[linear data]->[processing]->OECF->[sRGB output]
For the sRGB color space, the conversion functions are defined as
follows:
OECF(linear) :=
linear <= 0.0031308 ? linear * 12.92 : (pow(linear, 1/2.4) * 1.055) - 0.055
EOCF(srgb) :=
srgb <= 0.04045 ? srgb / 12.92 : pow((srgb + 0.055) / 1.055, 2.4)
The EOCF is simply the reciprocal of the OECF.
While it is highly recommended to use the exact sRGB conversion
functions everywhere possible, it is sometimes useful or beneficial
to rely on approximations:
- pow(x,2.2) and pow(x,1/2.2)
- x^2 and sqrt(x)
The latter is particularly useful in fragment shaders (for instance
to apply dithering in sRGB space), especially if the sqrt() can be
replaced with an inversesqrt().
Here is a fairly exhaustive list of modifications implemented
in this CL:
- Set TARGET_ENABLE_LINEAR_BLENDING := false in BoardConfig.mk
to disable linear blending. This is only for GLES 2.0 GPUs
with no hardware sRGB support. This flag is currently assumed
to be false (see note above)
- sRGB writes are disabled when entering a functor (WebView).
This will need to be fixed at some point
- Skia bitmaps are created with the sRGB color space
- Bitmaps using a 565 config are expanded to 888
- Linear blending is disabled when entering a functor
- External textures are not properly sampled (see below)
- Gradients are interpolated in linear space
- Texture-based dithering was replaced with analytical dithering
- Dithering is done in the quantization color space, which is
why we must do EOCF(OECF(color)+dither)
- Text is now gamma corrected differently depending on the luminance
of the source pixel. The asumption is that a bright pixel will be
blended on a dark background and the other way around. The source
alpha is gamma corrected to thicken dark on bright and thin
bright on dark to match the intended design of fonts. This also
matches the behavior of popular design/drawing applications
- Removed the asset atlas. It did not contain anything useful and
could not be sampled in sRGB without a yet-to-be-defined GL
extension
- The last column of color matrices is converted to linear space
because its value are added to linear colors
Missing features:
- Resource qualifier?
- Regeneration of goldeng images for automated tests
- Handle alpha8/grey8 properly
- Disable sRGB write for layers with external textures
Test: Manual testing while work in progress
Bug: 29940137
Change-Id: I6a07b15ab49b554377cd33a36b6d9971a15e9a0b
2016-09-28 17:34:42 -07:00
|
|
|
return mCaches.textureCache.get(bitmap);
|
2015-10-26 15:49:56 -07:00
|
|
|
}
|
|
|
|
|
2016-03-04 15:59:24 -08:00
|
|
|
void BakedOpRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
|
|
|
|
std::vector<Vertex> vertices;
|
|
|
|
vertices.reserve(count);
|
|
|
|
Vertex* vertex = vertices.data();
|
|
|
|
|
|
|
|
for (int index = 0; index < count; index += 4) {
|
|
|
|
float l = rects[index + 0];
|
|
|
|
float t = rects[index + 1];
|
|
|
|
float r = rects[index + 2];
|
|
|
|
float b = rects[index + 3];
|
|
|
|
|
|
|
|
Vertex::set(vertex++, l, t);
|
|
|
|
Vertex::set(vertex++, r, t);
|
|
|
|
Vertex::set(vertex++, l, b);
|
|
|
|
Vertex::set(vertex++, r, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_ALWAYS_FATAL_IF(mRenderTarget.frameBufferId != 0, "decoration only supported for FBO 0");
|
|
|
|
// TODO: Currently assume full FBO damage, due to FrameInfoVisualizer::unionDirty.
|
2016-03-18 15:24:30 -07:00
|
|
|
// Should should scissor/set mHasDrawn safely.
|
2016-03-04 15:59:24 -08:00
|
|
|
mRenderState.scissor().setEnabled(false);
|
2016-03-18 15:24:30 -07:00
|
|
|
mHasDrawn = true;
|
2016-03-04 15:59:24 -08:00
|
|
|
Glop glop;
|
|
|
|
GlopBuilder(mRenderState, mCaches, &glop)
|
|
|
|
.setRoundRectClipState(nullptr)
|
|
|
|
.setMeshIndexedQuads(vertices.data(), count / 4)
|
|
|
|
.setFillPaint(*paint, 1.0f)
|
|
|
|
.setTransform(Matrix4::identity(), TransformFlags::None)
|
|
|
|
.setModelViewIdentityEmptyBounds()
|
|
|
|
.build();
|
|
|
|
mRenderState.render(glop, mRenderTarget.orthoMatrix);
|
|
|
|
}
|
|
|
|
|
2015-12-22 16:32:23 -08:00
|
|
|
// clears and re-fills stencil with provided rendertarget space quads,
|
|
|
|
// and then put stencil into test mode
|
|
|
|
void BakedOpRenderer::setupStencilQuads(std::vector<Vertex>& quadVertices,
|
|
|
|
int incrementThreshold) {
|
|
|
|
mRenderState.stencil().enableWrite(incrementThreshold);
|
|
|
|
mRenderState.stencil().clear();
|
|
|
|
Glop glop;
|
|
|
|
GlopBuilder(mRenderState, mCaches, &glop)
|
|
|
|
.setRoundRectClipState(nullptr)
|
|
|
|
.setMeshIndexedQuads(quadVertices.data(), quadVertices.size() / 4)
|
|
|
|
.setFillBlack()
|
|
|
|
.setTransform(Matrix4::identity(), TransformFlags::None)
|
|
|
|
.setModelViewIdentityEmptyBounds()
|
|
|
|
.build();
|
|
|
|
mRenderState.render(glop, mRenderTarget.orthoMatrix);
|
|
|
|
mRenderState.stencil().enableTest(incrementThreshold);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedOpRenderer::setupStencilRectList(const ClipBase* clip) {
|
2016-01-11 17:50:08 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF(clip->mode != ClipMode::RectangleList, "can't rectlist clip without rectlist");
|
2015-12-22 16:32:23 -08:00
|
|
|
auto&& rectList = reinterpret_cast<const ClipRectList*>(clip)->rectList;
|
|
|
|
int quadCount = rectList.getTransformedRectanglesCount();
|
|
|
|
std::vector<Vertex> rectangleVertices;
|
|
|
|
rectangleVertices.reserve(quadCount * 4);
|
|
|
|
for (int i = 0; i < quadCount; i++) {
|
|
|
|
const TransformedRectangle& tr(rectList.getTransformedRectangle(i));
|
|
|
|
const Matrix4& transform = tr.getTransform();
|
|
|
|
Rect bounds = tr.getBounds();
|
|
|
|
if (transform.rectToRect()) {
|
|
|
|
// If rectToRect, can simply map bounds before storing verts
|
|
|
|
transform.mapRect(bounds);
|
|
|
|
bounds.doIntersect(clip->rect);
|
|
|
|
if (bounds.isEmpty()) {
|
|
|
|
continue; // will be outside of scissor, skip
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rectangleVertices.push_back(Vertex{bounds.left, bounds.top});
|
|
|
|
rectangleVertices.push_back(Vertex{bounds.right, bounds.top});
|
|
|
|
rectangleVertices.push_back(Vertex{bounds.left, bounds.bottom});
|
|
|
|
rectangleVertices.push_back(Vertex{bounds.right, bounds.bottom});
|
|
|
|
|
|
|
|
if (!transform.rectToRect()) {
|
|
|
|
// If not rectToRect, must map each point individually
|
|
|
|
for (auto cur = rectangleVertices.end() - 4; cur < rectangleVertices.end(); cur++) {
|
|
|
|
transform.mapPoint(cur->x, cur->y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setupStencilQuads(rectangleVertices, rectList.getTransformedRectanglesCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedOpRenderer::setupStencilRegion(const ClipBase* clip) {
|
2016-01-11 17:50:08 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF(clip->mode != ClipMode::Region, "can't region clip without region");
|
2015-12-22 16:32:23 -08:00
|
|
|
auto&& region = reinterpret_cast<const ClipRegion*>(clip)->region;
|
|
|
|
|
|
|
|
std::vector<Vertex> regionVertices;
|
|
|
|
SkRegion::Cliperator it(region, clip->rect.toSkIRect());
|
|
|
|
while (!it.done()) {
|
|
|
|
const SkIRect& r = it.rect();
|
|
|
|
regionVertices.push_back(Vertex{(float)r.fLeft, (float)r.fTop});
|
|
|
|
regionVertices.push_back(Vertex{(float)r.fRight, (float)r.fTop});
|
|
|
|
regionVertices.push_back(Vertex{(float)r.fLeft, (float)r.fBottom});
|
|
|
|
regionVertices.push_back(Vertex{(float)r.fRight, (float)r.fBottom});
|
|
|
|
it.next();
|
|
|
|
}
|
|
|
|
setupStencilQuads(regionVertices, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedOpRenderer::prepareRender(const Rect* dirtyBounds, const ClipBase* clip) {
|
2016-01-06 09:16:05 -08:00
|
|
|
// Prepare scissor (done before stencil, to simplify filling stencil)
|
2015-12-03 12:16:56 -08:00
|
|
|
mRenderState.scissor().setEnabled(clip != nullptr);
|
|
|
|
if (clip) {
|
2015-12-22 16:32:23 -08:00
|
|
|
mRenderState.scissor().set(mRenderTarget.viewportHeight, clip->rect);
|
2016-01-04 15:09:19 -08:00
|
|
|
}
|
|
|
|
|
2016-01-06 09:16:05 -08:00
|
|
|
// If stencil may be used for clipping, enable it, fill it, or disable it as appropriate
|
2016-01-04 15:09:19 -08:00
|
|
|
if (CC_LIKELY(!Properties::debugOverdraw)) {
|
|
|
|
// only modify stencil mode and content when it's not used for overdraw visualization
|
|
|
|
if (CC_UNLIKELY(clip && clip->mode != ClipMode::Rectangle)) {
|
|
|
|
// NOTE: this pointer check is only safe for non-rect clips,
|
|
|
|
// since rect clips may be created on the stack
|
|
|
|
if (mRenderTarget.lastStencilClip != clip) {
|
|
|
|
// Stencil needed, but current stencil isn't up to date
|
|
|
|
mRenderTarget.lastStencilClip = clip;
|
|
|
|
|
|
|
|
if (mRenderTarget.frameBufferId != 0 && !mRenderTarget.stencil) {
|
|
|
|
OffscreenBuffer* layer = mRenderTarget.offscreenBuffer;
|
|
|
|
mRenderTarget.stencil = mCaches.renderBufferCache.get(
|
|
|
|
Stencil::getLayerStencilFormat(),
|
2015-11-10 12:19:17 -08:00
|
|
|
layer->texture.width(), layer->texture.height());
|
2016-01-04 15:09:19 -08:00
|
|
|
// stencil is bound + allocated - associate it with current FBO
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
|
|
|
|
GL_RENDERBUFFER, mRenderTarget.stencil->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clip->mode == ClipMode::RectangleList) {
|
|
|
|
setupStencilRectList(clip);
|
|
|
|
} else {
|
|
|
|
setupStencilRegion(clip);
|
2015-12-22 16:32:23 -08:00
|
|
|
}
|
|
|
|
} else {
|
2016-01-04 15:09:19 -08:00
|
|
|
// stencil is up to date - just need to ensure it's enabled (since an unclipped
|
|
|
|
// or scissor-only clipped op may have been drawn, disabling the stencil)
|
|
|
|
int incrementThreshold = 0;
|
|
|
|
if (CC_LIKELY(clip->mode == ClipMode::RectangleList)) {
|
|
|
|
auto&& rectList = reinterpret_cast<const ClipRectList*>(clip)->rectList;
|
|
|
|
incrementThreshold = rectList.getTransformedRectanglesCount();
|
|
|
|
}
|
|
|
|
mRenderState.stencil().enableTest(incrementThreshold);
|
2015-12-22 16:32:23 -08:00
|
|
|
}
|
2016-01-04 15:09:19 -08:00
|
|
|
} else {
|
|
|
|
// either scissor or no clip, so disable stencil test
|
|
|
|
mRenderState.stencil().disable();
|
2015-12-22 16:32:23 -08:00
|
|
|
}
|
2015-10-26 15:49:56 -07:00
|
|
|
}
|
2015-12-22 16:32:23 -08:00
|
|
|
|
2016-02-26 15:01:24 -08:00
|
|
|
if (dirtyBounds) {
|
|
|
|
// dirty offscreenbuffer if present
|
|
|
|
dirtyRenderTarget(*dirtyBounds);
|
2015-11-02 14:52:21 -08:00
|
|
|
}
|
2015-12-10 16:25:13 -08:00
|
|
|
}
|
|
|
|
|
2016-03-08 16:24:12 -08:00
|
|
|
void BakedOpRenderer::renderGlopImpl(const Rect* dirtyBounds, const ClipBase* clip,
|
2015-12-22 16:32:23 -08:00
|
|
|
const Glop& glop) {
|
2015-12-10 16:25:13 -08:00
|
|
|
prepareRender(dirtyBounds, clip);
|
2015-10-26 15:49:56 -07:00
|
|
|
mRenderState.render(glop, mRenderTarget.orthoMatrix);
|
2015-11-13 10:55:30 -08:00
|
|
|
if (!mRenderTarget.frameBufferId) mHasDrawn = true;
|
2015-10-26 15:49:56 -07:00
|
|
|
}
|
|
|
|
|
2015-12-10 16:25:13 -08:00
|
|
|
void BakedOpRenderer::renderFunctor(const FunctorOp& op, const BakedOpState& state) {
|
2015-12-22 16:32:23 -08:00
|
|
|
prepareRender(&state.computedState.clippedBounds, state.computedState.getClipIfNeeded());
|
2015-12-10 16:25:13 -08:00
|
|
|
|
|
|
|
DrawGlInfo info;
|
2015-12-22 16:32:23 -08:00
|
|
|
auto&& clip = state.computedState.clipRect();
|
2015-12-10 16:25:13 -08:00
|
|
|
info.clipLeft = clip.left;
|
|
|
|
info.clipTop = clip.top;
|
|
|
|
info.clipRight = clip.right;
|
|
|
|
info.clipBottom = clip.bottom;
|
|
|
|
info.isLayer = offscreenRenderTarget();
|
|
|
|
info.width = mRenderTarget.viewportWidth;
|
|
|
|
info.height = mRenderTarget.viewportHeight;
|
|
|
|
state.computedState.transform.copyTo(&info.transform[0]);
|
|
|
|
|
|
|
|
mRenderState.invokeFunctor(op.functor, DrawGlInfo::kModeDraw, &info);
|
2017-03-24 17:00:39 -07:00
|
|
|
if (!mRenderTarget.frameBufferId) mHasDrawn = true;
|
2015-12-10 16:25:13 -08:00
|
|
|
}
|
|
|
|
|
2015-12-03 12:16:56 -08:00
|
|
|
void BakedOpRenderer::dirtyRenderTarget(const Rect& uiDirty) {
|
|
|
|
if (mRenderTarget.offscreenBuffer) {
|
2016-02-26 15:01:24 -08:00
|
|
|
mRenderTarget.offscreenBuffer->dirty(uiDirty);
|
2015-12-03 12:16:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 13:00:52 -07:00
|
|
|
} // namespace uirenderer
|
|
|
|
} // namespace android
|