Home | History | Annotate | Download | only in layers
      1 #define LOG_TAG "PictureLayerContent"
      2 #define LOG_NDEBUG 1
      3 
      4 #include "config.h"
      5 #include "PictureLayerContent.h"
      6 
      7 #include "AndroidLog.h"
      8 #include "InspectorCanvas.h"
      9 #include "SkPicture.h"
     10 
     11 namespace WebCore {
     12 
     13 PictureLayerContent::PictureLayerContent(SkPicture* picture)
     14     : m_picture(picture)
     15     , m_checkedContent(false)
     16     , m_hasText(true)
     17 {
     18     SkSafeRef(m_picture);
     19 }
     20 
     21 PictureLayerContent::PictureLayerContent(const PictureLayerContent& content)
     22     : m_picture(content.m_picture)
     23     , m_checkedContent(content.m_checkedContent)
     24     , m_hasText(content.m_hasText)
     25 {
     26     SkSafeRef(m_picture);
     27 }
     28 
     29 PictureLayerContent::~PictureLayerContent()
     30 {
     31     SkSafeUnref(m_picture);
     32 }
     33 
     34 int PictureLayerContent::width()
     35 {
     36     if (!m_picture)
     37         return 0;
     38     return m_picture->width();
     39 }
     40 
     41 int PictureLayerContent::height()
     42 {
     43     if (!m_picture)
     44         return 0;
     45     return m_picture->height();
     46 }
     47 
     48 void PictureLayerContent::checkForOptimisations()
     49 {
     50     if (!m_checkedContent)
     51         maxZoomScale(); // for now only check the maximum scale for painting
     52 }
     53 
     54 float PictureLayerContent::maxZoomScale()
     55 {
     56     if (m_checkedContent)
     57         return m_hasText ? 1e6 : 1.0;
     58 
     59     // Let's check if we have text or not. If we don't, we can limit
     60     // ourselves to scale 1!
     61     InspectorBounder inspectorBounder;
     62     InspectorCanvas checker(&inspectorBounder, m_picture);
     63     SkBitmap bitmap;
     64     bitmap.setConfig(SkBitmap::kARGB_8888_Config,
     65                      m_picture->width(),
     66                      m_picture->height());
     67     checker.setBitmapDevice(bitmap);
     68     checker.drawPicture(*m_picture);
     69     m_hasText = checker.hasText();
     70     if (!checker.hasContent()) {
     71         // no content to draw, discard picture so UI / tile generation
     72         // doesn't bother with it
     73         SkSafeUnref(m_picture);
     74         m_picture = 0;
     75     }
     76 
     77     m_checkedContent = true;
     78 
     79     return m_hasText ? 1e6 : 1.0;
     80 }
     81 
     82 void PictureLayerContent::draw(SkCanvas* canvas)
     83 {
     84     if (!m_picture)
     85         return;
     86 
     87     TRACE_METHOD();
     88     android::Mutex::Autolock lock(m_drawLock);
     89     SkRect r = SkRect::MakeWH(width(), height());
     90     canvas->clipRect(r);
     91     canvas->drawPicture(*m_picture);
     92 }
     93 
     94 void PictureLayerContent::serialize(SkWStream* stream)
     95 {
     96     if (!m_picture)
     97         return;
     98     m_picture->serialize(stream);
     99 }
    100 
    101 } // namespace WebCore
    102