| 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 20 matching lines...) Expand all Loading... |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 #include "sky/engine/platform/graphics/ImageBuffer.h" | 33 #include "sky/engine/platform/graphics/ImageBuffer.h" |
| 34 | 34 |
| 35 #include "platform/image-encoders/skia/JPEGImageEncoder.h" | 35 #include "platform/image-encoders/skia/JPEGImageEncoder.h" |
| 36 #include "platform/image-encoders/skia/PNGImageEncoder.h" | 36 #include "platform/image-encoders/skia/PNGImageEncoder.h" |
| 37 #include "sky/engine/platform/MIMETypeRegistry.h" | 37 #include "sky/engine/platform/MIMETypeRegistry.h" |
| 38 #include "sky/engine/platform/geometry/IntRect.h" | 38 #include "sky/engine/platform/geometry/IntRect.h" |
| 39 #include "sky/engine/platform/graphics/BitmapImage.h" | 39 #include "sky/engine/platform/graphics/BitmapImage.h" |
| 40 #include "sky/engine/platform/graphics/GraphicsContext.h" | 40 #include "sky/engine/platform/graphics/GraphicsContext.h" |
| 41 #include "sky/engine/platform/graphics/GraphicsTypes3D.h" | |
| 42 #include "sky/engine/platform/graphics/ImageBufferClient.h" | 41 #include "sky/engine/platform/graphics/ImageBufferClient.h" |
| 43 #include "sky/engine/platform/graphics/UnacceleratedImageBufferSurface.h" | 42 #include "sky/engine/platform/graphics/UnacceleratedImageBufferSurface.h" |
| 44 #include "sky/engine/platform/graphics/gpu/DrawingBuffer.h" | |
| 45 #include "sky/engine/platform/graphics/gpu/Extensions3DUtil.h" | |
| 46 #include "sky/engine/platform/graphics/skia/NativeImageSkia.h" | 43 #include "sky/engine/platform/graphics/skia/NativeImageSkia.h" |
| 47 #include "sky/engine/platform/graphics/skia/SkiaUtils.h" | 44 #include "sky/engine/platform/graphics/skia/SkiaUtils.h" |
| 48 #include "sky/engine/public/platform/Platform.h" | 45 #include "sky/engine/public/platform/Platform.h" |
| 49 #include "sky/engine/public/platform/WebExternalTextureMailbox.h" | 46 #include "sky/engine/public/platform/WebExternalTextureMailbox.h" |
| 50 #include "sky/engine/public/platform/WebGraphicsContext3D.h" | 47 #include "sky/engine/public/platform/WebGraphicsContext3D.h" |
| 51 #include "sky/engine/public/platform/WebGraphicsContext3DProvider.h" | 48 #include "sky/engine/public/platform/WebGraphicsContext3DProvider.h" |
| 52 #include "sky/engine/wtf/MathExtras.h" | 49 #include "sky/engine/wtf/MathExtras.h" |
| 53 #include "sky/engine/wtf/Vector.h" | 50 #include "sky/engine/wtf/Vector.h" |
| 54 #include "sky/engine/wtf/text/Base64.h" | 51 #include "sky/engine/wtf/text/Base64.h" |
| 55 #include "sky/engine/wtf/text/WTFString.h" | 52 #include "sky/engine/wtf/text/WTFString.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 BackingStoreCopy ImageBuffer::fastCopyImageMode() | 154 BackingStoreCopy ImageBuffer::fastCopyImageMode() |
| 158 { | 155 { |
| 159 return DontCopyBackingStore; | 156 return DontCopyBackingStore; |
| 160 } | 157 } |
| 161 | 158 |
| 162 WebLayer* ImageBuffer::platformLayer() const | 159 WebLayer* ImageBuffer::platformLayer() const |
| 163 { | 160 { |
| 164 return m_surface->layer(); | 161 return m_surface->layer(); |
| 165 } | 162 } |
| 166 | 163 |
| 167 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) | |
| 168 { | |
| 169 if (!m_surface->isAccelerated() || !platformLayer() || !isSurfaceValid()) | |
| 170 return false; | |
| 171 | |
| 172 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, destType, l
evel)) | |
| 173 return false; | |
| 174 | |
| 175 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | |
| 176 if (!provider) | |
| 177 return false; | |
| 178 WebGraphicsContext3D* sharedContext = provider->context3d(); | |
| 179 if (!sharedContext) | |
| 180 return false; | |
| 181 | |
| 182 OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureM
ailbox); | |
| 183 | |
| 184 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | |
| 185 sharedContext->genMailboxCHROMIUM(mailbox->name); | |
| 186 sharedContext->produceTextureDirectCHROMIUM(getBackingTexture(), GL_TEXTURE_
2D, mailbox->name); | |
| 187 sharedContext->flush(); | |
| 188 | |
| 189 mailbox->syncPoint = sharedContext->insertSyncPoint(); | |
| 190 | |
| 191 context->waitSyncPoint(mailbox->syncPoint); | |
| 192 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL
_TEXTURE_2D, mailbox->name); | |
| 193 | |
| 194 // The canvas is stored in a premultiplied format, so unpremultiply if neces
sary. | |
| 195 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, !premultiplyA
lpha); | |
| 196 | |
| 197 // The canvas is stored in an inverted position, so the flip semantics are r
eversed. | |
| 198 context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, !flipY); | |
| 199 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, level, i
nternalFormat, destType); | |
| 200 | |
| 201 context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, false); | |
| 202 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false); | |
| 203 | |
| 204 context->deleteTexture(sourceTexture); | |
| 205 | |
| 206 context->flush(); | |
| 207 sharedContext->waitSyncPoint(context->insertSyncPoint()); | |
| 208 | |
| 209 // Undo grContext texture binding changes introduced in this function | |
| 210 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); | |
| 211 | |
| 212 return true; | |
| 213 } | |
| 214 | |
| 215 static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst) | 164 static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst) |
| 216 { | 165 { |
| 217 ASSERT(dst); | 166 ASSERT(dst); |
| 218 return (src == dst); | 167 return (src == dst); |
| 219 } | 168 } |
| 220 | 169 |
| 221 Platform3DObject ImageBuffer::getBackingTexture() | |
| 222 { | |
| 223 return m_surface->getBackingTexture(); | |
| 224 } | |
| 225 | |
| 226 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, bool fromFrontBuffer) | |
| 227 { | |
| 228 if (!drawingBuffer) | |
| 229 return false; | |
| 230 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | |
| 231 if (!provider) | |
| 232 return false; | |
| 233 WebGraphicsContext3D* context3D = provider->context3d(); | |
| 234 Platform3DObject tex = m_surface->getBackingTexture(); | |
| 235 if (!context3D || !tex) | |
| 236 return false; | |
| 237 | |
| 238 m_surface->invalidateCachedBitmap(); | |
| 239 return drawingBuffer->copyToPlatformTexture(context3D, tex, GL_RGBA, | |
| 240 GL_UNSIGNED_BYTE, 0, true, false, fromFrontBuffer); | |
| 241 } | |
| 242 | |
| 243 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, CompositeOperator op, WebBlendMode blendMode) | 170 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, CompositeOperator op, WebBlendMode blendMode) |
| 244 { | 171 { |
| 245 if (!isSurfaceValid()) | 172 if (!isSurfaceValid()) |
| 246 return; | 173 return; |
| 247 | 174 |
| 248 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size()); | 175 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size()); |
| 249 RefPtr<SkPicture> picture = m_surface->getPicture(); | 176 RefPtr<SkPicture> picture = m_surface->getPicture(); |
| 250 if (picture) { | 177 if (picture) { |
| 251 context->drawPicture(picture.release(), destRect, srcRect, op, blendMode
); | 178 context->drawPicture(picture.release(), destRect, srcRect, op, blendMode
); |
| 252 return; | 179 return; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 348 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
| 422 return "data:,"; | 349 return "data:,"; |
| 423 | 350 |
| 424 Vector<char> base64Data; | 351 Vector<char> base64Data; |
| 425 base64Encode(encodedImage, base64Data); | 352 base64Encode(encodedImage, base64Data); |
| 426 | 353 |
| 427 return "data:" + mimeType + ";base64," + base64Data; | 354 return "data:" + mimeType + ";base64," + base64Data; |
| 428 } | 355 } |
| 429 | 356 |
| 430 } // namespace blink | 357 } // namespace blink |
| OLD | NEW |