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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp

Issue 2411363002: Add timer to OffscreenCanvas's commit API (Closed)
Patch Set: forgot two breaks Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" 5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h"
6 6
7 #include "cc/output/compositor_frame.h" 7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/delegated_frame_data.h" 8 #include "cc/output/delegated_frame_data.h"
9 #include "cc/quads/render_pass.h" 9 #include "cc/quads/render_pass.h"
10 #include "cc/quads/shared_quad_state.h" 10 #include "cc/quads/shared_quad_state.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 resource.read_lock_fences_enabled = false; 145 resource.read_lock_fences_enabled = false;
146 resource.is_software = false; 146 resource.is_software = false;
147 147
148 // Hold ref to |image|, to keep it alive until the browser ReturnResources. 148 // Hold ref to |image|, to keep it alive until the browser ReturnResources.
149 // It guarantees that the resource is not re-used or deleted. 149 // It guarantees that the resource is not re-used or deleted.
150 m_cachedImages.add(m_nextResourceId, std::move(image)); 150 m_cachedImages.add(m_nextResourceId, std::move(image));
151 } 151 }
152 152
153 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame( 153 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame(
154 RefPtr<StaticBitmapImage> image, 154 RefPtr<StaticBitmapImage> image,
155 double commitStartTime,
155 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is 156 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is
156 called on SwiftShader. */) { 157 called on SwiftShader. */) {
157 if (!image) 158 if (!image)
158 return; 159 return;
159 if (!verifyImageSize(image->imageForCurrentFrame())) 160 if (!verifyImageSize(image->imageForCurrentFrame()))
160 return; 161 return;
161 cc::CompositorFrame frame; 162 cc::CompositorFrame frame;
162 // TODO(crbug.com/652931): update the device_scale_factor 163 // TODO(crbug.com/652931): update the device_scale_factor
163 frame.metadata.device_scale_factor = 1.0f; 164 frame.metadata.device_scale_factor = 1.0f;
164 frame.delegated_frame_data.reset(new cc::DelegatedFrameData); 165 frame.delegated_frame_data.reset(new cc::DelegatedFrameData);
(...skipping 10 matching lines...) Expand all
175 cc::TransferableResource resource; 176 cc::TransferableResource resource;
176 resource.id = m_nextResourceId; 177 resource.id = m_nextResourceId;
177 resource.format = cc::ResourceFormat::RGBA_8888; 178 resource.format = cc::ResourceFormat::RGBA_8888;
178 // TODO(crbug.com/645590): filter should respect the image-rendering CSS 179 // TODO(crbug.com/645590): filter should respect the image-rendering CSS
179 // property of associated canvas element. 180 // property of associated canvas element.
180 resource.filter = GL_LINEAR; 181 resource.filter = GL_LINEAR;
181 resource.size = gfx::Size(m_width, m_height); 182 resource.size = gfx::Size(m_width, m_height);
182 // TODO(crbug.com/646022): making this overlay-able. 183 // TODO(crbug.com/646022): making this overlay-able.
183 resource.is_overlay_candidate = false; 184 resource.is_overlay_candidate = false;
184 185
186 OffscreenCanvasCommitType commitType;
185 DEFINE_THREAD_SAFE_STATIC_LOCAL( 187 DEFINE_THREAD_SAFE_STATIC_LOCAL(
186 EnumerationHistogram, commitTypeHistogram, 188 EnumerationHistogram, commitTypeHistogram,
187 new EnumerationHistogram("OffscreenCanvas.CommitType", 189 new EnumerationHistogram("OffscreenCanvas.CommitType",
188 OffscreenCanvasCommitTypeCount)); 190 OffscreenCanvasCommitTypeCount));
189 if (image->isTextureBacked()) { 191 if (image->isTextureBacked()) {
190 if (Platform::current()->isGPUCompositingEnabled() && 192 if (Platform::current()->isGPUCompositingEnabled() &&
191 !isWebGLSoftwareRendering) { 193 !isWebGLSoftwareRendering) {
192 // Case 1: both canvas and compositor are gpu accelerated. 194 // Case 1: both canvas and compositor are gpu accelerated.
193 commitTypeHistogram.count(CommitGPUCanvasGPUCompositing); 195 commitType = CommitGPUCanvasGPUCompositing;
194 setTransferableResourceToStaticBitmapImage(resource, image); 196 setTransferableResourceToStaticBitmapImage(resource, image);
195 } else { 197 } else {
196 // Case 2: canvas is accelerated but --disable-gpu-compositing is 198 // Case 2: canvas is accelerated but --disable-gpu-compositing is
197 // specified, or WebGL's commit is called with SwiftShader. The latter 199 // specified, or WebGL's commit is called with SwiftShader. The latter
198 // case is indicated by 200 // case is indicated by
199 // WebGraphicsContext3DProvider::isSoftwareRendering. 201 // WebGraphicsContext3DProvider::isSoftwareRendering.
200 commitTypeHistogram.count(CommitGPUCanvasSoftwareCompositing); 202 commitType = CommitGPUCanvasSoftwareCompositing;
201 setTransferableResourceToSharedBitmap(resource, image); 203 setTransferableResourceToSharedBitmap(resource, image);
202 } 204 }
203 } else { 205 } else {
204 if (Platform::current()->isGPUCompositingEnabled() && 206 if (Platform::current()->isGPUCompositingEnabled() &&
205 !isWebGLSoftwareRendering) { 207 !isWebGLSoftwareRendering) {
206 // Case 3: canvas is not gpu-accelerated, but compositor is 208 // Case 3: canvas is not gpu-accelerated, but compositor is
207 commitTypeHistogram.count(CommitSoftwareCanvasGPUCompositing); 209 commitType = CommitSoftwareCanvasGPUCompositing;
208 setTransferableResourceToSharedGPUContext(resource, image); 210 setTransferableResourceToSharedGPUContext(resource, image);
209 } else { 211 } else {
210 // Case 4: both canvas and compositor are not gpu accelerated. 212 // Case 4: both canvas and compositor are not gpu accelerated.
211 commitTypeHistogram.count(CommitSoftwareCanvasSoftwareCompositing); 213 commitType = CommitSoftwareCanvasSoftwareCompositing;
212 setTransferableResourceToSharedBitmap(resource, image); 214 setTransferableResourceToSharedBitmap(resource, image);
213 } 215 }
214 } 216 }
217 commitTypeHistogram.count(commitType);
215 218
216 m_nextResourceId++; 219 m_nextResourceId++;
217 frame.delegated_frame_data->resource_list.push_back(std::move(resource)); 220 frame.delegated_frame_data->resource_list.push_back(std::move(resource));
218 221
219 cc::TextureDrawQuad* quad = 222 cc::TextureDrawQuad* quad =
220 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); 223 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>();
221 gfx::Size rectSize(m_width, m_height); 224 gfx::Size rectSize(m_width, m_height);
222 225
223 const bool needsBlending = true; 226 const bool needsBlending = true;
224 // TOOD(crbug.com/645993): this should be inherited from WebGL context's 227 // TOOD(crbug.com/645993): this should be inherited from WebGL context's
225 // creation settings. 228 // creation settings.
226 const bool premultipliedAlpha = true; 229 const bool premultipliedAlpha = true;
227 const gfx::PointF uvTopLeft(0.f, 0.f); 230 const gfx::PointF uvTopLeft(0.f, 0.f);
228 const gfx::PointF uvBottomRight(1.f, 1.f); 231 const gfx::PointF uvBottomRight(1.f, 1.f);
229 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f}; 232 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f};
230 const bool yflipped = false; 233 const bool yflipped = false;
231 // TODO(crbug.com/645994): this should be true when using style 234 // TODO(crbug.com/645994): this should be true when using style
232 // "image-rendering: pixelated". 235 // "image-rendering: pixelated".
233 const bool nearestNeighbor = false; 236 const bool nearestNeighbor = false;
234 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, 237 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id,
235 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight, 238 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight,
236 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor, 239 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor,
237 false); 240 false);
238 241
239 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); 242 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass));
240 243
244 double elapsedTime = WTF::monotonicallyIncreasingTime() - commitStartTime;
245 switch (commitType) {
246 case CommitGPUCanvasGPUCompositing:
247 if (isMainThread()) {
248 DEFINE_STATIC_LOCAL(
249 CustomCountHistogram, commitGPUCanvasGPUCompositingMainTimer,
250 ("Blink.Canvas.OffscreenCommit.GPUCanvasGPUCompositingMain", 0,
251 10000000, 50));
252 commitGPUCanvasGPUCompositingMainTimer.count(elapsedTime * 1000000.0);
253 } else {
254 DEFINE_STATIC_LOCAL(
255 CustomCountHistogram, commitGPUCanvasGPUCompositingWorkerTimer,
256 ("Blink.Canvas.OffscreenCommit.GPUCanvasGPUCompositingWorker", 0,
257 10000000, 50));
258 commitGPUCanvasGPUCompositingWorkerTimer.count(elapsedTime * 1000000.0);
259 }
260 break;
261 case CommitGPUCanvasSoftwareCompositing:
262 if (isMainThread()) {
263 DEFINE_STATIC_LOCAL(
264 CustomCountHistogram, commitGPUCanvasSoftwareCompositingMainTimer,
265 ("Blink.Canvas.OffscreenCommit.GPUCanvasSoftwareCompositingMain", 0,
266 10000000, 50));
267 commitGPUCanvasSoftwareCompositingMainTimer.count(elapsedTime *
268 1000000.0);
269 } else {
270 DEFINE_STATIC_LOCAL(
271 CustomCountHistogram, commitGPUCanvasSoftwareCompositingWorkerTimer,
272 ("Blink.Canvas.OffscreenCommit.GPUCanvasSoftwareCompositingWorker",
273 0, 10000000, 50));
274 commitGPUCanvasSoftwareCompositingWorkerTimer.count(elapsedTime *
275 1000000.0);
276 }
277 break;
278 case CommitSoftwareCanvasGPUCompositing:
279 if (isMainThread()) {
280 DEFINE_STATIC_LOCAL(
281 CustomCountHistogram, commitSoftwareCanvasGPUCompositingMainTimer,
282 ("Blink.Canvas.OffscreenCommit.SoftwareCanvasGPUCompositingMain", 0,
283 10000000, 50));
284 commitSoftwareCanvasGPUCompositingMainTimer.count(elapsedTime *
285 1000000.0);
286 } else {
287 DEFINE_STATIC_LOCAL(
288 CustomCountHistogram, commitSoftwareCanvasGPUCompositingWorkerTimer,
289 ("Blink.Canvas.OffscreenCommit.SoftwareCanvasGPUCompositingWorker",
290 0, 10000000, 50));
291 commitSoftwareCanvasGPUCompositingWorkerTimer.count(elapsedTime *
292 1000000.0);
293 }
294 break;
295 case CommitSoftwareCanvasSoftwareCompositing:
296 if (isMainThread()) {
297 DEFINE_STATIC_LOCAL(CustomCountHistogram,
298 commitSoftwareCanvasSoftwareCompositingMainTimer,
299 ("Blink.Canvas.OffscreenCommit."
300 "SoftwareCanvasSoftwareCompositingMain",
301 0, 10000000, 50));
302 commitSoftwareCanvasSoftwareCompositingMainTimer.count(elapsedTime *
303 1000000.0);
304 } else {
305 DEFINE_STATIC_LOCAL(CustomCountHistogram,
306 commitSoftwareCanvasSoftwareCompositingWorkerTimer,
307 ("Blink.Canvas.OffscreenCommit."
308 "SoftwareCanvasSoftwareCompositingWorker",
309 0, 10000000, 50));
310 commitSoftwareCanvasSoftwareCompositingWorkerTimer.count(elapsedTime *
311 1000000.0);
312 }
313 break;
314 case OffscreenCanvasCommitTypeCount:
315 NOTREACHED();
316 }
317
241 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure()); 318 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure());
242 } 319 }
243 320
244 void OffscreenCanvasFrameDispatcherImpl::ReturnResources( 321 void OffscreenCanvasFrameDispatcherImpl::ReturnResources(
245 const cc::ReturnedResourceArray& resources) { 322 const cc::ReturnedResourceArray& resources) {
246 for (const auto& resource : resources) { 323 for (const auto& resource : resources) {
247 m_cachedImages.remove(resource.id); 324 m_cachedImages.remove(resource.id);
248 m_sharedBitmaps.remove(resource.id); 325 m_sharedBitmaps.remove(resource.id);
249 m_cachedTextureIds.remove(resource.id); 326 m_cachedTextureIds.remove(resource.id);
250 } 327 }
251 } 328 }
252 329
253 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( 330 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(
254 const sk_sp<SkImage>& image) { 331 const sk_sp<SkImage>& image) {
255 if (image && image->width() == m_width && image->height() == m_height) 332 if (image && image->width() == m_width && image->height() == m_height)
256 return true; 333 return true;
257 return false; 334 return false;
258 } 335 }
259 336
260 } // namespace blink 337 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698