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