| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer_texture_sub_image.h" | 7 #include "cc/layer_texture_sub_image.h" |
| 8 | 8 |
| 9 #include "CCRendererGL.h" // For the GLC() macro. | 9 #include "CCRendererGL.h" // For the GLC() macro. |
| 10 #include "GraphicsContext3D.h" | |
| 11 #include "Extensions3DChromium.h" | |
| 12 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "third_party/khronos/GLES2/gl2.h" |
| 12 #include "third_party/khronos/GLES2/gl2ext.h" |
| 13 #include <public/WebGraphicsContext3D.h> | 13 #include <public/WebGraphicsContext3D.h> |
| 14 | 14 |
| 15 using WebKit::WebGraphicsContext3D; | 15 using WebKit::WebGraphicsContext3D; |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 LayerTextureSubImage::LayerTextureSubImage(bool useMapTexSubImage) | 19 LayerTextureSubImage::LayerTextureSubImage(bool useMapTexSubImage) |
| 20 : m_useMapTexSubImage(useMapTexSubImage) | 20 : m_useMapTexSubImage(useMapTexSubImage) |
| 21 , m_subImageSize(0) | 21 , m_subImageSize(0) |
| 22 { | 22 { |
| 23 } | 23 } |
| 24 | 24 |
| 25 LayerTextureSubImage::~LayerTextureSubImage() | 25 LayerTextureSubImage::~LayerTextureSubImage() |
| 26 { | 26 { |
| 27 } | 27 } |
| 28 | 28 |
| 29 void LayerTextureSubImage::upload(const uint8_t* image, const IntRect& imageRect
, | 29 void LayerTextureSubImage::upload(const uint8_t* image, const IntRect& imageRect
, |
| 30 const IntRect& sourceRect, const IntSize& dest
Offset, | 30 const IntRect& sourceRect, const IntSize& dest
Offset, |
| 31 GC3Denum format, WebGraphicsContext3D* context
) | 31 GLenum format, WebGraphicsContext3D* context) |
| 32 { | 32 { |
| 33 if (m_useMapTexSubImage) | 33 if (m_useMapTexSubImage) |
| 34 uploadWithMapTexSubImage(image, imageRect, sourceRect, destOffset, forma
t, context); | 34 uploadWithMapTexSubImage(image, imageRect, sourceRect, destOffset, forma
t, context); |
| 35 else | 35 else |
| 36 uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format,
context); | 36 uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format,
context); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void LayerTextureSubImage::uploadWithTexSubImage(const uint8_t* image, const Int
Rect& imageRect, | 39 void LayerTextureSubImage::uploadWithTexSubImage(const uint8_t* image, const Int
Rect& imageRect, |
| 40 const IntRect& sourceRect, cons
t IntSize& destOffset, | 40 const IntRect& sourceRect, cons
t IntSize& destOffset, |
| 41 GC3Denum format, WebGraphicsCon
text3D* context) | 41 GLenum format, WebGraphicsConte
xt3D* context) |
| 42 { | 42 { |
| 43 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithTexSubImage"); | 43 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithTexSubImage"); |
| 44 | 44 |
| 45 // Offset from image-rect to source-rect. | 45 // Offset from image-rect to source-rect. |
| 46 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); | 46 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); |
| 47 | 47 |
| 48 const uint8_t* pixelSource; | 48 const uint8_t* pixelSource; |
| 49 if (imageRect.width() == sourceRect.width() && !offset.x()) | 49 if (imageRect.width() == sourceRect.width() && !offset.x()) |
| 50 pixelSource = &image[4 * offset.y() * imageRect.width()]; | 50 pixelSource = &image[4 * offset.y() * imageRect.width()]; |
| 51 else { | 51 else { |
| 52 size_t neededSize = 4 * sourceRect.width() * sourceRect.height(); | 52 size_t neededSize = 4 * sourceRect.width() * sourceRect.height(); |
| 53 if (m_subImageSize < neededSize) { | 53 if (m_subImageSize < neededSize) { |
| 54 m_subImage.reset(new uint8_t[neededSize]); | 54 m_subImage.reset(new uint8_t[neededSize]); |
| 55 m_subImageSize = neededSize; | 55 m_subImageSize = neededSize; |
| 56 } | 56 } |
| 57 // Strides not equal, so do a row-by-row memcpy from the | 57 // Strides not equal, so do a row-by-row memcpy from the |
| 58 // paint results into a temp buffer for uploading. | 58 // paint results into a temp buffer for uploading. |
| 59 for (int row = 0; row < sourceRect.height(); ++row) | 59 for (int row = 0; row < sourceRect.height(); ++row) |
| 60 memcpy(&m_subImage[sourceRect.width() * 4 * row], | 60 memcpy(&m_subImage[sourceRect.width() * 4 * row], |
| 61 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], | 61 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], |
| 62 sourceRect.width() * 4); | 62 sourceRect.width() * 4); |
| 63 | 63 |
| 64 pixelSource = &m_subImage[0]; | 64 pixelSource = &m_subImage[0]; |
| 65 } | 65 } |
| 66 | 66 |
| 67 GLC(context, context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, destOf
fset.width(), destOffset.height(), sourceRect.width(), sourceRect.height(), form
at, GraphicsContext3D::UNSIGNED_BYTE, pixelSource)); | 67 GLC(context, context->texSubImage2D(GL_TEXTURE_2D, 0, destOffset.width(), de
stOffset.height(), sourceRect.width(), sourceRect.height(), format, GL_UNSIGNED_
BYTE, pixelSource)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void LayerTextureSubImage::uploadWithMapTexSubImage(const uint8_t* image, const
IntRect& imageRect, | 70 void LayerTextureSubImage::uploadWithMapTexSubImage(const uint8_t* image, const
IntRect& imageRect, |
| 71 const IntRect& sourceRect, c
onst IntSize& destOffset, | 71 const IntRect& sourceRect, c
onst IntSize& destOffset, |
| 72 GC3Denum format, WebGraphics
Context3D* context) | 72 GLenum format, WebGraphicsCo
ntext3D* context) |
| 73 { | 73 { |
| 74 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithMapTexSubImage"); | 74 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithMapTexSubImage"); |
| 75 // Offset from image-rect to source-rect. | 75 // Offset from image-rect to source-rect. |
| 76 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); | 76 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); |
| 77 | 77 |
| 78 // Upload tile data via a mapped transfer buffer | 78 // Upload tile data via a mapped transfer buffer |
| 79 uint8_t* pixelDest = static_cast<uint8_t*>(context->mapTexSubImage2DCHROMIUM
(GraphicsContext3D::TEXTURE_2D, 0, destOffset.width(), destOffset.height(), sour
ceRect.width(), sourceRect.height(), format, GraphicsContext3D::UNSIGNED_BYTE, E
xtensions3DChromium::WRITE_ONLY)); | 79 uint8_t* pixelDest = static_cast<uint8_t*>(context->mapTexSubImage2DCHROMIUM
(GL_TEXTURE_2D, 0, destOffset.width(), destOffset.height(), sourceRect.width(),
sourceRect.height(), format, GL_UNSIGNED_BYTE, GL_WRITE_ONLY)); |
| 80 | 80 |
| 81 if (!pixelDest) { | 81 if (!pixelDest) { |
| 82 uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format,
context); | 82 uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format,
context); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 | 85 |
| 86 unsigned int componentsPerPixel = 0; | 86 unsigned int componentsPerPixel = 0; |
| 87 switch (format) { | 87 switch (format) { |
| 88 case GraphicsContext3D::RGBA: | 88 case GL_RGBA: |
| 89 case Extensions3D::BGRA_EXT: | 89 case GL_BGRA_EXT: |
| 90 componentsPerPixel = 4; | 90 componentsPerPixel = 4; |
| 91 break; | 91 break; |
| 92 case GraphicsContext3D::LUMINANCE: | 92 case GL_LUMINANCE: |
| 93 componentsPerPixel = 1; | 93 componentsPerPixel = 1; |
| 94 break; | 94 break; |
| 95 default: | 95 default: |
| 96 NOTREACHED(); | 96 NOTREACHED(); |
| 97 } | 97 } |
| 98 unsigned int bytesPerComponent = 1; | 98 unsigned int bytesPerComponent = 1; |
| 99 | 99 |
| 100 if (imageRect.width() == sourceRect.width() && !offset.x()) | 100 if (imageRect.width() == sourceRect.width() && !offset.x()) |
| 101 memcpy(pixelDest, &image[offset.y() * imageRect.width() * componentsPerP
ixel * bytesPerComponent], imageRect.width() * sourceRect.height() * componentsP
erPixel * bytesPerComponent); | 101 memcpy(pixelDest, &image[offset.y() * imageRect.width() * componentsPerP
ixel * bytesPerComponent], imageRect.width() * sourceRect.height() * componentsP
erPixel * bytesPerComponent); |
| 102 else { | 102 else { |
| 103 // Strides not equal, so do a row-by-row memcpy from the | 103 // Strides not equal, so do a row-by-row memcpy from the |
| 104 // paint results into the pixelDest | 104 // paint results into the pixelDest |
| 105 for (int row = 0; row < sourceRect.height(); ++row) | 105 for (int row = 0; row < sourceRect.height(); ++row) |
| 106 memcpy(&pixelDest[sourceRect.width() * row * componentsPerPixel * by
tesPerComponent], | 106 memcpy(&pixelDest[sourceRect.width() * row * componentsPerPixel * by
tesPerComponent], |
| 107 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], | 107 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], |
| 108 sourceRect.width() * componentsPerPixel * bytesPerComponent); | 108 sourceRect.width() * componentsPerPixel * bytesPerComponent); |
| 109 } | 109 } |
| 110 GLC(context, context->unmapTexSubImage2DCHROMIUM(pixelDest)); | 110 GLC(context, context->unmapTexSubImage2DCHROMIUM(pixelDest)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace cc | 113 } // namespace cc |
| OLD | NEW |