| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 cc::TransferableResource resource; | 176 cc::TransferableResource resource; |
| 177 resource.id = m_nextResourceId; | 177 resource.id = m_nextResourceId; |
| 178 resource.format = cc::ResourceFormat::RGBA_8888; | 178 resource.format = cc::ResourceFormat::RGBA_8888; |
| 179 // TODO(crbug.com/645590): filter should respect the image-rendering CSS | 179 // TODO(crbug.com/645590): filter should respect the image-rendering CSS |
| 180 // property of associated canvas element. | 180 // property of associated canvas element. |
| 181 resource.filter = GL_LINEAR; | 181 resource.filter = GL_LINEAR; |
| 182 resource.size = gfx::Size(m_width, m_height); | 182 resource.size = gfx::Size(m_width, m_height); |
| 183 // TODO(crbug.com/646022): making this overlay-able. | 183 // TODO(crbug.com/646022): making this overlay-able. |
| 184 resource.is_overlay_candidate = false; | 184 resource.is_overlay_candidate = false; |
| 185 | 185 |
| 186 bool yflipped = false; |
| 186 OffscreenCanvasCommitType commitType; | 187 OffscreenCanvasCommitType commitType; |
| 187 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 188 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 188 EnumerationHistogram, commitTypeHistogram, | 189 EnumerationHistogram, commitTypeHistogram, |
| 189 new EnumerationHistogram("OffscreenCanvas.CommitType", | 190 new EnumerationHistogram("OffscreenCanvas.CommitType", |
| 190 OffscreenCanvasCommitTypeCount)); | 191 OffscreenCanvasCommitTypeCount)); |
| 191 if (image->isTextureBacked()) { | 192 if (image->isTextureBacked()) { |
| 192 if (Platform::current()->isGPUCompositingEnabled() && | 193 if (Platform::current()->isGPUCompositingEnabled() && |
| 193 !isWebGLSoftwareRendering) { | 194 !isWebGLSoftwareRendering) { |
| 194 // Case 1: both canvas and compositor are gpu accelerated. | 195 // Case 1: both canvas and compositor are gpu accelerated. |
| 195 commitType = CommitGPUCanvasGPUCompositing; | 196 commitType = CommitGPUCanvasGPUCompositing; |
| 196 setTransferableResourceToStaticBitmapImage(resource, image); | 197 setTransferableResourceToStaticBitmapImage(resource, image); |
| 198 yflipped = true; |
| 197 } else { | 199 } else { |
| 198 // Case 2: canvas is accelerated but --disable-gpu-compositing is | 200 // Case 2: canvas is accelerated but --disable-gpu-compositing is |
| 199 // specified, or WebGL's commit is called with SwiftShader. The latter | 201 // specified, or WebGL's commit is called with SwiftShader. The latter |
| 200 // case is indicated by | 202 // case is indicated by |
| 201 // WebGraphicsContext3DProvider::isSoftwareRendering. | 203 // WebGraphicsContext3DProvider::isSoftwareRendering. |
| 202 commitType = CommitGPUCanvasSoftwareCompositing; | 204 commitType = CommitGPUCanvasSoftwareCompositing; |
| 203 setTransferableResourceToSharedBitmap(resource, image); | 205 setTransferableResourceToSharedBitmap(resource, image); |
| 204 } | 206 } |
| 205 } else { | 207 } else { |
| 206 if (Platform::current()->isGPUCompositingEnabled() && | 208 if (Platform::current()->isGPUCompositingEnabled() && |
| 207 !isWebGLSoftwareRendering) { | 209 !isWebGLSoftwareRendering) { |
| 208 // Case 3: canvas is not gpu-accelerated, but compositor is | 210 // Case 3: canvas is not gpu-accelerated, but compositor is |
| 209 commitType = CommitSoftwareCanvasGPUCompositing; | 211 commitType = CommitSoftwareCanvasGPUCompositing; |
| 210 setTransferableResourceToSharedGPUContext(resource, image); | 212 setTransferableResourceToSharedGPUContext(resource, image); |
| 213 yflipped = true; |
| 211 } else { | 214 } else { |
| 212 // Case 4: both canvas and compositor are not gpu accelerated. | 215 // Case 4: both canvas and compositor are not gpu accelerated. |
| 213 commitType = CommitSoftwareCanvasSoftwareCompositing; | 216 commitType = CommitSoftwareCanvasSoftwareCompositing; |
| 214 setTransferableResourceToSharedBitmap(resource, image); | 217 setTransferableResourceToSharedBitmap(resource, image); |
| 215 } | 218 } |
| 216 } | 219 } |
| 217 commitTypeHistogram.count(commitType); | 220 commitTypeHistogram.count(commitType); |
| 218 | 221 |
| 219 m_nextResourceId++; | 222 m_nextResourceId++; |
| 220 frame.delegated_frame_data->resource_list.push_back(std::move(resource)); | 223 frame.delegated_frame_data->resource_list.push_back(std::move(resource)); |
| 221 | 224 |
| 222 cc::TextureDrawQuad* quad = | 225 cc::TextureDrawQuad* quad = |
| 223 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); | 226 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); |
| 224 gfx::Size rectSize(m_width, m_height); | 227 gfx::Size rectSize(m_width, m_height); |
| 225 | 228 |
| 226 const bool needsBlending = true; | 229 const bool needsBlending = true; |
| 227 // TOOD(crbug.com/645993): this should be inherited from WebGL context's | 230 // TOOD(crbug.com/645993): this should be inherited from WebGL context's |
| 228 // creation settings. | 231 // creation settings. |
| 229 const bool premultipliedAlpha = true; | 232 const bool premultipliedAlpha = true; |
| 230 const gfx::PointF uvTopLeft(0.f, 0.f); | 233 const gfx::PointF uvTopLeft(0.f, 0.f); |
| 231 const gfx::PointF uvBottomRight(1.f, 1.f); | 234 const gfx::PointF uvBottomRight(1.f, 1.f); |
| 232 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f}; | 235 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f}; |
| 233 const bool yflipped = false; | |
| 234 // TODO(crbug.com/645994): this should be true when using style | 236 // TODO(crbug.com/645994): this should be true when using style |
| 235 // "image-rendering: pixelated". | 237 // "image-rendering: pixelated". |
| 236 const bool nearestNeighbor = false; | 238 const bool nearestNeighbor = false; |
| 237 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, | 239 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, |
| 238 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight, | 240 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight, |
| 239 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor, | 241 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor, |
| 240 false); | 242 false); |
| 241 | 243 |
| 242 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 244 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
| 243 | 245 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 330 } |
| 329 | 331 |
| 330 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( | 332 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( |
| 331 const sk_sp<SkImage>& image) { | 333 const sk_sp<SkImage>& image) { |
| 332 if (image && image->width() == m_width && image->height() == m_height) | 334 if (image && image->width() == m_width && image->height() == m_height) |
| 333 return true; | 335 return true; |
| 334 return false; | 336 return false; |
| 335 } | 337 } |
| 336 | 338 |
| 337 } // namespace blink | 339 } // namespace blink |
| OLD | NEW |