RenderNode.cpp revision e4267ea4f20740c37c01bfb6aefcf61fddc4566a
1113e0824d6bddf4376240681f9cf6a2deded9498John Reck/* 2113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Copyright (C) 2014 The Android Open Source Project 3113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 4113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 5113e0824d6bddf4376240681f9cf6a2deded9498John Reck * you may not use this file except in compliance with the License. 6113e0824d6bddf4376240681f9cf6a2deded9498John Reck * You may obtain a copy of the License at 7113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 8113e0824d6bddf4376240681f9cf6a2deded9498John Reck * http://www.apache.org/licenses/LICENSE-2.0 9113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 10113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Unless required by applicable law or agreed to in writing, software 11113e0824d6bddf4376240681f9cf6a2deded9498John Reck * distributed under the License is distributed on an "AS IS" BASIS, 12113e0824d6bddf4376240681f9cf6a2deded9498John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13113e0824d6bddf4376240681f9cf6a2deded9498John Reck * See the License for the specific language governing permissions and 14113e0824d6bddf4376240681f9cf6a2deded9498John Reck * limitations under the License. 15113e0824d6bddf4376240681f9cf6a2deded9498John Reck */ 16113e0824d6bddf4376240681f9cf6a2deded9498John Reck 17113e0824d6bddf4376240681f9cf6a2deded9498John Reck#define ATRACE_TAG ATRACE_TAG_VIEW 18113e0824d6bddf4376240681f9cf6a2deded9498John Reck 19113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include "RenderNode.h" 20113e0824d6bddf4376240681f9cf6a2deded9498John Reck 21e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include <algorithm> 22e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 23113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include <SkCanvas.h> 24113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include <algorithm> 25113e0824d6bddf4376240681f9cf6a2deded9498John Reck 26113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include <utils/Trace.h> 27113e0824d6bddf4376240681f9cf6a2deded9498John Reck 28e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck#include "DamageAccumulator.h" 29113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include "Debug.h" 30113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include "DisplayListOp.h" 31113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include "DisplayListLogBuffer.h" 32e0bb87d4bdbd3b08ab6a8569c8e564ed59b8a5a7Chris Craik#include "utils/MathUtils.h" 33113e0824d6bddf4376240681f9cf6a2deded9498John Reck 34113e0824d6bddf4376240681f9cf6a2deded9498John Recknamespace android { 35113e0824d6bddf4376240681f9cf6a2deded9498John Recknamespace uirenderer { 36113e0824d6bddf4376240681f9cf6a2deded9498John Reck 37113e0824d6bddf4376240681f9cf6a2deded9498John Reckvoid RenderNode::outputLogBuffer(int fd) { 38113e0824d6bddf4376240681f9cf6a2deded9498John Reck DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); 39113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (logBuffer.isEmpty()) { 40113e0824d6bddf4376240681f9cf6a2deded9498John Reck return; 41113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 42113e0824d6bddf4376240681f9cf6a2deded9498John Reck 43113e0824d6bddf4376240681f9cf6a2deded9498John Reck FILE *file = fdopen(fd, "a"); 44113e0824d6bddf4376240681f9cf6a2deded9498John Reck 45113e0824d6bddf4376240681f9cf6a2deded9498John Reck fprintf(file, "\nRecent DisplayList operations\n"); 46113e0824d6bddf4376240681f9cf6a2deded9498John Reck logBuffer.outputCommands(file); 47113e0824d6bddf4376240681f9cf6a2deded9498John Reck 48113e0824d6bddf4376240681f9cf6a2deded9498John Reck String8 cachesLog; 49113e0824d6bddf4376240681f9cf6a2deded9498John Reck Caches::getInstance().dumpMemoryUsage(cachesLog); 50113e0824d6bddf4376240681f9cf6a2deded9498John Reck fprintf(file, "\nCaches:\n%s", cachesLog.string()); 51113e0824d6bddf4376240681f9cf6a2deded9498John Reck fprintf(file, "\n"); 52113e0824d6bddf4376240681f9cf6a2deded9498John Reck 53113e0824d6bddf4376240681f9cf6a2deded9498John Reck fflush(file); 54113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 55113e0824d6bddf4376240681f9cf6a2deded9498John Reck 568de65a8e05285df52a1e6f0c1d5616dd233298a7John ReckRenderNode::RenderNode() 57ff941dcd815021bb20d6504eb486acb1e50592c3John Reck : mDirtyPropertyFields(0) 588de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck , mNeedsDisplayListDataSync(false) 598de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck , mDisplayListData(0) 60e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck , mStagingDisplayListData(0) 61e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck , mNeedsAnimatorsSync(false) { 62113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 63113e0824d6bddf4376240681f9cf6a2deded9498John Reck 64113e0824d6bddf4376240681f9cf6a2deded9498John ReckRenderNode::~RenderNode() { 65113e0824d6bddf4376240681f9cf6a2deded9498John Reck delete mDisplayListData; 668de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck delete mStagingDisplayListData; 67113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 68113e0824d6bddf4376240681f9cf6a2deded9498John Reck 698de65a8e05285df52a1e6f0c1d5616dd233298a7John Reckvoid RenderNode::setStagingDisplayList(DisplayListData* data) { 708de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck mNeedsDisplayListDataSync = true; 718de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck delete mStagingDisplayListData; 728de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck mStagingDisplayListData = data; 738de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck if (mStagingDisplayListData) { 748de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck Caches::getInstance().registerFunctors(mStagingDisplayListData->functorCount); 75113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 76113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 77113e0824d6bddf4376240681f9cf6a2deded9498John Reck 78113e0824d6bddf4376240681f9cf6a2deded9498John Reck/** 79113e0824d6bddf4376240681f9cf6a2deded9498John Reck * This function is a simplified version of replay(), where we simply retrieve and log the 80113e0824d6bddf4376240681f9cf6a2deded9498John Reck * display list. This function should remain in sync with the replay() function. 81113e0824d6bddf4376240681f9cf6a2deded9498John Reck */ 82113e0824d6bddf4376240681f9cf6a2deded9498John Reckvoid RenderNode::output(uint32_t level) { 83113e0824d6bddf4376240681f9cf6a2deded9498John Reck ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this, 843f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik getName(), isRenderable()); 85113e0824d6bddf4376240681f9cf6a2deded9498John Reck ALOGD("%*s%s %d", level * 2, "", "Save", 86113e0824d6bddf4376240681f9cf6a2deded9498John Reck SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); 87113e0824d6bddf4376240681f9cf6a2deded9498John Reck 88d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck properties().debugOutputProperties(level); 89113e0824d6bddf4376240681f9cf6a2deded9498John Reck int flags = DisplayListOp::kOpLogFlag_Recurse; 90113e0824d6bddf4376240681f9cf6a2deded9498John Reck for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) { 91113e0824d6bddf4376240681f9cf6a2deded9498John Reck mDisplayListData->displayListOps[i]->output(level, flags); 92113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 93113e0824d6bddf4376240681f9cf6a2deded9498John Reck 943f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName()); 95113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 96113e0824d6bddf4376240681f9cf6a2deded9498John Reck 97fe5e7b7346a54537b980796ceeca66bfdbd05561John Reckint RenderNode::getDebugSize() { 98fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck int size = sizeof(RenderNode); 99fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck if (mStagingDisplayListData) { 100fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck size += mStagingDisplayListData->allocator.usedSize(); 101fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck } 102fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck if (mDisplayListData && mDisplayListData != mStagingDisplayListData) { 103fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck size += mDisplayListData->allocator.usedSize(); 104fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck } 105fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck return size; 106fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck} 107fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 108f4198b713e43c0c0f9adac74203cf24c2a49b802John Reckvoid RenderNode::prepareTree(TreeInfo& info) { 109f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck ATRACE_CALL(); 110f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck 111f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck prepareTreeImpl(info); 112f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck} 113f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck 114e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckstatic inline void pushNode(RenderNode* self, TreeInfo& info) { 115e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck if (info.damageAccumulator) { 116e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck info.damageAccumulator->pushNode(self); 117e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck } 118e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck} 119e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 120e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckstatic inline void popNode(TreeInfo& info) { 121e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck if (info.damageAccumulator) { 122e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck info.damageAccumulator->popNode(); 123e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck } 124e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck} 125e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 126e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckvoid RenderNode::damageSelf(TreeInfo& info) { 127e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck if (info.damageAccumulator && isRenderable() && properties().getAlpha() > 0) { 128e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight()); 129e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck } 130e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck} 131e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 132f4198b713e43c0c0f9adac74203cf24c2a49b802John Reckvoid RenderNode::prepareTreeImpl(TreeInfo& info) { 133e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck pushNode(this, info); 134e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck if (info.mode == TreeInfo::MODE_FULL) { 135e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck pushStagingChanges(info); 136e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck evaluateAnimations(info); 137e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck } else if (info.mode == TreeInfo::MODE_MAYBE_DETACHING) { 138e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck pushStagingChanges(info); 139e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck } else if (info.mode == TreeInfo::MODE_RT_ONLY) { 140e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck evaluateAnimations(info); 141e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck } 142f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck prepareSubTree(info, mDisplayListData); 143e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck popNode(info); 144f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck} 145f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck 146ff941dcd815021bb20d6504eb486acb1e50592c3John Reckclass PushAnimatorsFunctor { 147ff941dcd815021bb20d6504eb486acb1e50592c3John Reckpublic: 148ff941dcd815021bb20d6504eb486acb1e50592c3John Reck PushAnimatorsFunctor(RenderNode* target, TreeInfo& info) 149ff941dcd815021bb20d6504eb486acb1e50592c3John Reck : mTarget(target), mInfo(info) {} 150e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 151ff941dcd815021bb20d6504eb486acb1e50592c3John Reck bool operator() (const sp<BaseRenderNodeAnimator>& animator) { 152ff941dcd815021bb20d6504eb486acb1e50592c3John Reck animator->setupStartValueIfNecessary(mTarget, mInfo); 153ff941dcd815021bb20d6504eb486acb1e50592c3John Reck return animator->isFinished(); 154113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 155ff941dcd815021bb20d6504eb486acb1e50592c3John Reckprivate: 156ff941dcd815021bb20d6504eb486acb1e50592c3John Reck RenderNode* mTarget; 157ff941dcd815021bb20d6504eb486acb1e50592c3John Reck TreeInfo& mInfo; 158ff941dcd815021bb20d6504eb486acb1e50592c3John Reck}; 159ff941dcd815021bb20d6504eb486acb1e50592c3John Reck 160ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid RenderNode::pushStagingChanges(TreeInfo& info) { 161ff941dcd815021bb20d6504eb486acb1e50592c3John Reck // Push the animators first so that setupStartValueIfNecessary() is called 162ff941dcd815021bb20d6504eb486acb1e50592c3John Reck // before properties() is trampled by stagingProperties(), as they are 163ff941dcd815021bb20d6504eb486acb1e50592c3John Reck // required by some animators. 164e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck if (mNeedsAnimatorsSync) { 16552622668f91c69ec718b356d2e0f8555fc88435fJohn Reck mAnimators.resize(mStagingAnimators.size()); 16652244fff29042926e21fa897ef5ab11148e35299John Reck std::vector< sp<BaseRenderNodeAnimator> >::iterator it; 167ff941dcd815021bb20d6504eb486acb1e50592c3John Reck PushAnimatorsFunctor functor(this, info); 168e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck // hint: this means copy_if_not() 169e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck it = std::remove_copy_if(mStagingAnimators.begin(), mStagingAnimators.end(), 170ff941dcd815021bb20d6504eb486acb1e50592c3John Reck mAnimators.begin(), functor); 171e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck mAnimators.resize(std::distance(mAnimators.begin(), it)); 172e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck } 173ff941dcd815021bb20d6504eb486acb1e50592c3John Reck if (mDirtyPropertyFields) { 174ff941dcd815021bb20d6504eb486acb1e50592c3John Reck mDirtyPropertyFields = 0; 175e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck damageSelf(info); 176e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck popNode(info); 177ff941dcd815021bb20d6504eb486acb1e50592c3John Reck mProperties = mStagingProperties; 178e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck pushNode(this, info); 179e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // We could try to be clever and only re-damage if the matrix changed. 180e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // However, we don't need to worry about that. The cost of over-damaging 181e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // here is only going to be a single additional map rect of this node 182e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // plus a rect join(). The parent's transform (and up) will only be 183e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // performed once. 184e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck damageSelf(info); 185ff941dcd815021bb20d6504eb486acb1e50592c3John Reck } 1868de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck if (mNeedsDisplayListDataSync) { 1878de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck mNeedsDisplayListDataSync = false; 1888de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck // Do a push pass on the old tree to handle freeing DisplayListData 1898de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck // that are no longer used 190e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck TreeInfo oldTreeInfo(TreeInfo::MODE_MAYBE_DETACHING); 191e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck oldTreeInfo.damageAccumulator = info.damageAccumulator; 192f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck prepareSubTree(oldTreeInfo, mDisplayListData); 1938de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck delete mDisplayListData; 1948de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck mDisplayListData = mStagingDisplayListData; 1958de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck mStagingDisplayListData = 0; 196e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck damageSelf(info); 1978de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck } 1988de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck} 199113e0824d6bddf4376240681f9cf6a2deded9498John Reck 200e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckclass AnimateFunctor { 201e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckpublic: 20252244fff29042926e21fa897ef5ab11148e35299John Reck AnimateFunctor(RenderNode* target, TreeInfo& info) 203e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck : mTarget(target), mInfo(info) {} 204e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 205ff941dcd815021bb20d6504eb486acb1e50592c3John Reck bool operator() (const sp<BaseRenderNodeAnimator>& animator) { 20652244fff29042926e21fa897ef5ab11148e35299John Reck return animator->animate(mTarget, mInfo); 207e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck } 208e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckprivate: 20952244fff29042926e21fa897ef5ab11148e35299John Reck RenderNode* mTarget; 210e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck TreeInfo& mInfo; 211e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}; 212e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 213e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckvoid RenderNode::evaluateAnimations(TreeInfo& info) { 214e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck if (!mAnimators.size()) return; 215e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 216e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // TODO: Can we target this better? For now treat it like any other staging 217e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // property push and just damage self before and after animators are run 218e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 219e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck damageSelf(info); 220e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck popNode(info); 221e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 22252244fff29042926e21fa897ef5ab11148e35299John Reck AnimateFunctor functor(this, info); 22352244fff29042926e21fa897ef5ab11148e35299John Reck std::vector< sp<BaseRenderNodeAnimator> >::iterator newEnd; 224e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck newEnd = std::remove_if(mAnimators.begin(), mAnimators.end(), functor); 225e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck mAnimators.erase(newEnd, mAnimators.end()); 226e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck mProperties.updateMatrix(); 227f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck info.out.hasAnimations |= mAnimators.size(); 228e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 229e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck pushNode(this, info); 230e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck damageSelf(info); 231e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} 232e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 233f4198b713e43c0c0f9adac74203cf24c2a49b802John Reckvoid RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) { 2348de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck if (subtree) { 235860d155f866cc15a725e7ce03763280987f24901John Reck TextureCache& cache = Caches::getInstance().textureCache; 236f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck info.out.hasFunctors |= subtree->functorCount; 237860d155f866cc15a725e7ce03763280987f24901John Reck // TODO: Fix ownedBitmapResources to not require disabling prepareTextures 238860d155f866cc15a725e7ce03763280987f24901John Reck // and thus falling out of async drawing path. 239860d155f866cc15a725e7ce03763280987f24901John Reck if (subtree->ownedBitmapResources.size()) { 240860d155f866cc15a725e7ce03763280987f24901John Reck info.prepareTextures = false; 241860d155f866cc15a725e7ce03763280987f24901John Reck } 242860d155f866cc15a725e7ce03763280987f24901John Reck for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) { 243860d155f866cc15a725e7ce03763280987f24901John Reck info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]); 244f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck } 2458de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck for (size_t i = 0; i < subtree->children().size(); i++) { 2468de65a8e05285df52a1e6f0c1d5616dd233298a7John Reck RenderNode* childNode = subtree->children()[i]->mDisplayList; 247f4198b713e43c0c0f9adac74203cf24c2a49b802John Reck childNode->prepareTreeImpl(info); 2485bf11bb98f5dbe278c257355d24c181237abd68cJohn Reck } 249113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 250113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 251113e0824d6bddf4376240681f9cf6a2deded9498John Reck 252113e0824d6bddf4376240681f9cf6a2deded9498John Reck/* 253113e0824d6bddf4376240681f9cf6a2deded9498John Reck * For property operations, we pass a savecount of 0, since the operations aren't part of the 254113e0824d6bddf4376240681f9cf6a2deded9498John Reck * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in 255d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount()) 256113e0824d6bddf4376240681f9cf6a2deded9498John Reck */ 257113e0824d6bddf4376240681f9cf6a2deded9498John Reck#define PROPERTY_SAVECOUNT 0 258113e0824d6bddf4376240681f9cf6a2deded9498John Reck 259113e0824d6bddf4376240681f9cf6a2deded9498John Recktemplate <class T> 260b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) { 261113e0824d6bddf4376240681f9cf6a2deded9498John Reck#if DEBUG_DISPLAY_LIST 262b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik properties().debugOutputProperties(handler.level() + 1); 263113e0824d6bddf4376240681f9cf6a2deded9498John Reck#endif 264d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (properties().getLeft() != 0 || properties().getTop() != 0) { 265d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck renderer.translate(properties().getLeft(), properties().getTop()); 266113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 267d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (properties().getStaticMatrix()) { 268139088228faa7f3c446af7387e017933998a5570Derek Sollenberger renderer.concatMatrix(*properties().getStaticMatrix()); 269d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck } else if (properties().getAnimationMatrix()) { 270139088228faa7f3c446af7387e017933998a5570Derek Sollenberger renderer.concatMatrix(*properties().getAnimationMatrix()); 271113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 272f7483e3af0513a1baa8341d403df2e0c0896a9ffJohn Reck if (properties().hasTransformMatrix()) { 273f7483e3af0513a1baa8341d403df2e0c0896a9ffJohn Reck if (properties().isTransformTranslateOnly()) { 274d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck renderer.translate(properties().getTranslationX(), properties().getTranslationY()); 275113e0824d6bddf4376240681f9cf6a2deded9498John Reck } else { 276d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck renderer.concatMatrix(*properties().getTransformMatrix()); 277113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 278113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 279d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck bool clipToBoundsNeeded = properties().getCaching() ? false : properties().getClipToBounds(); 280d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (properties().getAlpha() < 1) { 281d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (properties().getCaching()) { 282d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck renderer.setOverrideLayerAlpha(properties().getAlpha()); 283d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck } else if (!properties().getHasOverlappingRendering()) { 284d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck renderer.scaleAlpha(properties().getAlpha()); 285113e0824d6bddf4376240681f9cf6a2deded9498John Reck } else { 286113e0824d6bddf4376240681f9cf6a2deded9498John Reck // TODO: should be able to store the size of a DL at record time and not 287113e0824d6bddf4376240681f9cf6a2deded9498John Reck // have to pass it into this call. In fact, this information might be in the 288113e0824d6bddf4376240681f9cf6a2deded9498John Reck // location/size info that we store with the new native transform data. 289113e0824d6bddf4376240681f9cf6a2deded9498John Reck int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag; 290113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (clipToBoundsNeeded) { 291113e0824d6bddf4376240681f9cf6a2deded9498John Reck saveFlags |= SkCanvas::kClipToLayer_SaveFlag; 292113e0824d6bddf4376240681f9cf6a2deded9498John Reck clipToBoundsNeeded = false; // clipping done by saveLayer 293113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 294113e0824d6bddf4376240681f9cf6a2deded9498John Reck 295113e0824d6bddf4376240681f9cf6a2deded9498John Reck SaveLayerOp* op = new (handler.allocator()) SaveLayerOp( 2968c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik 0, 0, properties().getWidth(), properties().getHeight(), 2978c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik properties().getAlpha() * 255, saveFlags); 298d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); 299113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 300113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 301113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (clipToBoundsNeeded) { 3028c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik ClipRectOp* op = new (handler.allocator()) ClipRectOp( 3038c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik 0, 0, properties().getWidth(), properties().getHeight(), SkRegion::kIntersect_Op); 304d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); 305113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 3068c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik 3078c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik if (CC_UNLIKELY(properties().hasClippingPath())) { 3082bcad176757386d906157bb898167fbcebe9f55eChris Craik ClipPathOp* op = new (handler.allocator()) ClipPathOp( 3092bcad176757386d906157bb898167fbcebe9f55eChris Craik properties().getClippingPath(), properties().getClippingPathOp()); 310d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); 311113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 312113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 313113e0824d6bddf4376240681f9cf6a2deded9498John Reck 314113e0824d6bddf4376240681f9cf6a2deded9498John Reck/** 315113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Apply property-based transformations to input matrix 316113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 317113e0824d6bddf4376240681f9cf6a2deded9498John Reck * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 318113e0824d6bddf4376240681f9cf6a2deded9498John Reck * matrix computation instead of the Skia 3x3 matrix + camera hackery. 319113e0824d6bddf4376240681f9cf6a2deded9498John Reck */ 320113e0824d6bddf4376240681f9cf6a2deded9498John Reckvoid RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) { 321d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (properties().getLeft() != 0 || properties().getTop() != 0) { 322d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck matrix.translate(properties().getLeft(), properties().getTop()); 323113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 324d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (properties().getStaticMatrix()) { 325d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck mat4 stat(*properties().getStaticMatrix()); 326113e0824d6bddf4376240681f9cf6a2deded9498John Reck matrix.multiply(stat); 327d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck } else if (properties().getAnimationMatrix()) { 328d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck mat4 anim(*properties().getAnimationMatrix()); 329113e0824d6bddf4376240681f9cf6a2deded9498John Reck matrix.multiply(anim); 330113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 331e0bb87d4bdbd3b08ab6a8569c8e564ed59b8a5a7Chris Craik 332cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); 333e0bb87d4bdbd3b08ab6a8569c8e564ed59b8a5a7Chris Craik if (properties().hasTransformMatrix() || applyTranslationZ) { 334f7483e3af0513a1baa8341d403df2e0c0896a9ffJohn Reck if (properties().isTransformTranslateOnly()) { 335d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck matrix.translate(properties().getTranslationX(), properties().getTranslationY(), 336cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik true3dTransform ? properties().getZ() : 0.0f); 337113e0824d6bddf4376240681f9cf6a2deded9498John Reck } else { 338113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (!true3dTransform) { 339d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck matrix.multiply(*properties().getTransformMatrix()); 340113e0824d6bddf4376240681f9cf6a2deded9498John Reck } else { 341113e0824d6bddf4376240681f9cf6a2deded9498John Reck mat4 true3dMat; 342113e0824d6bddf4376240681f9cf6a2deded9498John Reck true3dMat.loadTranslate( 343d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck properties().getPivotX() + properties().getTranslationX(), 344d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck properties().getPivotY() + properties().getTranslationY(), 345cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik properties().getZ()); 346d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck true3dMat.rotate(properties().getRotationX(), 1, 0, 0); 347d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck true3dMat.rotate(properties().getRotationY(), 0, 1, 0); 348d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck true3dMat.rotate(properties().getRotation(), 0, 0, 1); 349d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); 350d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); 351113e0824d6bddf4376240681f9cf6a2deded9498John Reck 352113e0824d6bddf4376240681f9cf6a2deded9498John Reck matrix.multiply(true3dMat); 353113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 354113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 355113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 356113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 357113e0824d6bddf4376240681f9cf6a2deded9498John Reck 358113e0824d6bddf4376240681f9cf6a2deded9498John Reck/** 359113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Organizes the DisplayList hierarchy to prepare for background projection reordering. 360113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 361113e0824d6bddf4376240681f9cf6a2deded9498John Reck * This should be called before a call to defer() or drawDisplayList() 362113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 363113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Each DisplayList that serves as a 3d root builds its list of composited children, 364113e0824d6bddf4376240681f9cf6a2deded9498John Reck * which are flagged to not draw in the standard draw loop. 365113e0824d6bddf4376240681f9cf6a2deded9498John Reck */ 366113e0824d6bddf4376240681f9cf6a2deded9498John Reckvoid RenderNode::computeOrdering() { 367113e0824d6bddf4376240681f9cf6a2deded9498John Reck ATRACE_CALL(); 368113e0824d6bddf4376240681f9cf6a2deded9498John Reck mProjectedNodes.clear(); 369113e0824d6bddf4376240681f9cf6a2deded9498John Reck 370113e0824d6bddf4376240681f9cf6a2deded9498John Reck // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that 371113e0824d6bddf4376240681f9cf6a2deded9498John Reck // transform properties are applied correctly to top level children 372113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (mDisplayListData == NULL) return; 373087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { 374087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck DrawDisplayListOp* childOp = mDisplayListData->children()[i]; 375113e0824d6bddf4376240681f9cf6a2deded9498John Reck childOp->mDisplayList->computeOrderingImpl(childOp, 3763f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity()); 377113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 378113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 379113e0824d6bddf4376240681f9cf6a2deded9498John Reck 380113e0824d6bddf4376240681f9cf6a2deded9498John Reckvoid RenderNode::computeOrderingImpl( 381113e0824d6bddf4376240681f9cf6a2deded9498John Reck DrawDisplayListOp* opState, 3823f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPath* outlineOfProjectionSurface, 383113e0824d6bddf4376240681f9cf6a2deded9498John Reck Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface, 384113e0824d6bddf4376240681f9cf6a2deded9498John Reck const mat4* transformFromProjectionSurface) { 385113e0824d6bddf4376240681f9cf6a2deded9498John Reck mProjectedNodes.clear(); 386113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return; 387113e0824d6bddf4376240681f9cf6a2deded9498John Reck 388113e0824d6bddf4376240681f9cf6a2deded9498John Reck // TODO: should avoid this calculation in most cases 389113e0824d6bddf4376240681f9cf6a2deded9498John Reck // TODO: just calculate single matrix, down to all leaf composited elements 390113e0824d6bddf4376240681f9cf6a2deded9498John Reck Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface); 391113e0824d6bddf4376240681f9cf6a2deded9498John Reck localTransformFromProjectionSurface.multiply(opState->mTransformFromParent); 392113e0824d6bddf4376240681f9cf6a2deded9498John Reck 393d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (properties().getProjectBackwards()) { 394113e0824d6bddf4376240681f9cf6a2deded9498John Reck // composited projectee, flag for out of order draw, save matrix, and store in proj surface 395113e0824d6bddf4376240681f9cf6a2deded9498John Reck opState->mSkipInOrderDraw = true; 396113e0824d6bddf4376240681f9cf6a2deded9498John Reck opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface); 397113e0824d6bddf4376240681f9cf6a2deded9498John Reck compositedChildrenOfProjectionSurface->add(opState); 398113e0824d6bddf4376240681f9cf6a2deded9498John Reck } else { 399113e0824d6bddf4376240681f9cf6a2deded9498John Reck // standard in order draw 400113e0824d6bddf4376240681f9cf6a2deded9498John Reck opState->mSkipInOrderDraw = false; 401113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 402113e0824d6bddf4376240681f9cf6a2deded9498John Reck 403087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck if (mDisplayListData->children().size() > 0) { 404113e0824d6bddf4376240681f9cf6a2deded9498John Reck const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0; 405113e0824d6bddf4376240681f9cf6a2deded9498John Reck bool haveAppliedPropertiesToProjection = false; 406087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { 407087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck DrawDisplayListOp* childOp = mDisplayListData->children()[i]; 408113e0824d6bddf4376240681f9cf6a2deded9498John Reck RenderNode* child = childOp->mDisplayList; 409113e0824d6bddf4376240681f9cf6a2deded9498John Reck 4103f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPath* projectionOutline = NULL; 411113e0824d6bddf4376240681f9cf6a2deded9498John Reck Vector<DrawDisplayListOp*>* projectionChildren = NULL; 412113e0824d6bddf4376240681f9cf6a2deded9498John Reck const mat4* projectionTransform = NULL; 413d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (isProjectionReceiver && !child->properties().getProjectBackwards()) { 414113e0824d6bddf4376240681f9cf6a2deded9498John Reck // if receiving projections, collect projecting descendent 415113e0824d6bddf4376240681f9cf6a2deded9498John Reck 416113e0824d6bddf4376240681f9cf6a2deded9498John Reck // Note that if a direct descendent is projecting backwards, we pass it's 417113e0824d6bddf4376240681f9cf6a2deded9498John Reck // grandparent projection collection, since it shouldn't project onto it's 418113e0824d6bddf4376240681f9cf6a2deded9498John Reck // parent, where it will already be drawing. 4193f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik projectionOutline = properties().getOutline().getPath(); 420113e0824d6bddf4376240681f9cf6a2deded9498John Reck projectionChildren = &mProjectedNodes; 421113e0824d6bddf4376240681f9cf6a2deded9498John Reck projectionTransform = &mat4::identity(); 422113e0824d6bddf4376240681f9cf6a2deded9498John Reck } else { 423113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (!haveAppliedPropertiesToProjection) { 424113e0824d6bddf4376240681f9cf6a2deded9498John Reck applyViewPropertyTransforms(localTransformFromProjectionSurface); 425113e0824d6bddf4376240681f9cf6a2deded9498John Reck haveAppliedPropertiesToProjection = true; 426113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 4273f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik projectionOutline = outlineOfProjectionSurface; 428113e0824d6bddf4376240681f9cf6a2deded9498John Reck projectionChildren = compositedChildrenOfProjectionSurface; 429113e0824d6bddf4376240681f9cf6a2deded9498John Reck projectionTransform = &localTransformFromProjectionSurface; 430113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 4313f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik child->computeOrderingImpl(childOp, 4323f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik projectionOutline, projectionChildren, projectionTransform); 433113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 434113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 435113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 436113e0824d6bddf4376240681f9cf6a2deded9498John Reck 437113e0824d6bddf4376240681f9cf6a2deded9498John Reckclass DeferOperationHandler { 438113e0824d6bddf4376240681f9cf6a2deded9498John Reckpublic: 439113e0824d6bddf4376240681f9cf6a2deded9498John Reck DeferOperationHandler(DeferStateStruct& deferStruct, int level) 440113e0824d6bddf4376240681f9cf6a2deded9498John Reck : mDeferStruct(deferStruct), mLevel(level) {} 441113e0824d6bddf4376240681f9cf6a2deded9498John Reck inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { 442113e0824d6bddf4376240681f9cf6a2deded9498John Reck operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds); 443113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 444113e0824d6bddf4376240681f9cf6a2deded9498John Reck inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); } 445b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline void startMark(const char* name) {} // do nothing 446b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline void endMark() {} 447b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline int level() { return mLevel; } 448b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline int replayFlags() { return mDeferStruct.mReplayFlags; } 449113e0824d6bddf4376240681f9cf6a2deded9498John Reck 450113e0824d6bddf4376240681f9cf6a2deded9498John Reckprivate: 451113e0824d6bddf4376240681f9cf6a2deded9498John Reck DeferStateStruct& mDeferStruct; 452113e0824d6bddf4376240681f9cf6a2deded9498John Reck const int mLevel; 453113e0824d6bddf4376240681f9cf6a2deded9498John Reck}; 454113e0824d6bddf4376240681f9cf6a2deded9498John Reck 455b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::deferNodeTree(DeferStateStruct& deferStruct) { 456b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik DeferOperationHandler handler(deferStruct, 0); 457cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik if (MathUtils::isPositive(properties().getZ())) { 458cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik issueDrawShadowOperation(Matrix4::identity(), handler); 459cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik } 460b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler); 461b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik} 462b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 463b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::deferNodeInParent(DeferStateStruct& deferStruct, const int level) { 464113e0824d6bddf4376240681f9cf6a2deded9498John Reck DeferOperationHandler handler(deferStruct, level); 465b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler); 466113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 467113e0824d6bddf4376240681f9cf6a2deded9498John Reck 468113e0824d6bddf4376240681f9cf6a2deded9498John Reckclass ReplayOperationHandler { 469113e0824d6bddf4376240681f9cf6a2deded9498John Reckpublic: 470113e0824d6bddf4376240681f9cf6a2deded9498John Reck ReplayOperationHandler(ReplayStateStruct& replayStruct, int level) 471113e0824d6bddf4376240681f9cf6a2deded9498John Reck : mReplayStruct(replayStruct), mLevel(level) {} 472113e0824d6bddf4376240681f9cf6a2deded9498John Reck inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { 473113e0824d6bddf4376240681f9cf6a2deded9498John Reck#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS 4743f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik mReplayStruct.mRenderer.eventMark(operation->name()); 475113e0824d6bddf4376240681f9cf6a2deded9498John Reck#endif 476113e0824d6bddf4376240681f9cf6a2deded9498John Reck operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds); 477113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 478113e0824d6bddf4376240681f9cf6a2deded9498John Reck inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); } 479b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline void startMark(const char* name) { 480b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik mReplayStruct.mRenderer.startMark(name); 481b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik } 482b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline void endMark() { 483b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik mReplayStruct.mRenderer.endMark(); 484b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik } 485b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline int level() { return mLevel; } 486b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik inline int replayFlags() { return mReplayStruct.mReplayFlags; } 487113e0824d6bddf4376240681f9cf6a2deded9498John Reck 488113e0824d6bddf4376240681f9cf6a2deded9498John Reckprivate: 489113e0824d6bddf4376240681f9cf6a2deded9498John Reck ReplayStateStruct& mReplayStruct; 490113e0824d6bddf4376240681f9cf6a2deded9498John Reck const int mLevel; 491113e0824d6bddf4376240681f9cf6a2deded9498John Reck}; 492113e0824d6bddf4376240681f9cf6a2deded9498John Reck 493b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::replayNodeTree(ReplayStateStruct& replayStruct) { 494b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik ReplayOperationHandler handler(replayStruct, 0); 495cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik if (MathUtils::isPositive(properties().getZ())) { 496cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik issueDrawShadowOperation(Matrix4::identity(), handler); 497cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik } 498b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler); 499b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik} 500113e0824d6bddf4376240681f9cf6a2deded9498John Reck 501b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::replayNodeInParent(ReplayStateStruct& replayStruct, const int level) { 502b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik ReplayOperationHandler handler(replayStruct, level); 503b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler); 504113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 505113e0824d6bddf4376240681f9cf6a2deded9498John Reck 506113e0824d6bddf4376240681f9cf6a2deded9498John Reckvoid RenderNode::buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes) { 507087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return; 508113e0824d6bddf4376240681f9cf6a2deded9498John Reck 509087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { 510087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck DrawDisplayListOp* childOp = mDisplayListData->children()[i]; 511113e0824d6bddf4376240681f9cf6a2deded9498John Reck RenderNode* child = childOp->mDisplayList; 512cc39e16cb98855f35079941b5e7e6eac2b7bc388Chris Craik float childZ = child->properties().getZ(); 513113e0824d6bddf4376240681f9cf6a2deded9498John Reck 514e0bb87d4bdbd3b08ab6a8569c8e564ed59b8a5a7Chris Craik if (!MathUtils::isZero(childZ)) { 515113e0824d6bddf4376240681f9cf6a2deded9498John Reck zTranslatedNodes.add(ZDrawDisplayListOpPair(childZ, childOp)); 516113e0824d6bddf4376240681f9cf6a2deded9498John Reck childOp->mSkipInOrderDraw = true; 517d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck } else if (!child->properties().getProjectBackwards()) { 518113e0824d6bddf4376240681f9cf6a2deded9498John Reck // regular, in order drawing DisplayList 519113e0824d6bddf4376240681f9cf6a2deded9498John Reck childOp->mSkipInOrderDraw = false; 520113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 521113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 522113e0824d6bddf4376240681f9cf6a2deded9498John Reck 523113e0824d6bddf4376240681f9cf6a2deded9498John Reck // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order) 524113e0824d6bddf4376240681f9cf6a2deded9498John Reck std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end()); 525113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 526113e0824d6bddf4376240681f9cf6a2deded9498John Reck 527b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craiktemplate <class T> 528b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) { 52961317325b7b4b4ffafd9400ab5966e8d7c67df2eChris Craik if (properties().getAlpha() <= 0.0f || properties().getOutline().isEmpty()) return; 530b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 531b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik mat4 shadowMatrixXY(transformFromParent); 532b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik applyViewPropertyTransforms(shadowMatrixXY); 533b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 534b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik // Z matrix needs actual 3d transformation, so mapped z values will be correct 535b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik mat4 shadowMatrixZ(transformFromParent); 536b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik applyViewPropertyTransforms(shadowMatrixZ, true); 537b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 538b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik const SkPath* outlinePath = properties().getOutline().getPath(); 539b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik const RevealClip& revealClip = properties().getRevealClip(); 540b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik const SkPath* revealClipPath = revealClip.hasConvexClip() 541b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik ? revealClip.getPath() : NULL; // only pass the reveal clip's path if it's convex 542b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 54361317325b7b4b4ffafd9400ab5966e8d7c67df2eChris Craik if (revealClipPath && revealClipPath->isEmpty()) return; 54461317325b7b4b4ffafd9400ab5966e8d7c67df2eChris Craik 545b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik /** 546b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik * The drawing area of the caster is always the same as the its perimeter (which 547b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik * the shadow system uses) *except* in the inverse clip case. Inform the shadow 548b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik * system that the caster's drawing area (as opposed to its perimeter) has been 549b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik * clipped, so that it knows the caster can't be opaque. 550b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik */ 551b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik bool casterUnclipped = !revealClip.willClip() || revealClip.hasConvexClip(); 552b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 553b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp( 554b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik shadowMatrixXY, shadowMatrixZ, 555b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik properties().getAlpha(), casterUnclipped, 556b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik outlinePath, revealClipPath); 557b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); 558b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik} 559b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 560113e0824d6bddf4376240681f9cf6a2deded9498John Reck#define SHADOW_DELTA 0.1f 561113e0824d6bddf4376240681f9cf6a2deded9498John Reck 562113e0824d6bddf4376240681f9cf6a2deded9498John Recktemplate <class T> 563b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes, 564113e0824d6bddf4376240681f9cf6a2deded9498John Reck ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) { 565113e0824d6bddf4376240681f9cf6a2deded9498John Reck const int size = zTranslatedNodes.size(); 566113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (size == 0 567113e0824d6bddf4376240681f9cf6a2deded9498John Reck || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f) 568113e0824d6bddf4376240681f9cf6a2deded9498John Reck || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) { 569113e0824d6bddf4376240681f9cf6a2deded9498John Reck // no 3d children to draw 570113e0824d6bddf4376240681f9cf6a2deded9498John Reck return; 571113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 572113e0824d6bddf4376240681f9cf6a2deded9498John Reck 573113e0824d6bddf4376240681f9cf6a2deded9498John Reck /** 574113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters 575113e0824d6bddf4376240681f9cf6a2deded9498John Reck * with very similar Z heights to draw together. 576113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 577113e0824d6bddf4376240681f9cf6a2deded9498John Reck * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are 578113e0824d6bddf4376240681f9cf6a2deded9498John Reck * underneath both, and neither's shadow is drawn on top of the other. 579113e0824d6bddf4376240681f9cf6a2deded9498John Reck */ 580113e0824d6bddf4376240681f9cf6a2deded9498John Reck const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes); 581113e0824d6bddf4376240681f9cf6a2deded9498John Reck size_t drawIndex, shadowIndex, endIndex; 582113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (mode == kNegativeZChildren) { 583113e0824d6bddf4376240681f9cf6a2deded9498John Reck drawIndex = 0; 584113e0824d6bddf4376240681f9cf6a2deded9498John Reck endIndex = nonNegativeIndex; 585113e0824d6bddf4376240681f9cf6a2deded9498John Reck shadowIndex = endIndex; // draw no shadows 586113e0824d6bddf4376240681f9cf6a2deded9498John Reck } else { 587113e0824d6bddf4376240681f9cf6a2deded9498John Reck drawIndex = nonNegativeIndex; 588113e0824d6bddf4376240681f9cf6a2deded9498John Reck endIndex = size; 589113e0824d6bddf4376240681f9cf6a2deded9498John Reck shadowIndex = drawIndex; // potentially draw shadow for each pos Z child 590113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 5913f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 5923f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "", 5933f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive"); 5943f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 595113e0824d6bddf4376240681f9cf6a2deded9498John Reck float lastCasterZ = 0.0f; 596113e0824d6bddf4376240681f9cf6a2deded9498John Reck while (shadowIndex < endIndex || drawIndex < endIndex) { 597113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (shadowIndex < endIndex) { 598113e0824d6bddf4376240681f9cf6a2deded9498John Reck DrawDisplayListOp* casterOp = zTranslatedNodes[shadowIndex].value; 599113e0824d6bddf4376240681f9cf6a2deded9498John Reck RenderNode* caster = casterOp->mDisplayList; 600113e0824d6bddf4376240681f9cf6a2deded9498John Reck const float casterZ = zTranslatedNodes[shadowIndex].key; 601113e0824d6bddf4376240681f9cf6a2deded9498John Reck // attempt to render the shadow if the caster about to be drawn is its caster, 602113e0824d6bddf4376240681f9cf6a2deded9498John Reck // OR if its caster's Z value is similar to the previous potential caster 603113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) { 604b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler); 605113e0824d6bddf4376240681f9cf6a2deded9498John Reck 606113e0824d6bddf4376240681f9cf6a2deded9498John Reck lastCasterZ = casterZ; // must do this even if current caster not casting a shadow 607113e0824d6bddf4376240681f9cf6a2deded9498John Reck shadowIndex++; 608113e0824d6bddf4376240681f9cf6a2deded9498John Reck continue; 609113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 610113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 611113e0824d6bddf4376240681f9cf6a2deded9498John Reck 612113e0824d6bddf4376240681f9cf6a2deded9498John Reck // only the actual child DL draw needs to be in save/restore, 613113e0824d6bddf4376240681f9cf6a2deded9498John Reck // since it modifies the renderer's matrix 614113e0824d6bddf4376240681f9cf6a2deded9498John Reck int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag); 615113e0824d6bddf4376240681f9cf6a2deded9498John Reck 616113e0824d6bddf4376240681f9cf6a2deded9498John Reck DrawDisplayListOp* childOp = zTranslatedNodes[drawIndex].value; 617113e0824d6bddf4376240681f9cf6a2deded9498John Reck RenderNode* child = childOp->mDisplayList; 618113e0824d6bddf4376240681f9cf6a2deded9498John Reck 619113e0824d6bddf4376240681f9cf6a2deded9498John Reck renderer.concatMatrix(childOp->mTransformFromParent); 620113e0824d6bddf4376240681f9cf6a2deded9498John Reck childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone 621d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); 622113e0824d6bddf4376240681f9cf6a2deded9498John Reck childOp->mSkipInOrderDraw = true; 623113e0824d6bddf4376240681f9cf6a2deded9498John Reck 624113e0824d6bddf4376240681f9cf6a2deded9498John Reck renderer.restoreToCount(restoreTo); 625113e0824d6bddf4376240681f9cf6a2deded9498John Reck drawIndex++; 626113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 627113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 628113e0824d6bddf4376240681f9cf6a2deded9498John Reck 629113e0824d6bddf4376240681f9cf6a2deded9498John Recktemplate <class T> 630b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) { 6313f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size()); 6323f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPath* projectionReceiverOutline = properties().getOutline().getPath(); 6333f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik bool maskProjecteesWithPath = projectionReceiverOutline != NULL 6343f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik && !projectionReceiverOutline->isRect(NULL); 6353f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik int restoreTo = renderer.getSaveCount(); 6363f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 6373f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // If the projection reciever has an outline, we mask each of the projected rendernodes to it 6383f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // Either with clipRect, or special saveLayer masking 6393f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik LinearAllocator& alloc = handler.allocator(); 6403f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik if (projectionReceiverOutline != NULL) { 6413f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkRect& outlineBounds = projectionReceiverOutline->getBounds(); 6423f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik if (projectionReceiverOutline->isRect(NULL)) { 6433f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // mask to the rect outline simply with clipRect 6443f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), 6453f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik PROPERTY_SAVECOUNT, properties().getClipToBounds()); 6463f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik ClipRectOp* clipOp = new (alloc) ClipRectOp( 6473f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik outlineBounds.left(), outlineBounds.top(), 6483f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op); 6493f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); 6503f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik } else { 6513f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // wrap the projected RenderNodes with a SaveLayer that will mask to the outline 6523f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik SaveLayerOp* op = new (alloc) SaveLayerOp( 6533f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik outlineBounds.left(), outlineBounds.top(), 6543f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik outlineBounds.right(), outlineBounds.bottom(), 6553f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 255, SkCanvas::kARGB_ClipLayer_SaveFlag); 6563f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik op->setMask(projectionReceiverOutline); 6573f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); 6583f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 6593f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik /* TODO: add optimizations here to take advantage of placement/size of projected 6603f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik * children (which may shrink saveLayer area significantly). This is dependent on 6613f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik * passing actual drawing/dirtying bounds of projected content down to native. 6623f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik */ 6633f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik } 6643f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik } 6653f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 6663f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // draw projected nodes 667113e0824d6bddf4376240681f9cf6a2deded9498John Reck for (size_t i = 0; i < mProjectedNodes.size(); i++) { 668113e0824d6bddf4376240681f9cf6a2deded9498John Reck DrawDisplayListOp* childOp = mProjectedNodes[i]; 669113e0824d6bddf4376240681f9cf6a2deded9498John Reck 670113e0824d6bddf4376240681f9cf6a2deded9498John Reck // matrix save, concat, and restore can be done safely without allocating operations 671113e0824d6bddf4376240681f9cf6a2deded9498John Reck int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag); 672113e0824d6bddf4376240681f9cf6a2deded9498John Reck renderer.concatMatrix(childOp->mTransformFromCompositingAncestor); 673113e0824d6bddf4376240681f9cf6a2deded9498John Reck childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone 674d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); 675113e0824d6bddf4376240681f9cf6a2deded9498John Reck childOp->mSkipInOrderDraw = true; 676113e0824d6bddf4376240681f9cf6a2deded9498John Reck renderer.restoreToCount(restoreTo); 677113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 6783f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 6793f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik if (projectionReceiverOutline != NULL) { 6803f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik handler(new (alloc) RestoreToCountOp(restoreTo), 6813f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik PROPERTY_SAVECOUNT, properties().getClipToBounds()); 6823f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik } 683113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 684113e0824d6bddf4376240681f9cf6a2deded9498John Reck 685113e0824d6bddf4376240681f9cf6a2deded9498John Reck/** 686113e0824d6bddf4376240681f9cf6a2deded9498John Reck * This function serves both defer and replay modes, and will organize the displayList's component 687113e0824d6bddf4376240681f9cf6a2deded9498John Reck * operations for a single frame: 688113e0824d6bddf4376240681f9cf6a2deded9498John Reck * 689113e0824d6bddf4376240681f9cf6a2deded9498John Reck * Every 'simple' state operation that affects just the matrix and alpha (or other factors of 690113e0824d6bddf4376240681f9cf6a2deded9498John Reck * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom 691113e0824d6bddf4376240681f9cf6a2deded9498John Reck * defer logic) and operations in displayListOps are issued through the 'handler' which handles the 692113e0824d6bddf4376240681f9cf6a2deded9498John Reck * defer vs replay logic, per operation 693113e0824d6bddf4376240681f9cf6a2deded9498John Reck */ 694113e0824d6bddf4376240681f9cf6a2deded9498John Recktemplate <class T> 695b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craikvoid RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) { 696b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik const int level = handler.level(); 697d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck if (mDisplayListData->isEmpty() || properties().getAlpha() <= 0) { 6983f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName()); 699113e0824d6bddf4376240681f9cf6a2deded9498John Reck return; 700113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 701113e0824d6bddf4376240681f9cf6a2deded9498John Reck 7023f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik handler.startMark(getName()); 703b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 704113e0824d6bddf4376240681f9cf6a2deded9498John Reck#if DEBUG_DISPLAY_LIST 7053f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const Rect& clipRect = renderer.getLocalClipBounds(); 7063f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f", 7073f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik level * 2, "", this, getName(), 7083f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); 709113e0824d6bddf4376240681f9cf6a2deded9498John Reck#endif 710113e0824d6bddf4376240681f9cf6a2deded9498John Reck 711113e0824d6bddf4376240681f9cf6a2deded9498John Reck LinearAllocator& alloc = handler.allocator(); 712113e0824d6bddf4376240681f9cf6a2deded9498John Reck int restoreTo = renderer.getSaveCount(); 713113e0824d6bddf4376240681f9cf6a2deded9498John Reck handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), 714d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck PROPERTY_SAVECOUNT, properties().getClipToBounds()); 715113e0824d6bddf4376240681f9cf6a2deded9498John Reck 716113e0824d6bddf4376240681f9cf6a2deded9498John Reck DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "", 717113e0824d6bddf4376240681f9cf6a2deded9498John Reck SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo); 718113e0824d6bddf4376240681f9cf6a2deded9498John Reck 719b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik setViewProperties<T>(renderer, handler); 720113e0824d6bddf4376240681f9cf6a2deded9498John Reck 7218c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik bool quickRejected = properties().getClipToBounds() 7228c271ca63b62061fd22cfee78fd6a574b44476fdChris Craik && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight()); 723113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (!quickRejected) { 724deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik if (mProperties.getOutline().willClip()) { 725deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik renderer.setClippingOutline(alloc, &(mProperties.getOutline())); 726deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik } 727deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik 728113e0824d6bddf4376240681f9cf6a2deded9498John Reck Vector<ZDrawDisplayListOpPair> zTranslatedNodes; 729113e0824d6bddf4376240681f9cf6a2deded9498John Reck buildZSortedChildList(zTranslatedNodes); 730113e0824d6bddf4376240681f9cf6a2deded9498John Reck 731113e0824d6bddf4376240681f9cf6a2deded9498John Reck // for 3d root, draw children with negative z values 732b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler); 733113e0824d6bddf4376240681f9cf6a2deded9498John Reck 734113e0824d6bddf4376240681f9cf6a2deded9498John Reck DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); 735113e0824d6bddf4376240681f9cf6a2deded9498John Reck const int saveCountOffset = renderer.getSaveCount() - 1; 736113e0824d6bddf4376240681f9cf6a2deded9498John Reck const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex; 737113e0824d6bddf4376240681f9cf6a2deded9498John Reck for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) { 738113e0824d6bddf4376240681f9cf6a2deded9498John Reck DisplayListOp *op = mDisplayListData->displayListOps[i]; 739113e0824d6bddf4376240681f9cf6a2deded9498John Reck 740113e0824d6bddf4376240681f9cf6a2deded9498John Reck#if DEBUG_DISPLAY_LIST 741113e0824d6bddf4376240681f9cf6a2deded9498John Reck op->output(level + 1); 742113e0824d6bddf4376240681f9cf6a2deded9498John Reck#endif 743113e0824d6bddf4376240681f9cf6a2deded9498John Reck logBuffer.writeCommand(level, op->name()); 744d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck handler(op, saveCountOffset, properties().getClipToBounds()); 745113e0824d6bddf4376240681f9cf6a2deded9498John Reck 746113e0824d6bddf4376240681f9cf6a2deded9498John Reck if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) { 747b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik issueOperationsOfProjectedChildren(renderer, handler); 748113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 749113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 750113e0824d6bddf4376240681f9cf6a2deded9498John Reck 751113e0824d6bddf4376240681f9cf6a2deded9498John Reck // for 3d root, draw children with positive z values 752b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler); 753113e0824d6bddf4376240681f9cf6a2deded9498John Reck } 754113e0824d6bddf4376240681f9cf6a2deded9498John Reck 755113e0824d6bddf4376240681f9cf6a2deded9498John Reck DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo); 756113e0824d6bddf4376240681f9cf6a2deded9498John Reck handler(new (alloc) RestoreToCountOp(restoreTo), 757d0a0b2a3140bfb1819a116413ce9d81886697a07John Reck PROPERTY_SAVECOUNT, properties().getClipToBounds()); 758113e0824d6bddf4376240681f9cf6a2deded9498John Reck renderer.setOverrideLayerAlpha(1.0f); 759b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik 7603f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName()); 761b265e2ca50b6ceb2fd2987ef1f7d063b1bde19aeChris Craik handler.endMark(); 762113e0824d6bddf4376240681f9cf6a2deded9498John Reck} 763113e0824d6bddf4376240681f9cf6a2deded9498John Reck 764113e0824d6bddf4376240681f9cf6a2deded9498John Reck} /* namespace uirenderer */ 765113e0824d6bddf4376240681f9cf6a2deded9498John Reck} /* namespace android */ 766