| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 #include "platform/graphics/ImageBuffer.h" | 33 #include "platform/graphics/ImageBuffer.h" |
| 34 | 34 |
| 35 #include "GrContext.h" | 35 #include "gpu/command_buffer/client/gles2_interface.h" |
| 36 #include "platform/MIMETypeRegistry.h" | 36 #include "platform/MIMETypeRegistry.h" |
| 37 #include "platform/geometry/IntRect.h" | 37 #include "platform/geometry/IntRect.h" |
| 38 #include "platform/graphics/GraphicsContext.h" | 38 #include "platform/graphics/GraphicsContext.h" |
| 39 #include "platform/graphics/GraphicsTypes3D.h" | 39 #include "platform/graphics/GraphicsTypes3D.h" |
| 40 #include "platform/graphics/ImageBufferClient.h" | 40 #include "platform/graphics/ImageBufferClient.h" |
| 41 #include "platform/graphics/StaticBitmapImage.h" | 41 #include "platform/graphics/StaticBitmapImage.h" |
| 42 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 42 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 43 #include "platform/graphics/gpu/DrawingBuffer.h" | 43 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 44 #include "platform/graphics/gpu/Extensions3DUtil.h" | 44 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 45 #include "platform/graphics/skia/SkiaUtils.h" | 45 #include "platform/graphics/skia/SkiaUtils.h" |
| 46 #include "platform/image-encoders/skia/JPEGImageEncoder.h" | 46 #include "platform/image-encoders/skia/JPEGImageEncoder.h" |
| 47 #include "platform/image-encoders/skia/PNGImageEncoder.h" | 47 #include "platform/image-encoders/skia/PNGImageEncoder.h" |
| 48 #include "platform/image-encoders/skia/WEBPImageEncoder.h" | 48 #include "platform/image-encoders/skia/WEBPImageEncoder.h" |
| 49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 50 #include "public/platform/WebExternalTextureMailbox.h" | 50 #include "public/platform/WebExternalTextureMailbox.h" |
| 51 #include "public/platform/WebGraphicsContext3D.h" | 51 #include "public/platform/WebGraphicsContext3D.h" |
| 52 #include "public/platform/WebGraphicsContext3DProvider.h" | 52 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 53 #include "skia/ext/texture_handle.h" | 53 #include "skia/ext/texture_handle.h" |
| 54 #include "third_party/skia/include/core/SkPicture.h" | 54 #include "third_party/skia/include/core/SkPicture.h" |
| 55 #include "third_party/skia/include/gpu/GrContext.h" |
| 55 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 56 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
| 56 #include "wtf/ArrayBufferContents.h" | 57 #include "wtf/ArrayBufferContents.h" |
| 57 #include "wtf/MathExtras.h" | 58 #include "wtf/MathExtras.h" |
| 58 #include "wtf/Vector.h" | 59 #include "wtf/Vector.h" |
| 59 #include "wtf/text/Base64.h" | 60 #include "wtf/text/Base64.h" |
| 60 #include "wtf/text/WTFString.h" | 61 #include "wtf/text/WTFString.h" |
| 61 | 62 |
| 62 namespace blink { | 63 namespace blink { |
| 63 | 64 |
| 64 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa
ce) | 65 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa
ce) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 if (m_snapshotState == DidAcquireSnapshot) | 171 if (m_snapshotState == DidAcquireSnapshot) |
| 171 m_snapshotState = DrawnToAfterSnapshot; | 172 m_snapshotState = DrawnToAfterSnapshot; |
| 172 m_surface->didDraw(rect); | 173 m_surface->didDraw(rect); |
| 173 } | 174 } |
| 174 | 175 |
| 175 WebLayer* ImageBuffer::platformLayer() const | 176 WebLayer* ImageBuffer::platformLayer() const |
| 176 { | 177 { |
| 177 return m_surface->layer(); | 178 return m_surface->layer(); |
| 178 } | 179 } |
| 179 | 180 |
| 180 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) | 181 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, gpu::gles
2::GLES2Interface* gl, Platform3DObject texture, GLenum internalFormat, GLenum d
estType, GLint level, bool premultiplyAlpha, bool flipY) |
| 181 { | 182 { |
| 182 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) | 183 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) |
| 183 return false; | 184 return false; |
| 184 | 185 |
| 185 if (!isSurfaceValid()) | 186 if (!isSurfaceValid()) |
| 186 return false; | 187 return false; |
| 187 | 188 |
| 188 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel
eration, SnapshotReasonCopyToWebGLTexture); | 189 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel
eration, SnapshotReasonCopyToWebGLTexture); |
| 189 if (!textureImage) | 190 if (!textureImage) |
| 190 return false; | 191 return false; |
| 191 | 192 |
| 192 if (!m_surface->isAccelerated()) | 193 if (!m_surface->isAccelerated()) |
| 193 return false; | 194 return false; |
| 194 | 195 |
| 195 | 196 |
| 196 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this | 197 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this |
| 197 // Get the texture ID, flushing pending operations if needed. | 198 // Get the texture ID, flushing pending operations if needed. |
| 198 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo(
textureImage->getTextureHandle(true)); | 199 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo(
textureImage->getTextureHandle(true)); |
| 199 if (!textureInfo || !textureInfo->fID) | 200 if (!textureInfo || !textureInfo->fID) |
| 200 return false; | 201 return false; |
| 201 | 202 |
| 202 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 203 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); |
| 203 if (!provider) | 204 if (!provider) |
| 204 return false; | 205 return false; |
| 205 WebGraphicsContext3D* sharedContext = provider->context3d(); | 206 WebGraphicsContext3D* sharedContext = provider->context3d(); |
| 207 gpu::gles2::GLES2Interface* sharedGL = provider->contextGL(); |
| 206 | 208 |
| 207 OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureM
ailbox); | 209 OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureM
ailbox); |
| 208 mailbox->textureSize = WebSize(textureImage->width(), textureImage->height()
); | 210 mailbox->textureSize = WebSize(textureImage->width(), textureImage->height()
); |
| 209 | 211 |
| 210 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | 212 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first |
| 211 sharedContext->genMailboxCHROMIUM(mailbox->name); | 213 sharedContext->genMailboxCHROMIUM(mailbox->name); |
| 212 sharedContext->produceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->f
Target, mailbox->name); | 214 sharedContext->produceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->f
Target, mailbox->name); |
| 213 const WGC3Duint64 sharedFenceSync = sharedContext->insertFenceSyncCHROMIUM()
; | 215 const GLuint64 sharedFenceSync = sharedGL->InsertFenceSyncCHROMIUM(); |
| 214 sharedContext->flush(); | 216 sharedContext->flush(); |
| 215 | 217 |
| 216 mailbox->validSyncToken = sharedContext->genSyncTokenCHROMIUM(sharedFenceSyn
c, mailbox->syncToken); | 218 mailbox->validSyncToken = sharedContext->genSyncTokenCHROMIUM(sharedFenceSyn
c, mailbox->syncToken); |
| 217 if (mailbox->validSyncToken) | 219 if (mailbox->validSyncToken) |
| 218 context->waitSyncTokenCHROMIUM(mailbox->syncToken); | 220 gl->WaitSyncTokenCHROMIUM(mailbox->syncToken); |
| 219 | 221 |
| 220 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(te
xtureInfo->fTarget, mailbox->name); | 222 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(te
xtureInfo->fTarget, mailbox->name); |
| 221 | 223 |
| 222 // The canvas is stored in a premultiplied format, so unpremultiply if neces
sary. | 224 // The canvas is stored in a premultiplied format, so unpremultiply if neces
sary. |
| 223 // The canvas is stored in an inverted position, so the flip semantics are r
eversed. | 225 // The canvas is stored in an inverted position, so the flip semantics are r
eversed. |
| 224 context->copyTextureCHROMIUM(sourceTexture, texture, internalFormat, destTyp
e, flipY ? GL_FALSE : GL_TRUE, GL_FALSE, premultiplyAlpha ? GL_FALSE : GL_TRUE); | 226 context->copyTextureCHROMIUM(sourceTexture, texture, internalFormat, destTyp
e, flipY ? GL_FALSE : GL_TRUE, GL_FALSE, premultiplyAlpha ? GL_FALSE : GL_TRUE); |
| 225 | 227 |
| 226 context->deleteTexture(sourceTexture); | 228 context->deleteTexture(sourceTexture); |
| 227 | 229 |
| 228 const WGC3Duint64 contextFenceSync = context->insertFenceSyncCHROMIUM(); | 230 const GLuint64 contextFenceSync = gl->InsertFenceSyncCHROMIUM(); |
| 229 | 231 |
| 230 context->flush(); | 232 context->flush(); |
| 231 | 233 |
| 232 WGC3Dbyte syncToken[24]; | 234 WGC3Dbyte syncToken[24]; |
| 233 if (context->genSyncTokenCHROMIUM(contextFenceSync, syncToken)) | 235 if (context->genSyncTokenCHROMIUM(contextFenceSync, syncToken)) |
| 234 sharedContext->waitSyncTokenCHROMIUM(syncToken); | 236 sharedGL->WaitSyncTokenCHROMIUM(syncToken); |
| 235 | 237 |
| 236 // Undo grContext texture binding changes introduced in this function | 238 // Undo grContext texture binding changes introduced in this function |
| 237 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); | 239 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); |
| 238 | 240 |
| 239 return true; | 241 return true; |
| 240 } | 242 } |
| 241 | 243 |
| 242 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) | 244 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) |
| 243 { | 245 { |
| 244 if (!drawingBuffer || !m_surface->isAccelerated()) | 246 if (!drawingBuffer || !m_surface->isAccelerated()) |
| 245 return false; | 247 return false; |
| 246 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 248 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); |
| 247 if (!provider) | 249 if (!provider) |
| 248 return false; | 250 return false; |
| 249 WebGraphicsContext3D* context3D = provider->context3d(); | 251 WebGraphicsContext3D* context3D = provider->context3d(); |
| 252 gpu::gles2::GLES2Interface* gl = provider->contextGL(); |
| 250 Platform3DObject textureId = m_surface->getBackingTextureHandleForOverwrite(
); | 253 Platform3DObject textureId = m_surface->getBackingTextureHandleForOverwrite(
); |
| 251 if (!textureId) | 254 if (!textureId) |
| 252 return false; | 255 return false; |
| 253 | 256 |
| 254 context3D->flush(); | 257 context3D->flush(); |
| 255 | 258 |
| 256 return drawingBuffer->copyToPlatformTexture(context3D, textureId, GL_RGBA, | 259 return drawingBuffer->copyToPlatformTexture(context3D, gl, textureId, GL_RGB
A, |
| 257 GL_UNSIGNED_BYTE, 0, true, false, sourceBuffer); | 260 GL_UNSIGNED_BYTE, 0, true, false, sourceBuffer); |
| 258 } | 261 } |
| 259 | 262 |
| 260 void ImageBuffer::draw(GraphicsContext& context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) | 263 void ImageBuffer::draw(GraphicsContext& context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) |
| 261 { | 264 { |
| 262 if (!isSurfaceValid()) | 265 if (!isSurfaceValid()) |
| 263 return; | 266 return; |
| 264 | 267 |
| 265 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), FloatSize(siz
e())); | 268 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), FloatSize(siz
e())); |
| 266 m_surface->draw(context, destRect, srcRect, op); | 269 m_surface->draw(context, destRect, srcRect, op); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 405 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 403 | 406 |
| 404 Vector<unsigned char> result; | 407 Vector<unsigned char> result; |
| 405 if (!encodeImage(mimeType, quality, &result)) | 408 if (!encodeImage(mimeType, quality, &result)) |
| 406 return "data:,"; | 409 return "data:,"; |
| 407 | 410 |
| 408 return "data:" + mimeType + ";base64," + base64Encode(result); | 411 return "data:" + mimeType + ";base64," + base64Encode(result); |
| 409 } | 412 } |
| 410 | 413 |
| 411 } // namespace blink | 414 } // namespace blink |
| OLD | NEW |