Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: Source/platform/graphics/ImageBuffer.cpp

Issue 1284603003: WebGL: optimize webgl.texSubImage2D(video) path. (Blink side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase to ToT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (m_snapshotState == DidAcquireSnapshot) 171 if (m_snapshotState == DidAcquireSnapshot)
172 m_snapshotState = DrawnToAfterSnapshot; 172 m_snapshotState = DrawnToAfterSnapshot;
173 m_surface->didDraw(rect); 173 m_surface->didDraw(rect);
174 } 174 }
175 175
176 WebLayer* ImageBuffer::platformLayer() const 176 WebLayer* ImageBuffer::platformLayer() const
177 { 177 {
178 return m_surface->layer(); 178 return m_surface->layer();
179 } 179 }
180 180
181 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, GLenum ta rget, Platform3DObject texture,
182 GLenum internalFormat, GLenum destType, GLint level, bool premultiplyAlpha, bool flipY)
183 {
184 return copyToPlatformTextureInternal(true, context, target, texture, interna lFormat,
185 destType, level, 0, 0, 0, 0, premultiplyAlpha, flipY);
186 }
187
188 bool ImageBuffer::copySubToPlatformTexture(WebGraphicsContext3D* context, GLenum target, Platform3DObject texture,
189 GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, bo ol premultiplyAlpha, bool flipY)
190 {
191 return copyToPlatformTextureInternal(false, context, target, texture, GL_FAL SE, GL_FALSE, level,
192 xoffset, yoffset, width, height, premultiplyAlpha, flipY);
193 }
194
195 bool ImageBuffer::copyToPlatformTextureInternal(bool isFullCopy, WebGraphicsCont ext3D* context, GLenum target,
196 Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint leve l, GLint xoffset, GLint yoffset,
197 GLsizei width, GLsizei height, bool premultiplyAlpha, bool flipY)
182 { 198 {
183 if (!m_surface->isAccelerated() || !isSurfaceValid()) 199 if (!m_surface->isAccelerated() || !isSurfaceValid())
184 return false; 200 return false;
185 201
186 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm at, destType, level)) 202 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalFormat, des tType, level))
187 return false; 203 return false;
188 204
189 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(); 205 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot();
190 if (!textureImage) 206 if (!textureImage)
191 return false; 207 return false;
192 208
193 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou ld guarantee this 209 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou ld guarantee this
194 // Get the texture ID, flushing pending operations if needed. 210 // Get the texture ID, flushing pending operations if needed.
195 Platform3DObject textureId = textureImage->getTextureHandle(true); 211 Platform3DObject textureId = textureImage->getTextureHandle(true);
196 if (!textureId) 212 if (!textureId)
(...skipping 11 matching lines...) Expand all
208 // Contexts may be in a different share group. We must transfer the texture through a mailbox first 224 // Contexts may be in a different share group. We must transfer the texture through a mailbox first
209 sharedContext->genMailboxCHROMIUM(mailbox->name); 225 sharedContext->genMailboxCHROMIUM(mailbox->name);
210 sharedContext->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, mailbo x->name); 226 sharedContext->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, mailbo x->name);
211 sharedContext->flush(); 227 sharedContext->flush();
212 228
213 mailbox->syncPoint = sharedContext->insertSyncPoint(); 229 mailbox->syncPoint = sharedContext->insertSyncPoint();
214 230
215 context->waitSyncPoint(mailbox->syncPoint); 231 context->waitSyncPoint(mailbox->syncPoint);
216 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL _TEXTURE_2D, mailbox->name); 232 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL _TEXTURE_2D, mailbox->name);
217 233
234 WGC3Dboolean glFlipY = flipY ? GL_FALSE : GL_TRUE;
235 WGC3Dboolean glPremultiplyAlpha = premultiplyAlpha ? GL_FALSE : GL_TRUE;
236
218 // The canvas is stored in a premultiplied format, so unpremultiply if neces sary. 237 // The canvas is stored in a premultiplied format, so unpremultiply if neces sary.
219 // The canvas is stored in an inverted position, so the flip semantics are r eversed. 238 // The canvas is stored in an inverted position, so the flip semantics are r eversed.
220 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, internal Format, destType, flipY ? GL_FALSE : GL_TRUE, GL_FALSE, premultiplyAlpha ? GL_FA LSE : GL_TRUE); 239 if (isFullCopy) {
240 context->copyTextureCHROMIUM(target, sourceTexture, texture, internalFor mat, destType, glFlipY, GL_FALSE, glPremultiplyAlpha);
241 } else {
242 context->copySubTextureCHROMIUM(target, sourceTexture, texture, xoffset, yoffset, 0, 0, width, height, glFlipY, GL_FALSE, glPremultiplyAlpha);
243 }
221 244
222 context->deleteTexture(sourceTexture); 245 context->deleteTexture(sourceTexture);
223 246
224 context->flush(); 247 context->flush();
225 sharedContext->waitSyncPoint(context->insertSyncPoint()); 248 sharedContext->waitSyncPoint(context->insertSyncPoint());
226 249
227 // Undo grContext texture binding changes introduced in this function 250 // Undo grContext texture binding changes introduced in this function
228 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); 251 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState);
229 252
230 return true; 253 return true;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 394 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
372 395
373 Vector<char> encodedImage; 396 Vector<char> encodedImage;
374 if (!encodeImage(mimeType, quality, &encodedImage)) 397 if (!encodeImage(mimeType, quality, &encodedImage))
375 return "data:,"; 398 return "data:,";
376 399
377 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); 400 return "data:" + mimeType + ";base64," + base64Encode(encodedImage);
378 } 401 }
379 402
380 } // namespace blink 403 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/ImageBuffer.h ('k') | Source/platform/graphics/gpu/Extensions3DUtil.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698