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 20 matching lines...) Expand all Loading... | |
31 #include "platform/graphics/gpu/DrawingBuffer.h" | 31 #include "platform/graphics/gpu/DrawingBuffer.h" |
32 | 32 |
33 #include "cc/resources/shared_bitmap.h" | 33 #include "cc/resources/shared_bitmap.h" |
34 #include "gpu/GLES2/gl2extchromium.h" | 34 #include "gpu/GLES2/gl2extchromium.h" |
35 #include "gpu/command_buffer/client/gles2_interface.h" | 35 #include "gpu/command_buffer/client/gles2_interface.h" |
36 #include "gpu/command_buffer/common/capabilities.h" | 36 #include "gpu/command_buffer/common/capabilities.h" |
37 #include "platform/RuntimeEnabledFeatures.h" | 37 #include "platform/RuntimeEnabledFeatures.h" |
38 #include "platform/graphics/AcceleratedStaticBitmapImage.h" | 38 #include "platform/graphics/AcceleratedStaticBitmapImage.h" |
39 #include "platform/graphics/GraphicsLayer.h" | 39 #include "platform/graphics/GraphicsLayer.h" |
40 #include "platform/graphics/ImageBuffer.h" | 40 #include "platform/graphics/ImageBuffer.h" |
41 #include "platform/graphics/WebGraphicsContext3DProviderWrapper.h" | |
41 #include "platform/graphics/gpu/Extensions3DUtil.h" | 42 #include "platform/graphics/gpu/Extensions3DUtil.h" |
42 #include "platform/tracing/TraceEvent.h" | 43 #include "platform/tracing/TraceEvent.h" |
43 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
44 #include "public/platform/WebCompositorSupport.h" | 45 #include "public/platform/WebCompositorSupport.h" |
45 #include "public/platform/WebExternalBitmap.h" | 46 #include "public/platform/WebExternalBitmap.h" |
46 #include "public/platform/WebExternalTextureLayer.h" | 47 #include "public/platform/WebExternalTextureLayer.h" |
47 #include "public/platform/WebGraphicsContext3DProvider.h" | 48 #include "public/platform/WebGraphicsContext3DProvider.h" |
48 #include "skia/ext/texture_handle.h" | 49 #include "skia/ext/texture_handle.h" |
49 #include "third_party/skia/include/gpu/GrContext.h" | 50 #include "third_party/skia/include/gpu/GrContext.h" |
50 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 51 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 // back to it. | 475 // back to it. |
475 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use | 476 // TODO(danakj): Instead of using PrepareTextureMailbox(), we could just use |
476 // the actual texture id and avoid needing to produce/consume a mailbox. | 477 // the actual texture id and avoid needing to produce/consume a mailbox. |
477 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( | 478 GLuint textureId = m_gl->CreateAndConsumeTextureCHROMIUM( |
478 GL_TEXTURE_2D, textureMailbox.name()); | 479 GL_TEXTURE_2D, textureMailbox.name()); |
479 // Return the mailbox but report that the resource is lost to prevent trying | 480 // 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 | 481 // to use the backing for future frames. We keep it alive with our own |
481 // reference to the backing via our |textureId|. | 482 // reference to the backing via our |textureId|. |
482 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); | 483 releaseCallback->Run(gpu::SyncToken(), true /* lostResource */); |
483 | 484 |
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 | 485 // We reuse the same mailbox name from above since our texture id was consumed |
499 // from it. | 486 // from it. |
500 const auto& skImageMailbox = textureMailbox.mailbox(); | 487 const auto& skImageMailbox = textureMailbox.mailbox(); |
501 // Use the sync token generated after producing the mailbox. Waiting for this | 488 // 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 | 489 // 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 | 490 // 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 | 491 // because the texture id it generated would only be valid for the |
505 // DrawingBuffer's context anyways. | 492 // DrawingBuffer's context anyways. |
506 const auto& skImageSyncToken = textureMailbox.sync_token(); | 493 const auto& skImageSyncToken = textureMailbox.sync_token(); |
494 WebGraphicsContext3DProviderWrapper* contextProvider = | |
Justin Novosad
2016/11/08 19:38:54
This wrapper object is being leaked. DrawingBuffer
xidachen
2016/11/08 20:30:58
Done.
| |
495 new WebGraphicsContext3DProviderWrapper(m_contextProvider.get()); | |
507 | 496 |
508 // TODO(xidachen): Create a small pool of recycled textures from | 497 // TODO(xidachen): Create a small pool of recycled textures from |
509 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them | 498 // ImageBitmapRenderingContext's transferFromImageBitmap, and try to use them |
510 // in DrawingBuffer. | 499 // in DrawingBuffer. |
511 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( | 500 return AcceleratedStaticBitmapImage::createFromWebGLContextImage( |
512 std::move(skImage), skImageMailbox, skImageSyncToken); | 501 skImageMailbox, skImageSyncToken, textureId, |
502 contextProvider->createWeakPtr(), m_size); | |
513 } | 503 } |
514 | 504 |
515 DrawingBuffer::ColorBufferParameters | 505 DrawingBuffer::ColorBufferParameters |
516 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { | 506 DrawingBuffer::gpuMemoryBufferColorBufferParameters() { |
517 #if OS(MACOSX) | 507 #if OS(MACOSX) |
518 // A CHROMIUM_image backed texture requires a specialized set of parameters | 508 // A CHROMIUM_image backed texture requires a specialized set of parameters |
519 // on OSX. | 509 // on OSX. |
520 ColorBufferParameters parameters; | 510 ColorBufferParameters parameters; |
521 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; | 511 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; |
522 | 512 |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1265 if (m_pixelUnpackBufferBindingDirty) | 1255 if (m_pixelUnpackBufferBindingDirty) |
1266 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); | 1256 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); |
1267 } | 1257 } |
1268 | 1258 |
1269 bool DrawingBuffer::shouldUseChromiumImage() { | 1259 bool DrawingBuffer::shouldUseChromiumImage() { |
1270 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && | 1260 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && |
1271 m_chromiumImageUsage == AllowChromiumImage; | 1261 m_chromiumImageUsage == AllowChromiumImage; |
1272 } | 1262 } |
1273 | 1263 |
1274 } // namespace blink | 1264 } // namespace blink |
OLD | NEW |