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

Side by Side Diff: cc/ScrollbarLayerChromium.cpp

Issue 11122003: [cc] Rename all cc/ filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
« no previous file with comments | « cc/ScrollbarLayerChromium.h ('k') | cc/ShaderChromium.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #if USE(ACCELERATED_COMPOSITING)
8
9 #include "ScrollbarLayerChromium.h"
10
11 #include "base/basictypes.h"
12 #include "CCLayerTreeHost.h"
13 #include "CCScrollbarLayerImpl.h"
14 #include "CCTextureUpdateQueue.h"
15 #include "LayerPainterChromium.h"
16 #include "TraceEvent.h"
17 #include <public/WebRect.h>
18
19 using WebKit::WebRect;
20
21 namespace cc {
22
23 scoped_ptr<CCLayerImpl> ScrollbarLayerChromium::createCCLayerImpl()
24 {
25 return CCScrollbarLayerImpl::create(id()).PassAs<CCLayerImpl>();
26 }
27
28 scoped_refptr<ScrollbarLayerChromium> ScrollbarLayerChromium::create(PassOwnPtr< WebKit::WebScrollbar> scrollbar, WebKit::WebScrollbarThemePainter painter, PassO wnPtr<WebKit::WebScrollbarThemeGeometry> geometry, int scrollLayerId)
29 {
30 return make_scoped_refptr(new ScrollbarLayerChromium(scrollbar, painter, geo metry, scrollLayerId));
31 }
32
33 ScrollbarLayerChromium::ScrollbarLayerChromium(PassOwnPtr<WebKit::WebScrollbar> scrollbar, WebKit::WebScrollbarThemePainter painter, PassOwnPtr<WebKit::WebScrol lbarThemeGeometry> geometry, int scrollLayerId)
34 : m_scrollbar(scrollbar)
35 , m_painter(painter)
36 , m_geometry(geometry)
37 , m_scrollLayerId(scrollLayerId)
38 , m_textureFormat(GraphicsContext3D::INVALID_ENUM)
39 {
40 }
41
42 ScrollbarLayerChromium::~ScrollbarLayerChromium()
43 {
44 }
45
46 void ScrollbarLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
47 {
48 LayerChromium::pushPropertiesTo(layer);
49
50 CCScrollbarLayerImpl* scrollbarLayer = static_cast<CCScrollbarLayerImpl*>(la yer);
51
52 if (!scrollbarLayer->scrollbarGeometry())
53 scrollbarLayer->setScrollbarGeometry(CCScrollbarGeometryFixedThumb::crea te(adoptPtr(m_geometry->clone())));
54
55 scrollbarLayer->setScrollbarData(m_scrollbar.get());
56
57 if (m_backTrack && m_backTrack->texture()->haveBackingTexture())
58 scrollbarLayer->setBackTrackResourceId(m_backTrack->texture()->resourceI d());
59 else
60 scrollbarLayer->setBackTrackResourceId(0);
61
62 if (m_foreTrack && m_foreTrack->texture()->haveBackingTexture())
63 scrollbarLayer->setForeTrackResourceId(m_foreTrack->texture()->resourceI d());
64 else
65 scrollbarLayer->setForeTrackResourceId(0);
66
67 if (m_thumb && m_thumb->texture()->haveBackingTexture())
68 scrollbarLayer->setThumbResourceId(m_thumb->texture()->resourceId());
69 else
70 scrollbarLayer->setThumbResourceId(0);
71 }
72
73 ScrollbarLayerChromium* ScrollbarLayerChromium::toScrollbarLayerChromium()
74 {
75 return this;
76 }
77
78 class ScrollbarBackgroundPainter : public LayerPainterChromium {
79 public:
80 static PassOwnPtr<ScrollbarBackgroundPainter> create(WebKit::WebScrollbar* s crollbar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeo metry* geometry, WebKit::WebScrollbar::ScrollbarPart trackPart)
81 {
82 return adoptPtr(new ScrollbarBackgroundPainter(scrollbar, painter, geome try, trackPart));
83 }
84
85 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect &) OVERRIDE
86 {
87 WebKit::WebCanvas* canvas = skCanvas;
88 // The following is a simplification of ScrollbarThemeComposite::paint.
89 WebKit::WebRect contentWebRect(contentRect.x(), contentRect.y(), content Rect.width(), contentRect.height());
90 m_painter.paintScrollbarBackground(canvas, contentWebRect);
91
92 if (m_geometry->hasButtons(m_scrollbar)) {
93 WebRect backButtonStartPaintRect = m_geometry->backButtonStartRect(m _scrollbar);
94 m_painter.paintBackButtonStart(canvas, backButtonStartPaintRect);
95
96 WebRect backButtonEndPaintRect = m_geometry->backButtonEndRect(m_scr ollbar);
97 m_painter.paintBackButtonEnd(canvas, backButtonEndPaintRect);
98
99 WebRect forwardButtonStartPaintRect = m_geometry->forwardButtonStart Rect(m_scrollbar);
100 m_painter.paintForwardButtonStart(canvas, forwardButtonStartPaintRec t);
101
102 WebRect forwardButtonEndPaintRect = m_geometry->forwardButtonEndRect (m_scrollbar);
103 m_painter.paintForwardButtonEnd(canvas, forwardButtonEndPaintRect);
104 }
105
106 WebRect trackPaintRect = m_geometry->trackRect(m_scrollbar);
107 m_painter.paintTrackBackground(canvas, trackPaintRect);
108
109 bool thumbPresent = m_geometry->hasThumb(m_scrollbar);
110 if (thumbPresent) {
111 if (m_trackPart == WebKit::WebScrollbar::ForwardTrackPart)
112 m_painter.paintForwardTrackPart(canvas, trackPaintRect);
113 else
114 m_painter.paintBackTrackPart(canvas, trackPaintRect);
115 }
116
117 m_painter.paintTickmarks(canvas, trackPaintRect);
118 }
119 private:
120 ScrollbarBackgroundPainter(WebKit::WebScrollbar* scrollbar, WebKit::WebScrol lbarThemePainter painter, WebKit::WebScrollbarThemeGeometry* geometry, WebKit::W ebScrollbar::ScrollbarPart trackPart)
121 : m_scrollbar(scrollbar)
122 , m_painter(painter)
123 , m_geometry(geometry)
124 , m_trackPart(trackPart)
125 {
126 }
127
128 WebKit::WebScrollbar* m_scrollbar;
129 WebKit::WebScrollbarThemePainter m_painter;
130 WebKit::WebScrollbarThemeGeometry* m_geometry;
131 WebKit::WebScrollbar::ScrollbarPart m_trackPart;
132
133 DISALLOW_COPY_AND_ASSIGN(ScrollbarBackgroundPainter);
134 };
135
136 bool ScrollbarLayerChromium::needsContentsScale() const
137 {
138 return true;
139 }
140
141 IntSize ScrollbarLayerChromium::contentBounds() const
142 {
143 return IntSize(lroundf(bounds().width() * contentsScale()), lroundf(bounds() .height() * contentsScale()));
144 }
145
146 class ScrollbarThumbPainter : public LayerPainterChromium {
147 public:
148 static PassOwnPtr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry * geometry)
149 {
150 return adoptPtr(new ScrollbarThumbPainter(scrollbar, painter, geometry)) ;
151 }
152
153 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect & opaque) OVERRIDE
154 {
155 WebKit::WebCanvas* canvas = skCanvas;
156
157 // Consider the thumb to be at the origin when painting.
158 WebRect thumbRect = m_geometry->thumbRect(m_scrollbar);
159 thumbRect.x = 0;
160 thumbRect.y = 0;
161 m_painter.paintThumb(canvas, thumbRect);
162 }
163
164 private:
165 ScrollbarThumbPainter(WebKit::WebScrollbar* scrollbar, WebKit::WebScrollbarT hemePainter painter, WebKit::WebScrollbarThemeGeometry* geometry)
166 : m_scrollbar(scrollbar)
167 , m_painter(painter)
168 , m_geometry(geometry)
169 {
170 }
171
172 WebKit::WebScrollbar* m_scrollbar;
173 WebKit::WebScrollbarThemePainter m_painter;
174 WebKit::WebScrollbarThemeGeometry* m_geometry;
175
176 DISALLOW_COPY_AND_ASSIGN(ScrollbarThumbPainter);
177 };
178
179 void ScrollbarLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
180 {
181 if (!host || host != layerTreeHost()) {
182 m_backTrackUpdater.clear();
183 m_backTrack.clear();
184 m_thumbUpdater.clear();
185 m_thumb.clear();
186 }
187
188 LayerChromium::setLayerTreeHost(host);
189 }
190
191 void ScrollbarLayerChromium::createTextureUpdaterIfNeeded()
192 {
193 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
194
195 if (!m_backTrackUpdater)
196 m_backTrackUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(Scro llbarBackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(), W ebKit::WebScrollbar::BackTrackPart));
197 if (!m_backTrack)
198 m_backTrack = m_backTrackUpdater->createTexture(layerTreeHost()->content sTextureManager());
199
200 // Only create two-part track if we think the two parts could be different i n appearance.
201 if (m_scrollbar->isCustomScrollbar()) {
202 if (!m_foreTrackUpdater)
203 m_foreTrackUpdater = CachingBitmapCanvasLayerTextureUpdater::Create( ScrollbarBackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get( ), WebKit::WebScrollbar::ForwardTrackPart));
204 if (!m_foreTrack)
205 m_foreTrack = m_foreTrackUpdater->createTexture(layerTreeHost()->con tentsTextureManager());
206 }
207
208 if (!m_thumbUpdater)
209 m_thumbUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(Scrollba rThumbPainter::create(m_scrollbar.get(), m_painter, m_geometry.get()));
210 if (!m_thumb)
211 m_thumb = m_thumbUpdater->createTexture(layerTreeHost()->contentsTexture Manager());
212 }
213
214 void ScrollbarLayerChromium::updatePart(CachingBitmapCanvasLayerTextureUpdater* painter, LayerTextureUpdater::Texture* texture, const IntRect& rect, CCTextureUp dateQueue& queue, CCRenderingStats& stats)
215 {
216 // Skip painting and uploading if there are no invalidations and
217 // we already have valid texture data.
218 if (texture->texture()->haveBackingTexture()
219 && texture->texture()->size() == rect.size()
220 && m_updateRect.isEmpty())
221 return;
222
223 // We should always have enough memory for UI.
224 ASSERT(texture->texture()->canAcquireBackingTexture());
225 if (!texture->texture()->canAcquireBackingTexture())
226 return;
227
228 // Paint and upload the entire part.
229 float widthScale = static_cast<float>(contentBounds().width()) / bounds().wi dth();
230 float heightScale = static_cast<float>(contentBounds().height()) / bounds(). height();
231 IntRect paintedOpaqueRect;
232 painter->prepareToUpdate(rect, rect.size(), widthScale, heightScale, painted OpaqueRect, stats);
233 if (!painter->pixelsDidChange() && texture->texture()->haveBackingTexture()) {
234 TRACE_EVENT_INSTANT0("cc","ScrollbarLayerChromium::updatePart no texture upload needed");
235 return;
236 }
237
238 texture->prepareRect(rect, stats);
239
240 IntSize destOffset(0, 0);
241 TextureUploader::Parameters upload = { texture, rect, destOffset };
242 queue.appendFullUpload(upload);
243 }
244
245
246 void ScrollbarLayerChromium::setTexturePriorities(const CCPriorityCalculator&)
247 {
248 if (contentBounds().isEmpty())
249 return;
250
251 createTextureUpdaterIfNeeded();
252
253 bool drawsToRoot = !renderTarget()->parent();
254 if (m_backTrack) {
255 m_backTrack->texture()->setDimensions(contentBounds(), m_textureFormat);
256 m_backTrack->texture()->setRequestPriority(CCPriorityCalculator::uiPrior ity(drawsToRoot));
257 }
258 if (m_foreTrack) {
259 m_foreTrack->texture()->setDimensions(contentBounds(), m_textureFormat);
260 m_foreTrack->texture()->setRequestPriority(CCPriorityCalculator::uiPrior ity(drawsToRoot));
261 }
262 if (m_thumb) {
263 IntSize thumbSize = layerRectToContentRect(m_geometry->thumbRect(m_scrol lbar.get())).size();
264 m_thumb->texture()->setDimensions(thumbSize, m_textureFormat);
265 m_thumb->texture()->setRequestPriority(CCPriorityCalculator::uiPriority( drawsToRoot));
266 }
267 }
268
269 void ScrollbarLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusi onTracker*, CCRenderingStats& stats)
270 {
271 if (contentBounds().isEmpty())
272 return;
273
274 createTextureUpdaterIfNeeded();
275
276 IntPoint scrollbarOrigin(m_scrollbar->location().x, m_scrollbar->location(). y);
277 IntRect contentRect = layerRectToContentRect(WebKit::WebRect(scrollbarOrigin .x(), scrollbarOrigin.y(), bounds().width(), bounds().height()));
278 updatePart(m_backTrackUpdater.get(), m_backTrack.get(), contentRect, queue, stats);
279 if (m_foreTrack && m_foreTrackUpdater)
280 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que ue, stats);
281
282 // Consider the thumb to be at the origin when painting.
283 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get());
284 IntRect originThumbRect = layerRectToContentRect(WebKit::WebRect(0, 0, thumb Rect.width, thumbRect.height));
285 if (!originThumbRect.isEmpty())
286 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue, stats);
287 }
288
289 }
290 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« no previous file with comments | « cc/ScrollbarLayerChromium.h ('k') | cc/ShaderChromium.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698