Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright 2012, 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 #ifndef PicturePile_h
     27 #define PicturePile_h
     28 
     29 #include "IntRect.h"
     30 #include "IntSize.h"
     31 #include "PrerenderedInval.h"
     32 #include "SkBitmap.h"
     33 #include "SkRegion.h"
     34 #include "SkRefCnt.h"
     35 
     36 #include <wtf/PassRefPtr.h>
     37 #include <wtf/RefCounted.h>
     38 #include <wtf/ThreadSafeRefCounted.h>
     39 #include <wtf/Vector.h>
     40 
     41 #define USE_RECORDING_CONTEXT true
     42 #if USE_RECORDING_CONTEXT
     43 namespace WebCore {
     44 class Recording;
     45 }
     46 typedef WebCore::Recording Picture;
     47 #else
     48 class SkPicture;
     49 typedef SkPicture Picture;
     50 #endif
     51 
     52 class SkCanvas;
     53 
     54 namespace WebCore {
     55 
     56 class GraphicsContext;
     57 
     58 class PicturePainter {
     59 public:
     60     virtual void paintContents(GraphicsContext* gc, IntRect& dirty) = 0;
     61     virtual SkCanvas* createPrerenderCanvas(PrerenderedInval* prerendered)
     62     {
     63         return 0;
     64     }
     65     virtual ~PicturePainter() {}
     66 };
     67 
     68 class PictureContainer {
     69 public:
     70     Picture* picture;
     71     IntRect area;
     72     bool dirty;
     73     RefPtr<PrerenderedInval> prerendered;
     74     float maxZoomScale;
     75 
     76     PictureContainer(const IntRect& area)
     77         : picture(0)
     78         , area(area)
     79         , dirty(true)
     80         , maxZoomScale(1)
     81     {}
     82 
     83     PictureContainer(const PictureContainer& other);
     84     ~PictureContainer();
     85 };
     86 
     87 class PicturePile {
     88 public:
     89     PicturePile() {}
     90     PicturePile(const PicturePile& other);
     91 
     92     const IntSize& size() { return m_size; }
     93 
     94     void clearPrerenders();
     95 
     96     // used by PicturePileLayerContents
     97     void draw(SkCanvas* canvas);
     98 
     99     // Used by WebViewCore
    100     void invalidate(const IntRect& dirtyRect);
    101     void setSize(const IntSize& size);
    102     void updatePicturesIfNeeded(PicturePainter* painter);
    103     void reset();
    104     SkRegion& dirtyRegion() { return m_dirtyRegion; }
    105     PrerenderedInval* prerenderedInvalForArea(const IntRect& area);
    106 
    107     // UI-side methods used to check content, after construction/updates are complete
    108     float maxZoomScale() const;
    109     bool isEmpty() const;
    110 
    111 private:
    112     void applyWebkitInvals();
    113     void updatePicture(PicturePainter* painter, PictureContainer& container);
    114     Picture* recordPicture(PicturePainter* painter, PictureContainer& container);
    115     void appendToPile(const IntRect& inval, const IntRect& originalInval = IntRect());
    116     void drawWithClipRecursive(SkCanvas* canvas, int index);
    117     void drawPicture(SkCanvas* canvas, PictureContainer& pc);
    118 
    119     IntSize m_size;
    120     Vector<PictureContainer> m_pile;
    121     Vector<IntRect> m_webkitInvals;
    122     SkRegion m_dirtyRegion;
    123 };
    124 
    125 } // namespace android
    126 
    127 #endif // PicturePile_h
    128