Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 if (commitType == CommitGPUCanvasGPUCompositing) { | |
|
Justin Novosad
2016/10/12 21:11:12
Nit: Should use switch/case IMHO
xidachen
2016/10/13 01:39:24
Done.
| |
| 246 DEFINE_STATIC_LOCAL(CustomCountHistogram, | |
| 247 commitGPUCanvasGPUCompositingTimer, | |
| 248 ("Blink.Canvas.OffscreenCommit.GPUCanvasGPUCompositing", | |
| 249 0, 10000000, 50)); | |
|
Justin Novosad
2016/10/12 21:11:12
I think we should double the number of categories
xidachen
2016/10/13 01:39:24
Done.
| |
| 250 commitGPUCanvasGPUCompositingTimer.count(elapsedTime * 1000000.0); | |
| 251 } else if (commitType == CommitGPUCanvasSoftwareCompositing) { | |
| 252 DEFINE_STATIC_LOCAL( | |
| 253 CustomCountHistogram, commitGPUCanvasSoftwareCompositingTimer, | |
| 254 ("Blink.Canvas.OffscreenCommit.GPUCanvasSoftwareCompositing", 0, | |
| 255 10000000, 50)); | |
| 256 commitGPUCanvasSoftwareCompositingTimer.count(elapsedTime * 1000000.0); | |
| 257 } else if (commitType == CommitSoftwareCanvasGPUCompositing) { | |
| 258 DEFINE_STATIC_LOCAL( | |
| 259 CustomCountHistogram, commitSoftwareCanvasGPUCompositingTimer, | |
| 260 ("Blink.Canvas.OffscreenCommit.SoftwareCanvasGPUCompositing", 0, | |
| 261 10000000, 50)); | |
| 262 commitSoftwareCanvasGPUCompositingTimer.count(elapsedTime * 1000000.0); | |
| 263 } else { | |
| 264 DEFINE_STATIC_LOCAL( | |
| 265 CustomCountHistogram, commitSoftwareCanvasSoftwareCompositingTimer, | |
| 266 ("Blink.Canvas.OffscreenCommit.SoftwareCanvasSoftwareCompositing", 0, | |
| 267 10000000, 50)); | |
| 268 commitSoftwareCanvasSoftwareCompositingTimer.count(elapsedTime * 1000000.0); | |
| 269 } | |
| 270 | |
| 241 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure()); | 271 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure()); |
| 242 } | 272 } |
| 243 | 273 |
| 244 void OffscreenCanvasFrameDispatcherImpl::ReturnResources( | 274 void OffscreenCanvasFrameDispatcherImpl::ReturnResources( |
| 245 const cc::ReturnedResourceArray& resources) { | 275 const cc::ReturnedResourceArray& resources) { |
| 246 for (const auto& resource : resources) { | 276 for (const auto& resource : resources) { |
| 247 m_cachedImages.remove(resource.id); | 277 m_cachedImages.remove(resource.id); |
| 248 m_sharedBitmaps.remove(resource.id); | 278 m_sharedBitmaps.remove(resource.id); |
| 249 m_cachedTextureIds.remove(resource.id); | 279 m_cachedTextureIds.remove(resource.id); |
| 250 } | 280 } |
| 251 } | 281 } |
| 252 | 282 |
| 253 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( | 283 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( |
| 254 const sk_sp<SkImage>& image) { | 284 const sk_sp<SkImage>& image) { |
| 255 if (image && image->width() == m_width && image->height() == m_height) | 285 if (image && image->width() == m_width && image->height() == m_height) |
| 256 return true; | 286 return true; |
| 257 return false; | 287 return false; |
| 258 } | 288 } |
| 259 | 289 |
| 260 } // namespace blink | 290 } // namespace blink |
| OLD | NEW |