Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 bool wantDepth, | 147 bool wantDepth, |
| 148 bool wantStencil) | 148 bool wantStencil) |
| 149 : m_preserveDrawingBuffer(preserve) | 149 : m_preserveDrawingBuffer(preserve) |
| 150 , m_webGLVersion(webGLVersion) | 150 , m_webGLVersion(webGLVersion) |
| 151 , m_contextProvider(std::move(contextProvider)) | 151 , m_contextProvider(std::move(contextProvider)) |
| 152 , m_gl(m_contextProvider->contextGL()) | 152 , m_gl(m_contextProvider->contextGL()) |
| 153 , m_extensionsUtil(std::move(extensionsUtil)) | 153 , m_extensionsUtil(std::move(extensionsUtil)) |
| 154 , m_discardFramebufferSupported(discardFramebufferSupported) | 154 , m_discardFramebufferSupported(discardFramebufferSupported) |
| 155 , m_wantAlphaChannel(wantAlphaChannel) | 155 , m_wantAlphaChannel(wantAlphaChannel) |
| 156 , m_premultipliedAlpha(premultipliedAlpha) | 156 , m_premultipliedAlpha(premultipliedAlpha) |
| 157 , m_softwareRendering(m_contextProvider->isSoftwareRendering()) | |
| 157 , m_wantDepth(wantDepth) | 158 , m_wantDepth(wantDepth) |
| 158 , m_wantStencil(wantStencil) | 159 , m_wantStencil(wantStencil) |
| 159 { | 160 { |
| 160 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); | 161 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); |
| 161 memset(m_clearColor, 0, 4 * sizeof(GLfloat)); | 162 memset(m_clearColor, 0, 4 * sizeof(GLfloat)); |
| 162 // Used by browser tests to detect the use of a DrawingBuffer. | 163 // Used by browser tests to detect the use of a DrawingBuffer. |
| 163 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", TRACE_EVENT_SCOPE_ GLOBAL); | 164 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", TRACE_EVENT_SCOPE_ GLOBAL); |
| 164 } | 165 } |
| 165 | 166 |
| 166 DrawingBuffer::~DrawingBuffer() | 167 DrawingBuffer::~DrawingBuffer() |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 return std::move(recycled.bitmap); | 258 return std::move(recycled.bitmap); |
| 258 } | 259 } |
| 259 | 260 |
| 260 return Platform::current()->allocateSharedBitmap(m_size); | 261 return Platform::current()->allocateSharedBitmap(m_size); |
| 261 } | 262 } |
| 262 | 263 |
| 263 bool DrawingBuffer::PrepareTextureMailbox(cc::TextureMailbox* outMailbox, | 264 bool DrawingBuffer::PrepareTextureMailbox(cc::TextureMailbox* outMailbox, |
| 264 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, | 265 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, |
| 265 bool useSharedMemory) | 266 bool useSharedMemory) |
| 266 { | 267 { |
| 268 bool forceGpuResult = false; | |
| 269 return prepareTextureMailboxInternal(outMailbox, outReleaseCallback, forceGp uResult); | |
| 270 } | |
| 271 | |
| 272 bool DrawingBuffer::prepareTextureMailboxInternal( | |
|
danakj
2016/08/22 22:57:44
I added a prepareTextureMailboxInternal that lets
| |
| 273 cc::TextureMailbox* outMailbox, | |
| 274 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, | |
| 275 bool forceGpuResult) | |
| 276 { | |
| 267 if (m_destructionInProgress) { | 277 if (m_destructionInProgress) { |
| 268 // It can be hit in the following sequence. | 278 // It can be hit in the following sequence. |
| 269 // 1. WebGL draws something. | 279 // 1. WebGL draws something. |
| 270 // 2. The compositor begins the frame. | 280 // 2. The compositor begins the frame. |
| 271 // 3. Javascript makes a context lost using WEBGL_lose_context extension . | 281 // 3. Javascript makes a context lost using WEBGL_lose_context extension . |
| 272 // 4. Here. | 282 // 4. Here. |
| 273 return false; | 283 return false; |
| 274 } | 284 } |
| 275 ASSERT(!m_isHidden); | 285 ASSERT(!m_isHidden); |
| 276 if (!m_contentsChanged) | 286 if (!m_contentsChanged) |
| 277 return false; | 287 return false; |
| 278 | 288 |
| 289 // If the context is lost, we don't know if we should be producing GPU or | |
| 290 // software frames, until we get a new context, since the compositor will | |
| 291 // be trying to get a new context and may change modes. | |
| 292 if (m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | |
| 293 return false; | |
| 294 | |
| 279 TRACE_EVENT0("blink,rail", "DrawingBuffer::prepareMailbox"); | 295 TRACE_EVENT0("blink,rail", "DrawingBuffer::prepareMailbox"); |
| 280 | 296 |
| 281 if (m_newMailboxCallback) | 297 if (m_newMailboxCallback) |
| 282 (*m_newMailboxCallback)(); | 298 (*m_newMailboxCallback)(); |
| 283 | 299 |
| 284 // Resolve the multisampled buffer into m_colorBuffer texture. | 300 // Resolve the multisampled buffer into m_colorBuffer texture. |
| 285 if (m_antiAliasingMode != None) | 301 if (m_antiAliasingMode != None) |
| 286 commit(); | 302 commit(); |
| 287 | 303 |
| 288 if (useSharedMemory) { | 304 if (m_softwareRendering && !forceGpuResult) { |
| 289 std::unique_ptr<cc::SharedBitmap> bitmap = createOrRecycleBitmap(); | 305 std::unique_ptr<cc::SharedBitmap> bitmap = createOrRecycleBitmap(); |
| 290 if (!bitmap) | 306 if (!bitmap) |
| 291 return false; | 307 return false; |
| 292 unsigned char* pixels = bitmap->pixels(); | 308 unsigned char* pixels = bitmap->pixels(); |
| 293 DCHECK(pixels); | 309 DCHECK(pixels); |
| 294 | 310 |
| 295 bool needPremultiply = m_wantAlphaChannel && !m_premultipliedAlpha; | 311 bool needPremultiply = m_wantAlphaChannel && !m_premultipliedAlpha; |
| 296 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 312 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
| 297 readBackFramebuffer(pixels, size().width(), size().height(), ReadbackSki a, op); | 313 readBackFramebuffer(pixels, size().width(), size().height(), ReadbackSki a, op); |
| 298 | 314 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 m_recycledBitmapQueue.append(std::move(recycled)); | 414 m_recycledBitmapQueue.append(std::move(recycled)); |
| 399 } | 415 } |
| 400 | 416 |
| 401 PassRefPtr<StaticBitmapImage> DrawingBuffer::transferToStaticBitmapImage() | 417 PassRefPtr<StaticBitmapImage> DrawingBuffer::transferToStaticBitmapImage() |
| 402 { | 418 { |
| 403 // This can be null if the context is lost before the first call to grContex t(). | 419 // This can be null if the context is lost before the first call to grContex t(). |
| 404 GrContext* grContext = m_contextProvider->grContext(); | 420 GrContext* grContext = m_contextProvider->grContext(); |
| 405 | 421 |
| 406 cc::TextureMailbox textureMailbox; | 422 cc::TextureMailbox textureMailbox; |
| 407 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 423 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 408 bool useSharedMemory = false; | |
| 409 bool success = false; | 424 bool success = false; |
| 410 if (grContext) | 425 if (grContext) { |
| 411 success = PrepareTextureMailbox(&textureMailbox, &releaseCallback, useSh aredMemory); | 426 bool forceGpuResult = true; |
| 427 success = prepareTextureMailboxInternal(&textureMailbox, &releaseCallbac k, forceGpuResult); | |
| 428 } | |
| 412 if (!success) { | 429 if (!success) { |
| 413 // If we can't get a mailbox, return an transparent black ImageBitmap. | 430 // If we can't get a mailbox, return an transparent black ImageBitmap. |
| 414 // The only situation this could happen is when two or more calls to tra nsferToImageBitmap are made back-to-back, or when the context gets lost. | 431 // The only situation this could happen is when two or more calls to tra nsferToImageBitmap are made back-to-back, or when the context gets lost. |
| 415 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(m_size.width() , m_size.height()); | 432 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(m_size.width() , m_size.height()); |
| 416 return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())) ; | 433 return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())) ; |
| 417 } | 434 } |
| 418 | 435 |
| 419 DCHECK_EQ(m_size.width(), textureMailbox.size_in_pixels().width()); | 436 DCHECK_EQ(m_size.width(), textureMailbox.size_in_pixels().width()); |
| 420 DCHECK_EQ(m_size.height(), textureMailbox.size_in_pixels().height()); | 437 DCHECK_EQ(m_size.height(), textureMailbox.size_in_pixels().height()); |
| 421 | 438 |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 | 1230 |
| 1214 void DrawingBuffer::restoreTextureBindings() | 1231 void DrawingBuffer::restoreTextureBindings() |
| 1215 { | 1232 { |
| 1216 // This class potentially modifies the bindings for GL_TEXTURE_2D and | 1233 // This class potentially modifies the bindings for GL_TEXTURE_2D and |
| 1217 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since | 1234 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since |
| 1218 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. | 1235 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. |
| 1219 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1236 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
| 1220 } | 1237 } |
| 1221 | 1238 |
| 1222 } // namespace blink | 1239 } // namespace blink |
| OLD | NEW |