Home | History | Annotate | Download | only in rendering
      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 #define LOG_TAG "TilesProfiler"
     27 #define LOG_NDEBUG 1
     28 
     29 #include "config.h"
     30 #include "TilesProfiler.h"
     31 
     32 #if USE(ACCELERATED_COMPOSITING)
     33 
     34 #include "AndroidLog.h"
     35 #include "Tile.h"
     36 #include "TilesManager.h"
     37 #include <wtf/CurrentTime.h>
     38 
     39 // Hard limit on amount of frames (and thus memory) profiling can take
     40 #define MAX_PROF_FRAMES 400
     41 #define INVAL_CODE -2
     42 
     43 namespace WebCore {
     44 TilesProfiler::TilesProfiler()
     45     : m_enabled(false)
     46 {
     47 }
     48 
     49 void TilesProfiler::start()
     50 {
     51     m_enabled = true;
     52     m_goodTiles = 0;
     53     m_badTiles = 0;
     54     m_records.clear();
     55     m_time = currentTimeMS();
     56     ALOGV("initializing tileprofiling");
     57 }
     58 
     59 float TilesProfiler::stop()
     60 {
     61     m_enabled = false;
     62     ALOGV("completed tile profiling, observed %d frames", m_records.size());
     63     return (1.0 * m_goodTiles) / (m_goodTiles + m_badTiles);
     64 }
     65 
     66 void TilesProfiler::clear()
     67 {
     68     ALOGV("clearing tile profiling of its %d frames", m_records.size());
     69     m_records.clear();
     70 }
     71 
     72 void TilesProfiler::nextFrame(int left, int top, int right, int bottom, float scale)
     73 {
     74     if (!m_enabled || (m_records.size() > MAX_PROF_FRAMES))
     75         return;
     76 
     77     double currentTime = currentTimeMS();
     78     double timeDelta = currentTime - m_time;
     79     m_time = currentTime;
     80 
     81 #ifdef DEBUG
     82     if (m_records.size() != 0) {
     83         ALOGD("completed tile profiling frame, observed %d tiles. %f ms since last",
     84               m_records[0].size(), timeDelta);
     85     }
     86 #endif // DEBUG
     87 
     88     m_records.append(WTF::Vector<TileProfileRecord>());
     89 
     90     //first record designates viewport
     91     m_records.last().append(TileProfileRecord(
     92                                 left, top, right, bottom,
     93                                 scale, true, (int)(timeDelta * 1000)));
     94 }
     95 
     96 void TilesProfiler::nextTile(Tile* tile, float scale, bool inView)
     97 {
     98     if (!m_enabled || (m_records.size() > MAX_PROF_FRAMES) || (m_records.size() == 0))
     99         return;
    100 
    101     bool isReady = tile->isTileReady();
    102     int left = tile->x() * TilesManager::tileWidth();
    103     int top = tile->y() * TilesManager::tileWidth();
    104     int right = left + TilesManager::tileWidth();
    105     int bottom = top + TilesManager::tileWidth();
    106 
    107     if (inView) {
    108         if (isReady)
    109             m_goodTiles++;
    110         else
    111             m_badTiles++;
    112     }
    113     m_records.last().append(TileProfileRecord(
    114                                 left, top, right, bottom,
    115                                 scale, isReady, (int)tile->drawCount()));
    116     ALOGV("adding tile %d %d %d %d, scale %f", left, top, right, bottom, scale);
    117 }
    118 
    119 void TilesProfiler::nextInval(const SkIRect& rect, float scale)
    120 {
    121     if (!m_enabled || (m_records.size() > MAX_PROF_FRAMES) || (m_records.size() == 0))
    122         return;
    123 
    124     m_records.last().append(TileProfileRecord(
    125                                 rect.x(), rect.y(),
    126                                 rect.right(), rect.bottom(), scale, false, INVAL_CODE));
    127     ALOGV("adding inval region %d %d %d %d, scale %f", rect.x(), rect.y(),
    128           rect.right(), rect.bottom(), scale);
    129 }
    130 
    131 } // namespace WebCore
    132 
    133 #endif // USE(ACCELERATED_COMPOSITING)
    134