• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class SkPicture;
42 class SkCanvas;
43 
44 namespace WebCore {
45 
46 class GraphicsContext;
47 
48 class PicturePainter {
49 public:
50     virtual void paintContents(GraphicsContext* gc, IntRect& dirty) = 0;
createPrerenderCanvas(PrerenderedInval * prerendered)51     virtual SkCanvas* createPrerenderCanvas(PrerenderedInval* prerendered)
52     {
53         return 0;
54     }
~PicturePainter()55     virtual ~PicturePainter() {}
56 };
57 
58 class PictureContainer {
59 public:
60     SkPicture* picture;
61     IntRect area;
62     bool dirty;
63     RefPtr<PrerenderedInval> prerendered;
64 
PictureContainer(const IntRect & area)65     PictureContainer(const IntRect& area)
66         : picture(0)
67         , area(area)
68         , dirty(true)
69     {}
70 
PictureContainer(const PictureContainer & other)71     PictureContainer(const PictureContainer& other)
72         : picture(other.picture)
73         , area(other.area)
74         , dirty(other.dirty)
75         , prerendered(other.prerendered)
76     {
77         SkSafeRef(picture);
78     }
79 
~PictureContainer()80     ~PictureContainer()
81     {
82         SkSafeUnref(picture);
83     }
84 };
85 
86 class PicturePile {
87 public:
PicturePile()88     PicturePile() {}
89     PicturePile(const PicturePile& other);
90     PicturePile(SkPicture* picture);
91 
size()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();
dirtyRegion()104     SkRegion& dirtyRegion() { return m_dirtyRegion; }
105     PrerenderedInval* prerenderedInvalForArea(const IntRect& area);
106 
107 private:
108     void applyWebkitInvals();
109     void updatePicture(PicturePainter* painter, PictureContainer& container);
110     void appendToPile(const IntRect& inval, const IntRect& originalInval = IntRect());
111     void drawWithClipRecursive(SkCanvas* canvas, SkRegion& clipRegion, int index);
112 
113     IntSize m_size;
114     Vector<PictureContainer> m_pile;
115     Vector<IntRect> m_webkitInvals;
116     SkRegion m_dirtyRegion;
117 };
118 
119 } // namespace android
120 
121 #endif // PicturePile_h
122