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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // back to it. | 474 // back to it. |
475 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use | 475 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use |
476 // the actual texture id and avoid needing to produce/consume a mailbox. | 476 // the actual texture id and avoid needing to produce/consume a mailbox. |
477 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( | 477 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( |
478 GL_TEXTURE_2D, textureMailbox.name()); | 478 GL_TEXTURE_2D, textureMailbox.name()); |
479 // Return the mailbox but report that the resource is lost to prevent trying | 479 // Return the mailbox but report that the resource is lost to prevent trying |
480 // to use the backing for future frames. We keep it alive with our own | 480 // to use the backing for future frames. We keep it alive with our own |
481 // reference to the backing via our |textureId|. | 481 // reference to the backing via our |textureId|. |
482 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); | 482 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); |
483 | 483 |
484 // Store that texture id as the backing for an SkImage. | |
485 GrGLTextureInfo textureInfo; | |
486 textureInfo.fTarget = GL_TEXTURE_2D; | |
487 textureInfo.fID = textureId; | |
488 GrBackendTextureDesc backendTexture; | |
489 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin; | |
490 backendTexture.fWidth = m_size.width(); | |
491 backendTexture.fHeight = m_size.height(); | |
492 backendTexture.fConfig = kSkia8888_GrPixelConfig; | |
493 backendTexture.fTextureHandle = | |
494 skia::GrGLTextureInfoToGrBackendObject(textureInfo); | |
495 sk_sp<SkImage> skImage = | |
496 SkImage::MakeFromAdoptedTexture(grContext, backendTexture); | |
497 | |
498 // We reuse the same mailbox name from above since our texture id was consumed | 484 // We reuse the same mailbox name from above since our texture id was consumed |
499 // from it. | 485 // from it. |
500 const auto& skImageMailbox = textureMailbox.mailbox(); | 486 const auto& skImageMailbox = textureMailbox.mailbox(); |
501 // Use the sync token generated after producing the mailbox. Waiting for this | 487 // Use the sync token generated after producing the mailbox. Waiting for this |
502 // before trying to use the mailbox with some other context will ensure it is | 488 // before trying to use the mailbox with some other context will ensure it is |
503 // valid. We wouldn't need to wait for the consume done in this function | 489 // valid. We wouldn't need to wait for the consume done in this function |
504 // because the texture id it generated would only be valid for the | 490 // because the texture id it generated would only be valid for the |
505 // DrawingBuffer's context anyways. | 491 // DrawingBuffer's context anyways. |
506 const auto& skImageSyncToken = textureMailbox.sync_token(); | 492 const auto& skImageSyncToken = textureMailbox.sync_token(); |
507 | 493 |
508 // TODO(xidachen): Create a small pool of recycled textures from | 494 // TODO(xidachen): Create a small pool of recycled textures from |
509 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them | 495 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them |
510 // in DrawingBuffer. | 496 // in DrawingBuffer. |
511 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( | 497 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( |
512 std::move(skImage), skImageMailbox, skImageSyncToken); | 498 skImageMailbox, skImageSyncToken, textureId, m_gl, m_size); |
513 } | 499 } |
514 | 500 |
515 DrawingBuffer::ColorBufferParameters | 501 DrawingBuffer::ColorBufferParameters |
516 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { | 502 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { |
517 #if OS(MACOSX) | 503 #if OS(MACOSX) |
518 // A CHROMIUM_image backed texture requires a specialized set of parameters | 504 // A CHROMIUM_image backed texture requires a specialized set of parameters |
519 // on OSX. | 505 // on OSX. |
520 ColorBufferParameters parameters; | 506 ColorBufferParameters parameters; |
521 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; | 507 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; |
522 | 508 |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 if (m_pixelUnpackBufferBindingDirty) | 1251 if (m_pixelUnpackBufferBindingDirty) |
1266 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); | 1252 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); |
1267 } | 1253 } |
1268 | 1254 |
1269 bool DrawingBuffer::shouldUseChromiumImage() { | 1255 bool DrawingBuffer::shouldUseChromiumImage() { |
1270 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && | 1256 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && |
1271 m_chromiumImageUsage == AllowChromiumImage; | 1257 m_chromiumImageUsage == AllowChromiumImage; |
1272 } | 1258 } |
1273 | 1259 |
1274 } // namespace blink | 1260 } // namespace blink |
OLD | NEW |