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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2016043002: Avoid copy pixel data in texImage2D(ImageBitmap) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change to OwnPtr Created 4 years, 6 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) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 4089 matching lines...) Expand 10 before | Expand all | Expand 10 after
4100 bool needConversion = true; 4100 bool needConversion = true;
4101 // The data from ImageData is always of format RGBA8. 4101 // The data from ImageData is always of format RGBA8.
4102 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4102 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4103 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 4103 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
4104 needConversion = false; 4104 needConversion = false;
4105 } else { 4105 } else {
4106 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4106 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4107 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed. 4107 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed.
4108 type = GL_FLOAT; 4108 type = GL_FLOAT;
4109 } 4109 }
4110 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4110 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u npackFlipY, m_unpackPremultiplyAlpha, data)) {
4111 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 4111 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
4112 return; 4112 return;
4113 } 4113 }
4114 } 4114 }
4115 resetUnpackParameters(); 4115 resetUnpackParameters();
4116 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data()); 4116 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data());
4117 restoreUnpackParameters(); 4117 restoreUnpackParameters();
4118 } 4118 }
4119 4119
4120 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, 4120 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat,
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
4303 { 4303 {
4304 if (isContextLost()) 4304 if (isContextLost())
4305 return; 4305 return;
4306 if (!validateImageBitmap("texImage2D", bitmap, exceptionState)) 4306 if (!validateImageBitmap("texImage2D", bitmap, exceptionState))
4307 return; 4307 return;
4308 if (!validateTexture2DBinding("texImage2D", target)) 4308 if (!validateTexture2DBinding("texImage2D", target))
4309 return; 4309 return;
4310 if (!validateTexFunc("texImage2D", TexImage, SourceImageBitmap, target, leve l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0)) 4310 if (!validateTexFunc("texImage2D", TexImage, SourceImageBitmap, target, leve l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0))
4311 return; 4311 return;
4312 ASSERT(bitmap->bitmapImage()); 4312 ASSERT(bitmap->bitmapImage());
4313 OwnPtr<uint8_t[]> pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied () ? PremultiplyAlpha : DontPremultiplyAlpha); 4313 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame();
4314 SkPixmap pixmap;
4315 OwnPtr<uint8_t[]> pixelData;
4316 uint8_t* pixelDataPtr = nullptr;
4317 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed
4318 // Use texture mailbox in that case.
4319 bool peekSucceed = skImage->peekPixels(&pixmap);
4320 if (peekSucceed) {
4321 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr());
4322 } else if (skImage->isTextureBacked()) {
4323 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip lyAlpha : DontPremultiplyAlpha);
4324 pixelDataPtr = pixelData.get();
4325 }
4314 Vector<uint8_t> data; 4326 Vector<uint8_t> data;
4315 bool needConversion = true; 4327 bool needConversion = true;
4316 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 4328 bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::k RGBA_8888_SkColorType);
4329 bool isPixelDataRBGA = (havePeekableRGBA || !peekSucceed);
4330 if (isPixelDataRBGA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
4317 needConversion = false; 4331 needConversion = false;
4318 } else { 4332 } else {
4319 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4333 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4320 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed. 4334 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed.
4321 type = GL_FLOAT; 4335 type = GL_FLOAT;
4322 } 4336 }
4323 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha. 4337 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha.
4324 if (!WebGLImageConversion::extractImageData(pixelData.get(), bitmap->siz e(), format, type, false, false, data)) { 4338 bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType ::kBGRA_8888_SkColorType);
4339 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data))
4340 || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixel DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form at, type, false, false, data))) {
4325 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 4341 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
4326 return; 4342 return;
4327 } 4343 }
4328 } 4344 }
4329 resetUnpackParameters(); 4345 resetUnpackParameters();
4330 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->heigh t(), 0, format, type, needConversion ? data.data() : pixelData.get()); 4346 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->heigh t(), 0, format, type, needConversion ? data.data() : pixelDataPtr);
4331 restoreUnpackParameters(); 4347 restoreUnpackParameters();
4332 } 4348 }
4333 4349
4334 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat) 4350 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat)
4335 { 4351 {
4336 if (isContextLost()) 4352 if (isContextLost())
4337 return; 4353 return;
4338 if (!validateTextureBinding("texParameter", target)) 4354 if (!validateTextureBinding("texParameter", target))
4339 return; 4355 return;
4340 switch (pname) { 4356 switch (pname) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
4475 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4491 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4476 type = GL_FLOAT; 4492 type = GL_FLOAT;
4477 } 4493 }
4478 Vector<uint8_t> data; 4494 Vector<uint8_t> data;
4479 bool needConversion = true; 4495 bool needConversion = true;
4480 // The data from ImageData is always of format RGBA8. 4496 // The data from ImageData is always of format RGBA8.
4481 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4497 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4482 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 4498 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
4483 needConversion = false; 4499 needConversion = false;
4484 } else { 4500 } else {
4485 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4501 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u npackFlipY, m_unpackPremultiplyAlpha, data)) {
4486 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4502 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4487 return; 4503 return;
4488 } 4504 }
4489 } 4505 }
4490 resetUnpackParameters(); 4506 resetUnpackParameters();
4491 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->width(), pixels->height(), format, type, needConversion ? data.data() : pixels->data()-> data()); 4507 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->width(), pixels->height(), format, type, needConversion ? data.data() : pixels->data()-> data());
4492 restoreUnpackParameters(); 4508 restoreUnpackParameters();
4493 } 4509 }
4494 4510
4495 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4511 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
4573 return; 4589 return;
4574 if (!validateTexture2DBinding("texSubImage2D", target)) 4590 if (!validateTexture2DBinding("texSubImage2D", target))
4575 return; 4591 return;
4576 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceImageBitmap, target , level, 0, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0)) 4592 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceImageBitmap, target , level, 0, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0))
4577 return; 4593 return;
4578 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4594 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4579 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4595 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4580 type = GL_FLOAT; 4596 type = GL_FLOAT;
4581 } 4597 }
4582 ASSERT(bitmap->bitmapImage()); 4598 ASSERT(bitmap->bitmapImage());
4583 OwnPtr<uint8_t[]> pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied () ? PremultiplyAlpha : DontPremultiplyAlpha); 4599 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame();
4600 SkPixmap pixmap;
4601 OwnPtr<uint8_t[]> pixelData;
4602 uint8_t* pixelDataPtr = nullptr;
4603 bool peekSucceed = skImage->peekPixels(&pixmap);
4604 if (peekSucceed) {
4605 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr());
4606 } else if (skImage->isTextureBacked()) {
4607 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip lyAlpha : DontPremultiplyAlpha);
4608 pixelDataPtr = pixelData.get();
4609 }
4584 Vector<uint8_t> data; 4610 Vector<uint8_t> data;
4585 bool needConversion = true; 4611 bool needConversion = true;
4586 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 4612 bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::k RGBA_8888_SkColorType);
4613 bool isPixelDataRBGA = (havePeekableRGBA || !peekSucceed);
4614 if (isPixelDataRBGA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
4587 needConversion = false; 4615 needConversion = false;
4588 } else { 4616 } else {
4589 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha. 4617 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha.
4590 if (!WebGLImageConversion::extractImageData(pixelData.get(), bitmap->siz e(), format, type, false, false, data)) { 4618 bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType ::kBGRA_8888_SkColorType);
4619 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data))
4620 || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixel DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form at, type, false, false, data))) {
4591 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4621 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4592 return; 4622 return;
4593 } 4623 }
4594 } 4624 }
4595 resetUnpackParameters(); 4625 resetUnpackParameters();
4596 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->width(), bitmap->height(), format, type, needConversion ? data.data() : pixelData.get()) ; 4626 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->width(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr);
4597 restoreUnpackParameters(); 4627 restoreUnpackParameters();
4598 } 4628 }
4599 4629
4600 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) 4630 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
4601 { 4631 {
4602 if (isContextLost() || !location) 4632 if (isContextLost() || !location)
4603 return; 4633 return;
4604 4634
4605 if (location->program() != m_currentProgram) { 4635 if (location->program() != m_currentProgram) {
4606 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program"); 4636 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program");
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
6394 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6424 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6395 } 6425 }
6396 6426
6397 void WebGLRenderingContextBase::restoreUnpackParameters() 6427 void WebGLRenderingContextBase::restoreUnpackParameters()
6398 { 6428 {
6399 if (m_unpackAlignment != 1) 6429 if (m_unpackAlignment != 1)
6400 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6430 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6401 } 6431 }
6402 6432
6403 } // namespace blink 6433 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698