| 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/quads/texture_draw_quad.h" | 8 #include "cc/quads/texture_draw_quad.h" |
| 9 #include "gpu/command_buffer/client/gles2_interface.h" | 9 #include "gpu/command_buffer/client/gles2_interface.h" |
| 10 #include "platform/Histogram.h" | 10 #include "platform/Histogram.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 double commitStartTime, | 150 double commitStartTime, |
| 151 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is | 151 bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is |
| 152 called on SwiftShader. */) { | 152 called on SwiftShader. */) { |
| 153 if (!image) | 153 if (!image) |
| 154 return; | 154 return; |
| 155 if (!verifyImageSize(image->imageForCurrentFrame())) | 155 if (!verifyImageSize(image->imageForCurrentFrame())) |
| 156 return; | 156 return; |
| 157 cc::CompositorFrame frame; | 157 cc::CompositorFrame frame; |
| 158 // TODO(crbug.com/652931): update the device_scale_factor | 158 // TODO(crbug.com/652931): update the device_scale_factor |
| 159 frame.metadata.device_scale_factor = 1.0f; | 159 frame.metadata.device_scale_factor = 1.0f; |
| 160 frame.delegated_frame_data.reset(new cc::DelegatedFrameData); | |
| 161 | 160 |
| 162 const gfx::Rect bounds(m_width, m_height); | 161 const gfx::Rect bounds(m_width, m_height); |
| 163 const cc::RenderPassId renderPassId(1, 1); | 162 const cc::RenderPassId renderPassId(1, 1); |
| 164 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); | 163 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); |
| 165 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); | 164 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); |
| 166 | 165 |
| 167 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 166 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 168 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, | 167 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, |
| 169 SkXfermode::kSrcOver_Mode, 0); | 168 SkXfermode::kSrcOver_Mode, 0); |
| 170 | 169 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 setTransferableResourceToSharedGPUContext(resource, image); | 206 setTransferableResourceToSharedGPUContext(resource, image); |
| 208 } else { | 207 } else { |
| 209 // Case 4: both canvas and compositor are not gpu accelerated. | 208 // Case 4: both canvas and compositor are not gpu accelerated. |
| 210 commitType = CommitSoftwareCanvasSoftwareCompositing; | 209 commitType = CommitSoftwareCanvasSoftwareCompositing; |
| 211 setTransferableResourceToSharedBitmap(resource, image); | 210 setTransferableResourceToSharedBitmap(resource, image); |
| 212 } | 211 } |
| 213 } | 212 } |
| 214 commitTypeHistogram.count(commitType); | 213 commitTypeHistogram.count(commitType); |
| 215 | 214 |
| 216 m_nextResourceId++; | 215 m_nextResourceId++; |
| 217 frame.delegated_frame_data->resource_list.push_back(std::move(resource)); | 216 frame.resource_list.push_back(std::move(resource)); |
| 218 | 217 |
| 219 cc::TextureDrawQuad* quad = | 218 cc::TextureDrawQuad* quad = |
| 220 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); | 219 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); |
| 221 gfx::Size rectSize(m_width, m_height); | 220 gfx::Size rectSize(m_width, m_height); |
| 222 | 221 |
| 223 const bool needsBlending = true; | 222 const bool needsBlending = true; |
| 224 // TOOD(crbug.com/645993): this should be inherited from WebGL context's | 223 // TOOD(crbug.com/645993): this should be inherited from WebGL context's |
| 225 // creation settings. | 224 // creation settings. |
| 226 const bool premultipliedAlpha = true; | 225 const bool premultipliedAlpha = true; |
| 227 const gfx::PointF uvTopLeft(0.f, 0.f); | 226 const gfx::PointF uvTopLeft(0.f, 0.f); |
| 228 const gfx::PointF uvBottomRight(1.f, 1.f); | 227 const gfx::PointF uvBottomRight(1.f, 1.f); |
| 229 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f}; | 228 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f}; |
| 230 // TODO(crbug.com/645994): this should be true when using style | 229 // TODO(crbug.com/645994): this should be true when using style |
| 231 // "image-rendering: pixelated". | 230 // "image-rendering: pixelated". |
| 232 const bool nearestNeighbor = false; | 231 const bool nearestNeighbor = false; |
| 233 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, | 232 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, |
| 234 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight, | 233 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight, |
| 235 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor, | 234 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor, |
| 236 false); | 235 false); |
| 237 | 236 |
| 238 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 237 frame.render_pass_list.push_back(std::move(pass)); |
| 239 | 238 |
| 240 double elapsedTime = WTF::monotonicallyIncreasingTime() - commitStartTime; | 239 double elapsedTime = WTF::monotonicallyIncreasingTime() - commitStartTime; |
| 241 switch (commitType) { | 240 switch (commitType) { |
| 242 case CommitGPUCanvasGPUCompositing: | 241 case CommitGPUCanvasGPUCompositing: |
| 243 if (isMainThread()) { | 242 if (isMainThread()) { |
| 244 DEFINE_STATIC_LOCAL( | 243 DEFINE_STATIC_LOCAL( |
| 245 CustomCountHistogram, commitGPUCanvasGPUCompositingMainTimer, | 244 CustomCountHistogram, commitGPUCanvasGPUCompositingMainTimer, |
| 246 ("Blink.Canvas.OffscreenCommit.GPUCanvasGPUCompositingMain", 0, | 245 ("Blink.Canvas.OffscreenCommit.GPUCanvasGPUCompositingMain", 0, |
| 247 10000000, 50)); | 246 10000000, 50)); |
| 248 commitGPUCanvasGPUCompositingMainTimer.count(elapsedTime * 1000000.0); | 247 commitGPUCanvasGPUCompositingMainTimer.count(elapsedTime * 1000000.0); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 327 } |
| 329 | 328 |
| 330 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( | 329 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( |
| 331 const sk_sp<SkImage>& image) { | 330 const sk_sp<SkImage>& image) { |
| 332 if (image && image->width() == m_width && image->height() == m_height) | 331 if (image && image->width() == m_width && image->height() == m_height) |
| 333 return true; | 332 return true; |
| 334 return false; | 333 return false; |
| 335 } | 334 } |
| 336 | 335 |
| 337 } // namespace blink | 336 } // namespace blink |
| OLD | NEW |