}
void OpenGLRenderer::setViewport(int width, int height) {
+ initViewport(width, height);
+
+ glDisable(GL_DITHER);
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+ glEnableVertexAttribArray(Program::kBindingPosition);
+}
+
+void OpenGLRenderer::initViewport(int width, int height) {
mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
mWidth = width;
mFirstSnapshot->height = height;
mFirstSnapshot->viewport.set(0, 0, width, height);
-
- glDisable(GL_DITHER);
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-
- glEnableVertexAttribArray(Program::kBindingPosition);
}
int OpenGLRenderer::prepare(bool opaque) {
void OpenGLRenderer::resume() {
sp<Snapshot> snapshot = (mSnapshot != NULL) ? mSnapshot : mFirstSnapshot;
-
glViewport(0, 0, snapshot->viewport.getWidth(), snapshot->viewport.getHeight());
+ glBindFramebuffer(GL_FRAMEBUFFER, snapshot->fbo);
+
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
mCaches.scissorEnabled = glIsEnabled(GL_SCISSOR_TEST);
dirtyClip();
mCaches.activeTexture(0);
- glBindFramebuffer(GL_FRAMEBUFFER, snapshot->fbo);
mCaches.blend = true;
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
}
+void OpenGLRenderer::resumeAfterLayer() {
+ sp<Snapshot> snapshot = (mSnapshot != NULL) ? mSnapshot : mFirstSnapshot;
+ glViewport(0, 0, snapshot->viewport.getWidth(), snapshot->viewport.getHeight());
+ glBindFramebuffer(GL_FRAMEBUFFER, snapshot->fbo);
+
+ mCaches.resetScissor();
+ dirtyClip();
+}
+
void OpenGLRenderer::detachFunctor(Functor* functor) {
mFunctors.remove(functor);
}
return !clipRect.intersects(r);
}
+bool OpenGLRenderer::quickRejectNoScissor(float left, float top, float right, float bottom,
+ Rect& transformed, Rect& clip) {
+ if (mSnapshot->isIgnored()) {
+ return true;
+ }
+
+ transformed.set(left, top, right, bottom);
+ mSnapshot->transform->mapRect(transformed);
+ transformed.snapToPixelBoundaries();
+
+ clip.set(*mSnapshot->clipRect);
+ clip.snapToPixelBoundaries();
+
+ return !clip.intersects(transformed);
+}
+
bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
if (mSnapshot->isIgnored()) {
return true;
}
status_t OpenGLRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
- if (!layer || quickReject(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight())) {
+ if (!layer) {
return DrawGlInfo::kStatusDone;
}
- bool debugLayerUpdate = false;
+ Rect transformed;
+ Rect clip;
+ const bool rejected = quickRejectNoScissor(x, y,
+ x + layer->layer.getWidth(), y + layer->layer.getHeight(), transformed, clip);
+ if (rejected) {
+ return DrawGlInfo::kStatusDone;
+ }
+
+ bool debugLayerUpdate = false;
if (layer->deferredUpdateScheduled && layer->renderer && layer->displayList) {
OpenGLRenderer* renderer = layer->renderer;
Rect& dirty = layer->dirtyRect;
- interrupt();
renderer->setViewport(layer->layer.getWidth(), layer->layer.getHeight());
renderer->prepareDirty(dirty.left, dirty.top, dirty.right, dirty.bottom, !layer->isBlend());
renderer->drawDisplayList(layer->displayList, dirty, DisplayList::kReplayFlag_ClipChildren);
renderer->finish();
- resume();
+
+ resumeAfterLayer();
dirty.setEmpty();
layer->deferredUpdateScheduled = false;
debugLayerUpdate = mCaches.debugLayersUpdates;
}
+ mCaches.setScissorEnabled(!clip.contains(transformed));
mCaches.activeTexture(0);
if (CC_LIKELY(!layer->region.isEmpty())) {
protected:
/**
+ * Computes the projection matrix, initialize the first snapshot
+ * and stores the dimensions of the render target.
+ */
+ void initViewport(int width, int height);
+
+ /**
+ * Call this method after updating a layer during a drawing pass.
+ */
+ void resumeAfterLayer();
+
+ /**
* Compose the layer defined in the current snapshot with the layer
* defined by the previous snapshot.
*
void setScissorFromClip();
/**
+ * Performs a quick reject but does not affect the scissor. Returns
+ * the transformed rect to test and the current clip.
+ */
+ bool quickRejectNoScissor(float left, float top, float right, float bottom,
+ Rect& transformed, Rect& clip);
+
+ /**
* Creates a new layer stored in the specified snapshot.
*
* @param snapshot The snapshot associated with the new layer