1 /* 2 * Copyright 2010, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "CachedPrefix.h" 27 28 #include "CachedLayer.h" 29 #include "FloatRect.h" 30 #include "LayerAndroid.h" 31 32 namespace android { 33 34 #if USE(ACCELERATED_COMPOSITING) 35 36 IntRect CachedLayer::adjustBounds(const LayerAndroid* root, 37 const IntRect& bounds) const 38 { 39 const LayerAndroid* aLayer = layer(root); 40 if (!aLayer) { 41 DBG_NAV_LOGD("no layer in root=%p uniqueId=%d", root, mUniqueId); 42 #if DUMP_NAV_CACHE 43 if (root) 44 mDebug.printRootLayerAndroid(root); 45 #endif 46 return bounds; 47 } 48 FloatRect temp = bounds; 49 const FloatPoint& position = aLayer->getPosition(); 50 temp.move(position.x(), position.y()); 51 const FloatPoint& translation = aLayer->translation(); 52 temp.move(translation.x(), translation.y()); 53 IntRect result = enclosingIntRect(temp); 54 DBG_NAV_LOGD("root=%p aLayer=%p [%d]" 55 " bounds=(%d,%d,w=%d,h=%d) pos=(%g,%g) trans=(%g,%g)" 56 " result=(%d,%d,w=%d,h=%d) offset=(%d,%d)", 57 root, aLayer, aLayer->uniqueId(), 58 bounds.x(), bounds.y(), bounds.width(), bounds.height(), 59 position.x(), position.y(), translation.x(), translation.y(), 60 result.x(), result.y(), result.width(), result.height(), 61 mOffset.x(), mOffset.y()); 62 result.move(-mOffset.x(), -mOffset.y()); 63 return result; 64 } 65 66 const LayerAndroid* CachedLayer::layer(const LayerAndroid* root) const 67 { 68 if (!root || mLayer) 69 return mLayer; 70 return mLayer = root->findById(mUniqueId); 71 } 72 73 // return bounds relative to enclosing layer as recorded when walking the dom 74 IntRect CachedLayer::localBounds(const IntRect& bounds) const 75 { 76 IntRect temp = bounds; 77 temp.move(-mOffset.x(), -mOffset.y()); 78 return temp; 79 } 80 81 SkPicture* CachedLayer::picture(const LayerAndroid* root) const 82 { 83 const LayerAndroid* aLayer = layer(root); 84 if (!aLayer) 85 return 0; 86 DBG_NAV_LOGD("root=%p aLayer=%p [%d] picture=%p", 87 root, aLayer, aLayer->uniqueId(), aLayer->picture()); 88 return aLayer->picture(); 89 } 90 91 #if DUMP_NAV_CACHE 92 93 CachedLayer* CachedLayer::Debug::base() const { 94 return (CachedLayer*) ((char*) this - OFFSETOF(CachedLayer, mDebug)); 95 } 96 97 void CachedLayer::Debug::print() const 98 { 99 CachedLayer* b = base(); 100 DUMP_NAV_LOGD(" // int mCachedNodeIndex=%d;", b->mCachedNodeIndex); 101 DUMP_NAV_LOGD(" LayerAndroid* mLayer=%p;", b->mLayer); 102 DUMP_NAV_LOGD(" int mOffset=(%d, %d);", b->mOffset.x(), b->mOffset.y()); 103 DUMP_NAV_LOGD(" int mUniqueId=%p;\n", b->mUniqueId); 104 } 105 106 #endif 107 108 #if DUMP_NAV_CACHE 109 110 int CachedLayer::Debug::spaces; 111 112 void CachedLayer::Debug::printLayerAndroid(const LayerAndroid* layer) 113 { 114 ++spaces; 115 SkRect bounds; 116 layer->bounds(&bounds); 117 DUMP_NAV_LOGX("%.*s layer=%p [%d] (%g,%g,%g,%g) picture=%p clipped=%s", 118 spaces, " ", layer, layer->uniqueId(), 119 bounds.fLeft, bounds.fTop, bounds.width(), bounds.height(), 120 layer->picture(), layer->m_haveClip ? "true" : "false"); 121 for (int i = 0; i < layer->countChildren(); i++) 122 printLayerAndroid(layer->getChild(i)); 123 --spaces; 124 } 125 126 void CachedLayer::Debug::printRootLayerAndroid(const LayerAndroid* layer) 127 { 128 spaces = 0; 129 printLayerAndroid(layer); 130 } 131 #endif 132 133 #endif // USE(ACCELERATED_COMPOSITING) 134 135 } 136 137