Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: Source/platform/graphics/RecordingImageBufferSurface.cpp

Issue 379253002: Initial implementation of display list backed 2D canvases (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: compile error fix Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #include "platform/graphics/RecordingImageBufferSurface.h"
34
35 #include "platform/graphics/GraphicsContext.h"
36 #include "platform/graphics/ImageBuffer.h"
37 #include "third_party/skia/include/core/SkCanvas.h"
38 #include "third_party/skia/include/core/SkPictureRecorder.h"
39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/PassRefPtr.h"
41
42 namespace WebCore {
43
44 RecordingImageBufferSurface::RecordingImageBufferSurface(const IntSize& size, Op acityMode opacityMode)
45 : ImageBufferSurface(size, opacityMode)
46 , m_imageBuffer(0)
Stephen White 2014/07/09 20:04:08 You only ever seem to use m_imageBuffer->context()
Justin Novosad 2014/07/11 21:16:08 Technically that would be just as circular IMHO (a
Stephen White 2014/07/14 15:19:15 I realize that, but this class only needs the Grap
47 , m_frameWasCleared(true)
48 {
49 initializeCurrentFrame();
50 }
51
52 RecordingImageBufferSurface::~RecordingImageBufferSurface()
53 { }
54
55 void RecordingImageBufferSurface::initializeCurrentFrame()
56 {
57 static SkRTreeFactory rTreeFactory;
58 m_currentFrame = adoptPtr(new SkPictureRecorder);
59 m_currentFrame->beginRecording(size().width(), size().height(), &rTreeFactor y);
60 if (m_imageBuffer) {
61 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas ());
62 m_imageBuffer->context()->setTrackOpaqueRegion(true);
dshwang 2014/07/10 13:01:52 how much overhead when we turn on TrackOpaqueRegio
Justin Novosad 2014/07/11 21:16:08 It is low overhead. This method only tracks simple
63 }
64 }
65
66 void RecordingImageBufferSurface::setImageBuffer(ImageBuffer* imageBuffer)
67 {
68 m_imageBuffer = imageBuffer;
69 if (m_currentFrame) {
70 m_imageBuffer->context()->setTrackOpaqueRegion(true);
71 m_imageBuffer->context()->resetCanvas(m_currentFrame->getRecordingCanvas ());
72 }
73 }
74
75
76 void RecordingImageBufferSurface::willReadback()
77 {
78 fallbackToRasterCanvas();
79 }
80
81 void RecordingImageBufferSurface::fallbackToRasterCanvas()
82 {
83 if (m_rasterCanvas)
84 return;
85
86 m_rasterCanvas = adoptPtr(SkCanvas::NewRasterN32(size().width(), size().heig ht()));
87
88 if (m_previousFrame) {
89 m_previousFrame->draw(m_rasterCanvas.get());
90 m_previousFrame.clear();
91 }
92 if (m_currentFrame) {
93 RefPtr<SkPicture> currentPicture = adoptRef(m_currentFrame->endRecording ());
94 currentPicture->draw(m_rasterCanvas.get());
95 m_currentFrame.clear();
96 }
97
98 if (m_imageBuffer) {
99 m_imageBuffer->context()->setTrackOpaqueRegion(false);
100 m_imageBuffer->context()->resetCanvas(m_rasterCanvas.get());
101 }
102 }
103
104 SkCanvas* RecordingImageBufferSurface::canvas() const
105 {
106 if (m_rasterCanvas)
107 return m_rasterCanvas.get();
108
109 ASSERT(m_currentFrame->getRecordingCanvas());
110 return m_currentFrame->getRecordingCanvas();
111 }
112
113 PassRefPtr<SkPicture> RecordingImageBufferSurface::getPicture()
114 {
dshwang 2014/07/10 13:01:52 Following code might be needed, because we cannot
Justin Novosad 2014/07/11 21:16:08 Your logic is correct, but the check is not needed
115 if (handleOpaqueFrame())
116 return m_previousFrame;
Stephen White 2014/07/09 20:04:08 As discussed, it would be nice to handle the case
Justin Novosad 2014/07/11 21:16:08 Agreed. I filed a bug about this so we can deal wi
117
118 if (!m_rasterCanvas)
119 fallbackToRasterCanvas();
120 return nullptr;
121 }
122
123 void RecordingImageBufferSurface::didClearCanvas()
124 {
125 m_frameWasCleared = true;
126 }
127
128 bool RecordingImageBufferSurface::handleOpaqueFrame()
129 {
130 if (!m_currentFrame)
131 return false;
132 IntRect canvasRect(IntPoint(0, 0), size());
133 if (!m_frameWasCleared && !m_imageBuffer->context()->opaqueRegion().asRect() .contains(canvasRect))
134 return false;
135
136 SkCanvas* oldCanvas = m_currentFrame->getRecordingCanvas(); // Could be rast er or picture
137
138 // TODO: handle transferring complex state from the current
Stephen White 2014/07/09 20:04:08 Pls add a bug for this.
Justin Novosad 2014/07/11 21:16:08 Done.
139 // picture to the new one.
140 if (oldCanvas->getSaveCount())
141 return false;
142 if (!oldCanvas->isClipRect())
Stephen White 2014/07/09 20:04:08 You should probably also check that the clip op is
Justin Novosad 2014/07/11 21:16:08 Already covered by isClipRect. IsClipRect checks w
Stephen White 2014/07/14 15:19:15 Acknowledged.
143 return false;
144
145 SkMatrix ctm = oldCanvas->getTotalMatrix();
146 SkRect clip;
147 oldCanvas->getClipBounds(&clip);
148
149 m_previousFrame = adoptRef(m_currentFrame->endRecording());
150 initializeCurrentFrame();
151
152 SkCanvas* newCanvas = m_currentFrame->getRecordingCanvas();
153 newCanvas->concat(ctm);
154 newCanvas->clipRect(clip);
155
156 m_frameWasCleared = false;
157 return true;
158 }
159
160 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698