2014-03-18 09:22:59 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ATRACE_TAG ATRACE_TAG_VIEW
|
2014-06-11 18:39:44 -07:00
|
|
|
#define LOG_TAG "RenderNode"
|
2014-03-18 09:22:59 -07:00
|
|
|
|
|
|
|
#include "RenderNode.h"
|
|
|
|
|
2014-04-15 09:50:16 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-03-18 09:22:59 -07:00
|
|
|
#include <SkCanvas.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <utils/Trace.h>
|
|
|
|
|
2014-06-03 15:53:15 -07:00
|
|
|
#include "DamageAccumulator.h"
|
2014-03-18 09:22:59 -07:00
|
|
|
#include "Debug.h"
|
|
|
|
#include "DisplayListOp.h"
|
|
|
|
#include "DisplayListLogBuffer.h"
|
2014-06-12 13:46:45 -07:00
|
|
|
#include "LayerRenderer.h"
|
|
|
|
#include "OpenGLRenderer.h"
|
2014-04-22 17:55:41 -07:00
|
|
|
#include "utils/MathUtils.h"
|
2014-03-18 09:22:59 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
void RenderNode::outputLogBuffer(int fd) {
|
|
|
|
DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
|
|
|
|
if (logBuffer.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *file = fdopen(fd, "a");
|
|
|
|
|
|
|
|
fprintf(file, "\nRecent DisplayList operations\n");
|
|
|
|
logBuffer.outputCommands(file);
|
|
|
|
|
|
|
|
String8 cachesLog;
|
|
|
|
Caches::getInstance().dumpMemoryUsage(cachesLog);
|
|
|
|
fprintf(file, "\nCaches:\n%s", cachesLog.string());
|
|
|
|
fprintf(file, "\n");
|
|
|
|
|
|
|
|
fflush(file);
|
|
|
|
}
|
|
|
|
|
2014-04-09 15:23:38 -07:00
|
|
|
RenderNode::RenderNode()
|
2014-05-14 16:34:14 -07:00
|
|
|
: mDirtyPropertyFields(0)
|
2014-04-09 15:23:38 -07:00
|
|
|
, mNeedsDisplayListDataSync(false)
|
|
|
|
, mDisplayListData(0)
|
2014-04-15 09:50:16 -07:00
|
|
|
, mStagingDisplayListData(0)
|
2014-06-12 13:46:45 -07:00
|
|
|
, mNeedsAnimatorsSync(false)
|
|
|
|
, mLayer(0) {
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderNode::~RenderNode() {
|
|
|
|
delete mDisplayListData;
|
2014-04-09 15:23:38 -07:00
|
|
|
delete mStagingDisplayListData;
|
2014-06-12 13:46:45 -07:00
|
|
|
LayerRenderer::destroyLayerDeferred(mLayer);
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
2014-04-09 15:23:38 -07:00
|
|
|
void RenderNode::setStagingDisplayList(DisplayListData* data) {
|
|
|
|
mNeedsDisplayListDataSync = true;
|
|
|
|
delete mStagingDisplayListData;
|
|
|
|
mStagingDisplayListData = data;
|
|
|
|
if (mStagingDisplayListData) {
|
|
|
|
Caches::getInstance().registerFunctors(mStagingDisplayListData->functorCount);
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is a simplified version of replay(), where we simply retrieve and log the
|
|
|
|
* display list. This function should remain in sync with the replay() function.
|
|
|
|
*/
|
|
|
|
void RenderNode::output(uint32_t level) {
|
|
|
|
ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this,
|
2014-04-15 16:18:08 -07:00
|
|
|
getName(), isRenderable());
|
2014-03-18 09:22:59 -07:00
|
|
|
ALOGD("%*s%s %d", level * 2, "", "Save",
|
|
|
|
SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
|
|
|
|
|
2014-03-20 16:28:56 -07:00
|
|
|
properties().debugOutputProperties(level);
|
2014-03-18 09:22:59 -07:00
|
|
|
int flags = DisplayListOp::kOpLogFlag_Recurse;
|
|
|
|
for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
|
|
|
|
mDisplayListData->displayListOps[i]->output(level, flags);
|
|
|
|
}
|
|
|
|
|
2014-04-15 16:18:08 -07:00
|
|
|
ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
2014-05-23 17:42:28 -07:00
|
|
|
int RenderNode::getDebugSize() {
|
|
|
|
int size = sizeof(RenderNode);
|
|
|
|
if (mStagingDisplayListData) {
|
|
|
|
size += mStagingDisplayListData->allocator.usedSize();
|
|
|
|
}
|
|
|
|
if (mDisplayListData && mDisplayListData != mStagingDisplayListData) {
|
|
|
|
size += mDisplayListData->allocator.usedSize();
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2014-04-09 17:00:04 -07:00
|
|
|
void RenderNode::prepareTree(TreeInfo& info) {
|
|
|
|
ATRACE_CALL();
|
|
|
|
|
|
|
|
prepareTreeImpl(info);
|
|
|
|
}
|
|
|
|
|
2014-06-03 15:53:15 -07:00
|
|
|
void RenderNode::damageSelf(TreeInfo& info) {
|
2014-06-11 18:39:44 -07:00
|
|
|
if (isRenderable() && properties().getAlpha() > 0) {
|
|
|
|
if (properties().getClipToBounds()) {
|
|
|
|
info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
|
|
|
|
} else {
|
|
|
|
// Hope this is big enough?
|
|
|
|
// TODO: Get this from the display list ops or something
|
|
|
|
info.damageAccumulator->dirty(INT_MIN, INT_MIN, INT_MAX, INT_MAX);
|
|
|
|
}
|
2014-06-03 15:53:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-12 13:46:45 -07:00
|
|
|
void RenderNode::prepareLayer(TreeInfo& info) {
|
|
|
|
LayerType layerType = properties().layerProperties().type();
|
|
|
|
if (CC_UNLIKELY(layerType == kLayerTypeRenderLayer)) {
|
|
|
|
// We push a null transform here as we don't care what the existing dirty
|
|
|
|
// area is, only what our display list dirty is as well as our children's
|
|
|
|
// dirty area
|
|
|
|
info.damageAccumulator->pushNullTransform();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderNode::pushLayerUpdate(TreeInfo& info) {
|
|
|
|
LayerType layerType = properties().layerProperties().type();
|
|
|
|
// If we are not a layer OR we cannot be rendered (eg, view was detached)
|
|
|
|
// we need to destroy any Layers we may have had previously
|
|
|
|
if (CC_LIKELY(layerType != kLayerTypeRenderLayer) || CC_UNLIKELY(!isRenderable())) {
|
|
|
|
if (layerType == kLayerTypeRenderLayer) {
|
|
|
|
info.damageAccumulator->popTransform();
|
|
|
|
}
|
|
|
|
if (CC_UNLIKELY(mLayer)) {
|
|
|
|
LayerRenderer::destroyLayer(mLayer);
|
|
|
|
mLayer = NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mLayer) {
|
|
|
|
mLayer = LayerRenderer::createRenderLayer(getWidth(), getHeight());
|
|
|
|
applyLayerPropertiesToLayer(info);
|
|
|
|
damageSelf(info);
|
|
|
|
} else if (mLayer->layer.getWidth() != getWidth() || mLayer->layer.getHeight() != getHeight()) {
|
|
|
|
LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight());
|
|
|
|
damageSelf(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRect dirty;
|
|
|
|
info.damageAccumulator->peekAtDirty(&dirty);
|
|
|
|
info.damageAccumulator->popTransform();
|
|
|
|
|
|
|
|
if (!dirty.isEmpty()) {
|
|
|
|
mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom);
|
|
|
|
}
|
|
|
|
// This is not inside the above if because we may have called
|
|
|
|
// updateDeferred on a previous prepare pass that didn't have a renderer
|
|
|
|
if (info.renderer && mLayer->deferredUpdateScheduled) {
|
|
|
|
info.renderer->pushLayerUpdate(mLayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 17:00:04 -07:00
|
|
|
void RenderNode::prepareTreeImpl(TreeInfo& info) {
|
2014-06-11 18:39:44 -07:00
|
|
|
info.damageAccumulator->pushTransform(this);
|
2014-06-03 15:53:15 -07:00
|
|
|
if (info.mode == TreeInfo::MODE_FULL) {
|
2014-06-12 13:46:45 -07:00
|
|
|
pushStagingPropertiesChanges(info);
|
2014-06-03 15:53:15 -07:00
|
|
|
evaluateAnimations(info);
|
|
|
|
} else if (info.mode == TreeInfo::MODE_MAYBE_DETACHING) {
|
2014-06-12 13:46:45 -07:00
|
|
|
pushStagingPropertiesChanges(info);
|
2014-06-03 15:53:15 -07:00
|
|
|
} else if (info.mode == TreeInfo::MODE_RT_ONLY) {
|
2014-04-15 09:50:16 -07:00
|
|
|
evaluateAnimations(info);
|
|
|
|
}
|
2014-06-12 13:46:45 -07:00
|
|
|
|
|
|
|
prepareLayer(info);
|
|
|
|
if (info.mode == TreeInfo::MODE_FULL) {
|
|
|
|
pushStagingDisplayListChanges(info);
|
|
|
|
}
|
2014-04-09 17:00:04 -07:00
|
|
|
prepareSubTree(info, mDisplayListData);
|
2014-06-12 13:46:45 -07:00
|
|
|
pushLayerUpdate(info);
|
|
|
|
|
2014-06-11 18:39:44 -07:00
|
|
|
info.damageAccumulator->popTransform();
|
2014-04-09 17:00:04 -07:00
|
|
|
}
|
|
|
|
|
2014-05-14 16:34:14 -07:00
|
|
|
class PushAnimatorsFunctor {
|
|
|
|
public:
|
|
|
|
PushAnimatorsFunctor(RenderNode* target, TreeInfo& info)
|
|
|
|
: mTarget(target), mInfo(info) {}
|
2014-04-15 09:50:16 -07:00
|
|
|
|
2014-05-14 16:34:14 -07:00
|
|
|
bool operator() (const sp<BaseRenderNodeAnimator>& animator) {
|
|
|
|
animator->setupStartValueIfNecessary(mTarget, mInfo);
|
|
|
|
return animator->isFinished();
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
2014-05-14 16:34:14 -07:00
|
|
|
private:
|
|
|
|
RenderNode* mTarget;
|
|
|
|
TreeInfo& mInfo;
|
|
|
|
};
|
|
|
|
|
2014-06-12 13:46:45 -07:00
|
|
|
void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
|
2014-05-14 16:34:14 -07:00
|
|
|
// Push the animators first so that setupStartValueIfNecessary() is called
|
|
|
|
// before properties() is trampled by stagingProperties(), as they are
|
|
|
|
// required by some animators.
|
2014-04-15 09:50:16 -07:00
|
|
|
if (mNeedsAnimatorsSync) {
|
2014-04-30 14:19:56 -07:00
|
|
|
mAnimators.resize(mStagingAnimators.size());
|
2014-05-01 21:27:37 -07:00
|
|
|
std::vector< sp<BaseRenderNodeAnimator> >::iterator it;
|
2014-05-14 16:34:14 -07:00
|
|
|
PushAnimatorsFunctor functor(this, info);
|
2014-04-15 09:50:16 -07:00
|
|
|
// hint: this means copy_if_not()
|
|
|
|
it = std::remove_copy_if(mStagingAnimators.begin(), mStagingAnimators.end(),
|
2014-05-14 16:34:14 -07:00
|
|
|
mAnimators.begin(), functor);
|
2014-04-15 09:50:16 -07:00
|
|
|
mAnimators.resize(std::distance(mAnimators.begin(), it));
|
|
|
|
}
|
2014-05-14 16:34:14 -07:00
|
|
|
if (mDirtyPropertyFields) {
|
|
|
|
mDirtyPropertyFields = 0;
|
2014-06-03 15:53:15 -07:00
|
|
|
damageSelf(info);
|
2014-06-11 18:39:44 -07:00
|
|
|
info.damageAccumulator->popTransform();
|
2014-05-14 16:34:14 -07:00
|
|
|
mProperties = mStagingProperties;
|
2014-06-12 13:46:45 -07:00
|
|
|
applyLayerPropertiesToLayer(info);
|
2014-06-03 15:53:15 -07:00
|
|
|
// We could try to be clever and only re-damage if the matrix changed.
|
|
|
|
// However, we don't need to worry about that. The cost of over-damaging
|
|
|
|
// here is only going to be a single additional map rect of this node
|
|
|
|
// plus a rect join(). The parent's transform (and up) will only be
|
|
|
|
// performed once.
|
2014-06-11 18:39:44 -07:00
|
|
|
info.damageAccumulator->pushTransform(this);
|
2014-06-03 15:53:15 -07:00
|
|
|
damageSelf(info);
|
2014-05-14 16:34:14 -07:00
|
|
|
}
|
2014-06-12 13:46:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) {
|
|
|
|
if (CC_LIKELY(!mLayer)) return;
|
|
|
|
|
|
|
|
const LayerProperties& props = properties().layerProperties();
|
|
|
|
mLayer->setAlpha(props.alpha(), props.xferMode());
|
|
|
|
mLayer->setColorFilter(props.colorFilter());
|
|
|
|
mLayer->setBlend(props.needsBlending());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
|
2014-04-09 15:23:38 -07:00
|
|
|
if (mNeedsDisplayListDataSync) {
|
|
|
|
mNeedsDisplayListDataSync = false;
|
|
|
|
// Do a push pass on the old tree to handle freeing DisplayListData
|
|
|
|
// that are no longer used
|
2014-06-03 15:53:15 -07:00
|
|
|
TreeInfo oldTreeInfo(TreeInfo::MODE_MAYBE_DETACHING);
|
|
|
|
oldTreeInfo.damageAccumulator = info.damageAccumulator;
|
2014-04-09 17:00:04 -07:00
|
|
|
prepareSubTree(oldTreeInfo, mDisplayListData);
|
2014-04-09 15:23:38 -07:00
|
|
|
delete mDisplayListData;
|
|
|
|
mDisplayListData = mStagingDisplayListData;
|
|
|
|
mStagingDisplayListData = 0;
|
2014-06-03 15:53:15 -07:00
|
|
|
damageSelf(info);
|
2014-04-09 15:23:38 -07:00
|
|
|
}
|
|
|
|
}
|
2014-03-18 09:22:59 -07:00
|
|
|
|
2014-04-15 09:50:16 -07:00
|
|
|
class AnimateFunctor {
|
|
|
|
public:
|
2014-05-01 21:27:37 -07:00
|
|
|
AnimateFunctor(RenderNode* target, TreeInfo& info)
|
2014-04-15 09:50:16 -07:00
|
|
|
: mTarget(target), mInfo(info) {}
|
|
|
|
|
2014-05-14 16:34:14 -07:00
|
|
|
bool operator() (const sp<BaseRenderNodeAnimator>& animator) {
|
2014-05-01 21:27:37 -07:00
|
|
|
return animator->animate(mTarget, mInfo);
|
2014-04-15 09:50:16 -07:00
|
|
|
}
|
|
|
|
private:
|
2014-05-01 21:27:37 -07:00
|
|
|
RenderNode* mTarget;
|
2014-04-15 09:50:16 -07:00
|
|
|
TreeInfo& mInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
void RenderNode::evaluateAnimations(TreeInfo& info) {
|
|
|
|
if (!mAnimators.size()) return;
|
|
|
|
|
2014-06-03 15:53:15 -07:00
|
|
|
// TODO: Can we target this better? For now treat it like any other staging
|
|
|
|
// property push and just damage self before and after animators are run
|
|
|
|
|
|
|
|
damageSelf(info);
|
2014-06-11 18:39:44 -07:00
|
|
|
info.damageAccumulator->popTransform();
|
2014-06-03 15:53:15 -07:00
|
|
|
|
2014-05-01 21:27:37 -07:00
|
|
|
AnimateFunctor functor(this, info);
|
|
|
|
std::vector< sp<BaseRenderNodeAnimator> >::iterator newEnd;
|
2014-04-15 09:50:16 -07:00
|
|
|
newEnd = std::remove_if(mAnimators.begin(), mAnimators.end(), functor);
|
|
|
|
mAnimators.erase(newEnd, mAnimators.end());
|
|
|
|
mProperties.updateMatrix();
|
2014-05-02 18:21:16 -07:00
|
|
|
info.out.hasAnimations |= mAnimators.size();
|
2014-06-03 15:53:15 -07:00
|
|
|
|
2014-06-11 18:39:44 -07:00
|
|
|
info.damageAccumulator->pushTransform(this);
|
2014-06-03 15:53:15 -07:00
|
|
|
damageSelf(info);
|
2014-04-15 09:50:16 -07:00
|
|
|
}
|
|
|
|
|
2014-04-09 17:00:04 -07:00
|
|
|
void RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) {
|
2014-04-09 15:23:38 -07:00
|
|
|
if (subtree) {
|
2014-04-11 19:15:05 -07:00
|
|
|
TextureCache& cache = Caches::getInstance().textureCache;
|
2014-05-02 18:21:16 -07:00
|
|
|
info.out.hasFunctors |= subtree->functorCount;
|
2014-04-11 19:15:05 -07:00
|
|
|
// TODO: Fix ownedBitmapResources to not require disabling prepareTextures
|
|
|
|
// and thus falling out of async drawing path.
|
|
|
|
if (subtree->ownedBitmapResources.size()) {
|
|
|
|
info.prepareTextures = false;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) {
|
|
|
|
info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]);
|
2014-04-09 17:00:04 -07:00
|
|
|
}
|
2014-04-09 15:23:38 -07:00
|
|
|
for (size_t i = 0; i < subtree->children().size(); i++) {
|
2014-06-11 18:39:44 -07:00
|
|
|
DrawDisplayListOp* op = subtree->children()[i];
|
|
|
|
RenderNode* childNode = op->mDisplayList;
|
|
|
|
info.damageAccumulator->pushTransform(&op->mTransformFromParent);
|
2014-04-09 17:00:04 -07:00
|
|
|
childNode->prepareTreeImpl(info);
|
2014-06-11 18:39:44 -07:00
|
|
|
info.damageAccumulator->popTransform();
|
2014-03-25 10:22:09 -07:00
|
|
|
}
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For property operations, we pass a savecount of 0, since the operations aren't part of the
|
|
|
|
* displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
|
2014-03-20 16:28:56 -07:00
|
|
|
* base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount())
|
2014-03-18 09:22:59 -07:00
|
|
|
*/
|
|
|
|
#define PROPERTY_SAVECOUNT 0
|
|
|
|
|
|
|
|
template <class T>
|
2014-03-27 15:50:09 -07:00
|
|
|
void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) {
|
2014-03-18 09:22:59 -07:00
|
|
|
#if DEBUG_DISPLAY_LIST
|
2014-03-27 15:50:09 -07:00
|
|
|
properties().debugOutputProperties(handler.level() + 1);
|
2014-03-18 09:22:59 -07:00
|
|
|
#endif
|
2014-03-20 16:28:56 -07:00
|
|
|
if (properties().getLeft() != 0 || properties().getTop() != 0) {
|
|
|
|
renderer.translate(properties().getLeft(), properties().getTop());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
2014-03-20 16:28:56 -07:00
|
|
|
if (properties().getStaticMatrix()) {
|
2013-12-10 12:28:58 -05:00
|
|
|
renderer.concatMatrix(*properties().getStaticMatrix());
|
2014-03-20 16:28:56 -07:00
|
|
|
} else if (properties().getAnimationMatrix()) {
|
2013-12-10 12:28:58 -05:00
|
|
|
renderer.concatMatrix(*properties().getAnimationMatrix());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
2014-04-11 08:54:47 -07:00
|
|
|
if (properties().hasTransformMatrix()) {
|
|
|
|
if (properties().isTransformTranslateOnly()) {
|
2014-03-20 16:28:56 -07:00
|
|
|
renderer.translate(properties().getTranslationX(), properties().getTranslationY());
|
2014-03-18 09:22:59 -07:00
|
|
|
} else {
|
2014-03-20 16:28:56 -07:00
|
|
|
renderer.concatMatrix(*properties().getTransformMatrix());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 13:46:45 -07:00
|
|
|
const bool isLayer = properties().layerProperties().type() != kLayerTypeNone;
|
|
|
|
bool clipToBoundsNeeded = isLayer ? false : properties().getClipToBounds();
|
2014-03-20 16:28:56 -07:00
|
|
|
if (properties().getAlpha() < 1) {
|
2014-06-12 13:46:45 -07:00
|
|
|
if (isLayer) {
|
2014-03-20 16:28:56 -07:00
|
|
|
renderer.setOverrideLayerAlpha(properties().getAlpha());
|
|
|
|
} else if (!properties().getHasOverlappingRendering()) {
|
|
|
|
renderer.scaleAlpha(properties().getAlpha());
|
2014-03-18 09:22:59 -07:00
|
|
|
} else {
|
|
|
|
// TODO: should be able to store the size of a DL at record time and not
|
|
|
|
// have to pass it into this call. In fact, this information might be in the
|
|
|
|
// location/size info that we store with the new native transform data.
|
|
|
|
int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
|
|
|
|
if (clipToBoundsNeeded) {
|
|
|
|
saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
|
|
|
|
clipToBoundsNeeded = false; // clipping done by saveLayer
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
|
2014-03-25 10:33:01 -07:00
|
|
|
0, 0, properties().getWidth(), properties().getHeight(),
|
|
|
|
properties().getAlpha() * 255, saveFlags);
|
2014-03-20 16:28:56 -07:00
|
|
|
handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (clipToBoundsNeeded) {
|
2014-03-25 10:33:01 -07:00
|
|
|
ClipRectOp* op = new (handler.allocator()) ClipRectOp(
|
|
|
|
0, 0, properties().getWidth(), properties().getHeight(), SkRegion::kIntersect_Op);
|
2014-03-20 16:28:56 -07:00
|
|
|
handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
2014-03-25 10:33:01 -07:00
|
|
|
|
|
|
|
if (CC_UNLIKELY(properties().hasClippingPath())) {
|
2014-05-14 18:11:23 -07:00
|
|
|
ClipPathOp* op = new (handler.allocator()) ClipPathOp(
|
|
|
|
properties().getClippingPath(), properties().getClippingPathOp());
|
2014-03-20 16:28:56 -07:00
|
|
|
handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply property-based transformations to input matrix
|
|
|
|
*
|
|
|
|
* If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
|
|
|
|
* matrix computation instead of the Skia 3x3 matrix + camera hackery.
|
|
|
|
*/
|
|
|
|
void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) {
|
2014-03-20 16:28:56 -07:00
|
|
|
if (properties().getLeft() != 0 || properties().getTop() != 0) {
|
|
|
|
matrix.translate(properties().getLeft(), properties().getTop());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
2014-03-20 16:28:56 -07:00
|
|
|
if (properties().getStaticMatrix()) {
|
|
|
|
mat4 stat(*properties().getStaticMatrix());
|
2014-03-18 09:22:59 -07:00
|
|
|
matrix.multiply(stat);
|
2014-03-20 16:28:56 -07:00
|
|
|
} else if (properties().getAnimationMatrix()) {
|
|
|
|
mat4 anim(*properties().getAnimationMatrix());
|
2014-03-18 09:22:59 -07:00
|
|
|
matrix.multiply(anim);
|
|
|
|
}
|
2014-04-22 17:55:41 -07:00
|
|
|
|
2014-04-25 18:34:11 -07:00
|
|
|
bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
|
2014-04-22 17:55:41 -07:00
|
|
|
if (properties().hasTransformMatrix() || applyTranslationZ) {
|
2014-04-11 08:54:47 -07:00
|
|
|
if (properties().isTransformTranslateOnly()) {
|
2014-03-20 16:28:56 -07:00
|
|
|
matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
|
2014-04-25 18:34:11 -07:00
|
|
|
true3dTransform ? properties().getZ() : 0.0f);
|
2014-03-18 09:22:59 -07:00
|
|
|
} else {
|
|
|
|
if (!true3dTransform) {
|
2014-03-20 16:28:56 -07:00
|
|
|
matrix.multiply(*properties().getTransformMatrix());
|
2014-03-18 09:22:59 -07:00
|
|
|
} else {
|
|
|
|
mat4 true3dMat;
|
|
|
|
true3dMat.loadTranslate(
|
2014-03-20 16:28:56 -07:00
|
|
|
properties().getPivotX() + properties().getTranslationX(),
|
|
|
|
properties().getPivotY() + properties().getTranslationY(),
|
2014-04-25 18:34:11 -07:00
|
|
|
properties().getZ());
|
2014-03-20 16:28:56 -07:00
|
|
|
true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
|
|
|
|
true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
|
|
|
|
true3dMat.rotate(properties().getRotation(), 0, 0, 1);
|
|
|
|
true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
|
|
|
|
true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
|
2014-03-18 09:22:59 -07:00
|
|
|
|
|
|
|
matrix.multiply(true3dMat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Organizes the DisplayList hierarchy to prepare for background projection reordering.
|
|
|
|
*
|
|
|
|
* This should be called before a call to defer() or drawDisplayList()
|
|
|
|
*
|
|
|
|
* Each DisplayList that serves as a 3d root builds its list of composited children,
|
|
|
|
* which are flagged to not draw in the standard draw loop.
|
|
|
|
*/
|
|
|
|
void RenderNode::computeOrdering() {
|
|
|
|
ATRACE_CALL();
|
|
|
|
mProjectedNodes.clear();
|
|
|
|
|
|
|
|
// TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that
|
|
|
|
// transform properties are applied correctly to top level children
|
|
|
|
if (mDisplayListData == NULL) return;
|
2014-04-04 16:20:08 -07:00
|
|
|
for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
|
|
|
|
DrawDisplayListOp* childOp = mDisplayListData->children()[i];
|
2014-03-18 09:22:59 -07:00
|
|
|
childOp->mDisplayList->computeOrderingImpl(childOp,
|
2014-04-15 16:18:08 -07:00
|
|
|
properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity());
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderNode::computeOrderingImpl(
|
|
|
|
DrawDisplayListOp* opState,
|
2014-04-15 16:18:08 -07:00
|
|
|
const SkPath* outlineOfProjectionSurface,
|
2014-03-18 09:22:59 -07:00
|
|
|
Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface,
|
|
|
|
const mat4* transformFromProjectionSurface) {
|
|
|
|
mProjectedNodes.clear();
|
|
|
|
if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return;
|
|
|
|
|
|
|
|
// TODO: should avoid this calculation in most cases
|
|
|
|
// TODO: just calculate single matrix, down to all leaf composited elements
|
|
|
|
Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface);
|
|
|
|
localTransformFromProjectionSurface.multiply(opState->mTransformFromParent);
|
|
|
|
|
2014-03-20 16:28:56 -07:00
|
|
|
if (properties().getProjectBackwards()) {
|
2014-03-18 09:22:59 -07:00
|
|
|
// composited projectee, flag for out of order draw, save matrix, and store in proj surface
|
|
|
|
opState->mSkipInOrderDraw = true;
|
|
|
|
opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface);
|
|
|
|
compositedChildrenOfProjectionSurface->add(opState);
|
|
|
|
} else {
|
|
|
|
// standard in order draw
|
|
|
|
opState->mSkipInOrderDraw = false;
|
|
|
|
}
|
|
|
|
|
2014-04-04 16:20:08 -07:00
|
|
|
if (mDisplayListData->children().size() > 0) {
|
2014-03-18 09:22:59 -07:00
|
|
|
const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0;
|
|
|
|
bool haveAppliedPropertiesToProjection = false;
|
2014-04-04 16:20:08 -07:00
|
|
|
for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
|
|
|
|
DrawDisplayListOp* childOp = mDisplayListData->children()[i];
|
2014-03-18 09:22:59 -07:00
|
|
|
RenderNode* child = childOp->mDisplayList;
|
|
|
|
|
2014-04-15 16:18:08 -07:00
|
|
|
const SkPath* projectionOutline = NULL;
|
2014-03-18 09:22:59 -07:00
|
|
|
Vector<DrawDisplayListOp*>* projectionChildren = NULL;
|
|
|
|
const mat4* projectionTransform = NULL;
|
2014-03-20 16:28:56 -07:00
|
|
|
if (isProjectionReceiver && !child->properties().getProjectBackwards()) {
|
2014-03-18 09:22:59 -07:00
|
|
|
// if receiving projections, collect projecting descendent
|
|
|
|
|
|
|
|
// Note that if a direct descendent is projecting backwards, we pass it's
|
|
|
|
// grandparent projection collection, since it shouldn't project onto it's
|
|
|
|
// parent, where it will already be drawing.
|
2014-04-15 16:18:08 -07:00
|
|
|
projectionOutline = properties().getOutline().getPath();
|
2014-03-18 09:22:59 -07:00
|
|
|
projectionChildren = &mProjectedNodes;
|
|
|
|
projectionTransform = &mat4::identity();
|
|
|
|
} else {
|
|
|
|
if (!haveAppliedPropertiesToProjection) {
|
|
|
|
applyViewPropertyTransforms(localTransformFromProjectionSurface);
|
|
|
|
haveAppliedPropertiesToProjection = true;
|
|
|
|
}
|
2014-04-15 16:18:08 -07:00
|
|
|
projectionOutline = outlineOfProjectionSurface;
|
2014-03-18 09:22:59 -07:00
|
|
|
projectionChildren = compositedChildrenOfProjectionSurface;
|
|
|
|
projectionTransform = &localTransformFromProjectionSurface;
|
|
|
|
}
|
2014-04-15 16:18:08 -07:00
|
|
|
child->computeOrderingImpl(childOp,
|
|
|
|
projectionOutline, projectionChildren, projectionTransform);
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeferOperationHandler {
|
|
|
|
public:
|
|
|
|
DeferOperationHandler(DeferStateStruct& deferStruct, int level)
|
|
|
|
: mDeferStruct(deferStruct), mLevel(level) {}
|
|
|
|
inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
|
|
|
|
operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
|
|
|
|
}
|
|
|
|
inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); }
|
2014-03-27 15:50:09 -07:00
|
|
|
inline void startMark(const char* name) {} // do nothing
|
|
|
|
inline void endMark() {}
|
|
|
|
inline int level() { return mLevel; }
|
|
|
|
inline int replayFlags() { return mDeferStruct.mReplayFlags; }
|
2014-03-18 09:22:59 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
DeferStateStruct& mDeferStruct;
|
|
|
|
const int mLevel;
|
|
|
|
};
|
|
|
|
|
2014-03-27 15:50:09 -07:00
|
|
|
void RenderNode::deferNodeTree(DeferStateStruct& deferStruct) {
|
|
|
|
DeferOperationHandler handler(deferStruct, 0);
|
2014-04-25 18:34:11 -07:00
|
|
|
if (MathUtils::isPositive(properties().getZ())) {
|
|
|
|
issueDrawShadowOperation(Matrix4::identity(), handler);
|
|
|
|
}
|
2014-03-27 15:50:09 -07:00
|
|
|
issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderNode::deferNodeInParent(DeferStateStruct& deferStruct, const int level) {
|
2014-03-18 09:22:59 -07:00
|
|
|
DeferOperationHandler handler(deferStruct, level);
|
2014-03-27 15:50:09 -07:00
|
|
|
issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler);
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class ReplayOperationHandler {
|
|
|
|
public:
|
|
|
|
ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
|
|
|
|
: mReplayStruct(replayStruct), mLevel(level) {}
|
|
|
|
inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
|
|
|
|
#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
|
2014-04-15 16:18:08 -07:00
|
|
|
mReplayStruct.mRenderer.eventMark(operation->name());
|
2014-03-18 09:22:59 -07:00
|
|
|
#endif
|
|
|
|
operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
|
|
|
|
}
|
|
|
|
inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); }
|
2014-03-27 15:50:09 -07:00
|
|
|
inline void startMark(const char* name) {
|
|
|
|
mReplayStruct.mRenderer.startMark(name);
|
|
|
|
}
|
|
|
|
inline void endMark() {
|
|
|
|
mReplayStruct.mRenderer.endMark();
|
|
|
|
}
|
|
|
|
inline int level() { return mLevel; }
|
|
|
|
inline int replayFlags() { return mReplayStruct.mReplayFlags; }
|
2014-03-18 09:22:59 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
ReplayStateStruct& mReplayStruct;
|
|
|
|
const int mLevel;
|
|
|
|
};
|
|
|
|
|
2014-03-27 15:50:09 -07:00
|
|
|
void RenderNode::replayNodeTree(ReplayStateStruct& replayStruct) {
|
|
|
|
ReplayOperationHandler handler(replayStruct, 0);
|
2014-04-25 18:34:11 -07:00
|
|
|
if (MathUtils::isPositive(properties().getZ())) {
|
|
|
|
issueDrawShadowOperation(Matrix4::identity(), handler);
|
|
|
|
}
|
2014-03-27 15:50:09 -07:00
|
|
|
issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
|
|
|
|
}
|
2014-03-18 09:22:59 -07:00
|
|
|
|
2014-03-27 15:50:09 -07:00
|
|
|
void RenderNode::replayNodeInParent(ReplayStateStruct& replayStruct, const int level) {
|
|
|
|
ReplayOperationHandler handler(replayStruct, level);
|
|
|
|
issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler);
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderNode::buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes) {
|
2014-04-04 16:20:08 -07:00
|
|
|
if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return;
|
2014-03-18 09:22:59 -07:00
|
|
|
|
2014-04-04 16:20:08 -07:00
|
|
|
for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) {
|
|
|
|
DrawDisplayListOp* childOp = mDisplayListData->children()[i];
|
2014-03-18 09:22:59 -07:00
|
|
|
RenderNode* child = childOp->mDisplayList;
|
2014-04-25 18:34:11 -07:00
|
|
|
float childZ = child->properties().getZ();
|
2014-03-18 09:22:59 -07:00
|
|
|
|
2014-04-22 17:55:41 -07:00
|
|
|
if (!MathUtils::isZero(childZ)) {
|
2014-03-18 09:22:59 -07:00
|
|
|
zTranslatedNodes.add(ZDrawDisplayListOpPair(childZ, childOp));
|
|
|
|
childOp->mSkipInOrderDraw = true;
|
2014-03-20 16:28:56 -07:00
|
|
|
} else if (!child->properties().getProjectBackwards()) {
|
2014-03-18 09:22:59 -07:00
|
|
|
// regular, in order drawing DisplayList
|
|
|
|
childOp->mSkipInOrderDraw = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Z sort 3d children (stable-ness makes z compare fall back to standard drawing order)
|
|
|
|
std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end());
|
|
|
|
}
|
|
|
|
|
2014-03-27 15:50:09 -07:00
|
|
|
template <class T>
|
|
|
|
void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
|
2014-05-21 13:03:52 -07:00
|
|
|
if (properties().getAlpha() <= 0.0f || properties().getOutline().isEmpty()) return;
|
2014-03-27 15:50:09 -07:00
|
|
|
|
|
|
|
mat4 shadowMatrixXY(transformFromParent);
|
|
|
|
applyViewPropertyTransforms(shadowMatrixXY);
|
|
|
|
|
|
|
|
// Z matrix needs actual 3d transformation, so mapped z values will be correct
|
|
|
|
mat4 shadowMatrixZ(transformFromParent);
|
|
|
|
applyViewPropertyTransforms(shadowMatrixZ, true);
|
|
|
|
|
|
|
|
const SkPath* outlinePath = properties().getOutline().getPath();
|
|
|
|
const RevealClip& revealClip = properties().getRevealClip();
|
|
|
|
const SkPath* revealClipPath = revealClip.hasConvexClip()
|
|
|
|
? revealClip.getPath() : NULL; // only pass the reveal clip's path if it's convex
|
|
|
|
|
2014-05-21 13:03:52 -07:00
|
|
|
if (revealClipPath && revealClipPath->isEmpty()) return;
|
|
|
|
|
2014-03-27 15:50:09 -07:00
|
|
|
/**
|
|
|
|
* The drawing area of the caster is always the same as the its perimeter (which
|
|
|
|
* the shadow system uses) *except* in the inverse clip case. Inform the shadow
|
|
|
|
* system that the caster's drawing area (as opposed to its perimeter) has been
|
|
|
|
* clipped, so that it knows the caster can't be opaque.
|
|
|
|
*/
|
|
|
|
bool casterUnclipped = !revealClip.willClip() || revealClip.hasConvexClip();
|
|
|
|
|
|
|
|
DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
|
|
|
|
shadowMatrixXY, shadowMatrixZ,
|
|
|
|
properties().getAlpha(), casterUnclipped,
|
|
|
|
outlinePath, revealClipPath);
|
|
|
|
handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
|
|
|
}
|
|
|
|
|
2014-03-18 09:22:59 -07:00
|
|
|
#define SHADOW_DELTA 0.1f
|
|
|
|
|
|
|
|
template <class T>
|
2014-03-27 15:50:09 -07:00
|
|
|
void RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes,
|
2014-03-18 09:22:59 -07:00
|
|
|
ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) {
|
|
|
|
const int size = zTranslatedNodes.size();
|
|
|
|
if (size == 0
|
|
|
|
|| (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f)
|
|
|
|
|| (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) {
|
|
|
|
// no 3d children to draw
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw shadows and (potential) casters mostly in order, but allow the shadows of casters
|
|
|
|
* with very similar Z heights to draw together.
|
|
|
|
*
|
|
|
|
* This way, if Views A & B have the same Z height and are both casting shadows, the shadows are
|
|
|
|
* underneath both, and neither's shadow is drawn on top of the other.
|
|
|
|
*/
|
|
|
|
const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes);
|
|
|
|
size_t drawIndex, shadowIndex, endIndex;
|
|
|
|
if (mode == kNegativeZChildren) {
|
|
|
|
drawIndex = 0;
|
|
|
|
endIndex = nonNegativeIndex;
|
|
|
|
shadowIndex = endIndex; // draw no shadows
|
|
|
|
} else {
|
|
|
|
drawIndex = nonNegativeIndex;
|
|
|
|
endIndex = size;
|
|
|
|
shadowIndex = drawIndex; // potentially draw shadow for each pos Z child
|
|
|
|
}
|
2014-04-15 16:18:08 -07:00
|
|
|
|
|
|
|
DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "",
|
|
|
|
endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive");
|
|
|
|
|
2014-03-18 09:22:59 -07:00
|
|
|
float lastCasterZ = 0.0f;
|
|
|
|
while (shadowIndex < endIndex || drawIndex < endIndex) {
|
|
|
|
if (shadowIndex < endIndex) {
|
|
|
|
DrawDisplayListOp* casterOp = zTranslatedNodes[shadowIndex].value;
|
|
|
|
RenderNode* caster = casterOp->mDisplayList;
|
|
|
|
const float casterZ = zTranslatedNodes[shadowIndex].key;
|
|
|
|
// attempt to render the shadow if the caster about to be drawn is its caster,
|
|
|
|
// OR if its caster's Z value is similar to the previous potential caster
|
|
|
|
if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
|
2014-03-27 15:50:09 -07:00
|
|
|
caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler);
|
2014-03-18 09:22:59 -07:00
|
|
|
|
|
|
|
lastCasterZ = casterZ; // must do this even if current caster not casting a shadow
|
|
|
|
shadowIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only the actual child DL draw needs to be in save/restore,
|
|
|
|
// since it modifies the renderer's matrix
|
|
|
|
int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
|
|
|
|
|
|
|
|
DrawDisplayListOp* childOp = zTranslatedNodes[drawIndex].value;
|
|
|
|
RenderNode* child = childOp->mDisplayList;
|
|
|
|
|
|
|
|
renderer.concatMatrix(childOp->mTransformFromParent);
|
|
|
|
childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
|
2014-03-20 16:28:56 -07:00
|
|
|
handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
|
2014-03-18 09:22:59 -07:00
|
|
|
childOp->mSkipInOrderDraw = true;
|
|
|
|
|
|
|
|
renderer.restoreToCount(restoreTo);
|
|
|
|
drawIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2014-03-27 15:50:09 -07:00
|
|
|
void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) {
|
2014-04-15 16:18:08 -07:00
|
|
|
DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size());
|
|
|
|
const SkPath* projectionReceiverOutline = properties().getOutline().getPath();
|
|
|
|
bool maskProjecteesWithPath = projectionReceiverOutline != NULL
|
|
|
|
&& !projectionReceiverOutline->isRect(NULL);
|
|
|
|
int restoreTo = renderer.getSaveCount();
|
|
|
|
|
|
|
|
// If the projection reciever has an outline, we mask each of the projected rendernodes to it
|
|
|
|
// Either with clipRect, or special saveLayer masking
|
|
|
|
LinearAllocator& alloc = handler.allocator();
|
|
|
|
if (projectionReceiverOutline != NULL) {
|
|
|
|
const SkRect& outlineBounds = projectionReceiverOutline->getBounds();
|
|
|
|
if (projectionReceiverOutline->isRect(NULL)) {
|
|
|
|
// mask to the rect outline simply with clipRect
|
|
|
|
handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
|
|
|
|
PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
|
|
|
ClipRectOp* clipOp = new (alloc) ClipRectOp(
|
|
|
|
outlineBounds.left(), outlineBounds.top(),
|
|
|
|
outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op);
|
|
|
|
handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
|
|
|
} else {
|
|
|
|
// wrap the projected RenderNodes with a SaveLayer that will mask to the outline
|
|
|
|
SaveLayerOp* op = new (alloc) SaveLayerOp(
|
|
|
|
outlineBounds.left(), outlineBounds.top(),
|
|
|
|
outlineBounds.right(), outlineBounds.bottom(),
|
|
|
|
255, SkCanvas::kARGB_ClipLayer_SaveFlag);
|
|
|
|
op->setMask(projectionReceiverOutline);
|
|
|
|
handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
|
|
|
|
|
|
|
/* TODO: add optimizations here to take advantage of placement/size of projected
|
|
|
|
* children (which may shrink saveLayer area significantly). This is dependent on
|
|
|
|
* passing actual drawing/dirtying bounds of projected content down to native.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw projected nodes
|
2014-03-18 09:22:59 -07:00
|
|
|
for (size_t i = 0; i < mProjectedNodes.size(); i++) {
|
|
|
|
DrawDisplayListOp* childOp = mProjectedNodes[i];
|
|
|
|
|
|
|
|
// matrix save, concat, and restore can be done safely without allocating operations
|
|
|
|
int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag);
|
|
|
|
renderer.concatMatrix(childOp->mTransformFromCompositingAncestor);
|
|
|
|
childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone
|
2014-03-20 16:28:56 -07:00
|
|
|
handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds());
|
2014-03-18 09:22:59 -07:00
|
|
|
childOp->mSkipInOrderDraw = true;
|
|
|
|
renderer.restoreToCount(restoreTo);
|
|
|
|
}
|
2014-04-15 16:18:08 -07:00
|
|
|
|
|
|
|
if (projectionReceiverOutline != NULL) {
|
|
|
|
handler(new (alloc) RestoreToCountOp(restoreTo),
|
|
|
|
PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
|
|
|
}
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function serves both defer and replay modes, and will organize the displayList's component
|
|
|
|
* operations for a single frame:
|
|
|
|
*
|
|
|
|
* Every 'simple' state operation that affects just the matrix and alpha (or other factors of
|
|
|
|
* DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
|
|
|
|
* defer logic) and operations in displayListOps are issued through the 'handler' which handles the
|
|
|
|
* defer vs replay logic, per operation
|
|
|
|
*/
|
|
|
|
template <class T>
|
2014-03-27 15:50:09 -07:00
|
|
|
void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
|
2014-06-12 13:46:45 -07:00
|
|
|
const bool drawLayer = (mLayer && (&renderer != mLayer->renderer));
|
|
|
|
// If we are updating the contents of mLayer, we don't want to apply any of
|
|
|
|
// the RenderNode's properties to this issueOperations pass. Those will all
|
|
|
|
// be applied when the layer is drawn, aka when this is true.
|
|
|
|
const bool useViewProperties = (!mLayer || drawLayer);
|
|
|
|
|
2014-03-27 15:50:09 -07:00
|
|
|
const int level = handler.level();
|
2014-06-12 13:46:45 -07:00
|
|
|
if (mDisplayListData->isEmpty() || (useViewProperties && properties().getAlpha() <= 0)) {
|
2014-04-15 16:18:08 -07:00
|
|
|
DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName());
|
2014-03-18 09:22:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-15 16:18:08 -07:00
|
|
|
handler.startMark(getName());
|
2014-03-27 15:50:09 -07:00
|
|
|
|
2014-03-18 09:22:59 -07:00
|
|
|
#if DEBUG_DISPLAY_LIST
|
2014-04-15 16:18:08 -07:00
|
|
|
const Rect& clipRect = renderer.getLocalClipBounds();
|
|
|
|
DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f",
|
|
|
|
level * 2, "", this, getName(),
|
|
|
|
clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
|
2014-03-18 09:22:59 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
LinearAllocator& alloc = handler.allocator();
|
|
|
|
int restoreTo = renderer.getSaveCount();
|
|
|
|
handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
|
2014-03-20 16:28:56 -07:00
|
|
|
PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
2014-03-18 09:22:59 -07:00
|
|
|
|
|
|
|
DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "",
|
|
|
|
SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
|
|
|
|
|
2014-06-12 13:46:45 -07:00
|
|
|
if (useViewProperties) {
|
|
|
|
setViewProperties<T>(renderer, handler);
|
|
|
|
}
|
2014-03-18 09:22:59 -07:00
|
|
|
|
2014-03-25 10:33:01 -07:00
|
|
|
bool quickRejected = properties().getClipToBounds()
|
|
|
|
&& renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight());
|
2014-03-18 09:22:59 -07:00
|
|
|
if (!quickRejected) {
|
2014-05-05 19:09:33 -07:00
|
|
|
if (mProperties.getOutline().willClip()) {
|
|
|
|
renderer.setClippingOutline(alloc, &(mProperties.getOutline()));
|
|
|
|
}
|
|
|
|
|
2014-06-12 13:46:45 -07:00
|
|
|
if (drawLayer) {
|
|
|
|
handler(new (alloc) DrawLayerOp(mLayer, 0, 0),
|
|
|
|
renderer.getSaveCount() - 1, properties().getClipToBounds());
|
|
|
|
} else {
|
|
|
|
Vector<ZDrawDisplayListOpPair> zTranslatedNodes;
|
|
|
|
buildZSortedChildList(zTranslatedNodes);
|
|
|
|
|
|
|
|
// for 3d root, draw children with negative z values
|
|
|
|
issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler);
|
|
|
|
|
|
|
|
DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
|
|
|
|
const int saveCountOffset = renderer.getSaveCount() - 1;
|
|
|
|
const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex;
|
|
|
|
for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
|
|
|
|
DisplayListOp *op = mDisplayListData->displayListOps[i];
|
|
|
|
|
|
|
|
#if DEBUG_DISPLAY_LIST
|
|
|
|
op->output(level + 1);
|
|
|
|
#endif
|
|
|
|
logBuffer.writeCommand(level, op->name());
|
|
|
|
handler(op, saveCountOffset, properties().getClipToBounds());
|
|
|
|
|
|
|
|
if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) {
|
|
|
|
issueOperationsOfProjectedChildren(renderer, handler);
|
|
|
|
}
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
2014-06-12 13:46:45 -07:00
|
|
|
// for 3d root, draw children with positive z values
|
|
|
|
issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler);
|
|
|
|
}
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
|
|
|
|
handler(new (alloc) RestoreToCountOp(restoreTo),
|
2014-03-20 16:28:56 -07:00
|
|
|
PROPERTY_SAVECOUNT, properties().getClipToBounds());
|
2014-03-18 09:22:59 -07:00
|
|
|
renderer.setOverrideLayerAlpha(1.0f);
|
2014-03-27 15:50:09 -07:00
|
|
|
|
2014-04-15 16:18:08 -07:00
|
|
|
DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName());
|
2014-03-27 15:50:09 -07:00
|
|
|
handler.endMark();
|
2014-03-18 09:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace uirenderer */
|
|
|
|
} /* namespace android */
|