| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #if USE(ACCELERATED_COMPOSITING) | |
| 8 | |
| 9 #include "LayerTextureSubImage.h" | |
| 10 | |
| 11 #include "CCRendererGL.h" // For the GLC() macro. | |
| 12 #include "GraphicsContext3D.h" | |
| 13 #include "Extensions3DChromium.h" | |
| 14 #include "TraceEvent.h" | |
| 15 #include <public/WebGraphicsContext3D.h> | |
| 16 | |
| 17 using WebKit::WebGraphicsContext3D; | |
| 18 | |
| 19 namespace cc { | |
| 20 | |
| 21 LayerTextureSubImage::LayerTextureSubImage(bool useMapTexSubImage) | |
| 22 : m_useMapTexSubImage(useMapTexSubImage) | |
| 23 , m_subImageSize(0) | |
| 24 { | |
| 25 } | |
| 26 | |
| 27 LayerTextureSubImage::~LayerTextureSubImage() | |
| 28 { | |
| 29 } | |
| 30 | |
| 31 void LayerTextureSubImage::upload(const uint8_t* image, const IntRect& imageRect
, | |
| 32 const IntRect& sourceRect, const IntSize& dest
Offset, | |
| 33 GC3Denum format, WebGraphicsContext3D* context
) | |
| 34 { | |
| 35 if (m_useMapTexSubImage) | |
| 36 uploadWithMapTexSubImage(image, imageRect, sourceRect, destOffset, forma
t, context); | |
| 37 else | |
| 38 uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format,
context); | |
| 39 } | |
| 40 | |
| 41 void LayerTextureSubImage::uploadWithTexSubImage(const uint8_t* image, const Int
Rect& imageRect, | |
| 42 const IntRect& sourceRect, cons
t IntSize& destOffset, | |
| 43 GC3Denum format, WebGraphicsCon
text3D* context) | |
| 44 { | |
| 45 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithTexSubImage"); | |
| 46 | |
| 47 // Offset from image-rect to source-rect. | |
| 48 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); | |
| 49 | |
| 50 const uint8_t* pixelSource; | |
| 51 if (imageRect.width() == sourceRect.width() && !offset.x()) | |
| 52 pixelSource = &image[4 * offset.y() * imageRect.width()]; | |
| 53 else { | |
| 54 size_t neededSize = 4 * sourceRect.width() * sourceRect.height(); | |
| 55 if (m_subImageSize < neededSize) { | |
| 56 m_subImage = adoptArrayPtr(new uint8_t[neededSize]); | |
| 57 m_subImageSize = neededSize; | |
| 58 } | |
| 59 // Strides not equal, so do a row-by-row memcpy from the | |
| 60 // paint results into a temp buffer for uploading. | |
| 61 for (int row = 0; row < sourceRect.height(); ++row) | |
| 62 memcpy(&m_subImage[sourceRect.width() * 4 * row], | |
| 63 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], | |
| 64 sourceRect.width() * 4); | |
| 65 | |
| 66 pixelSource = &m_subImage[0]; | |
| 67 } | |
| 68 | |
| 69 GLC(context, context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, destOf
fset.width(), destOffset.height(), sourceRect.width(), sourceRect.height(), form
at, GraphicsContext3D::UNSIGNED_BYTE, pixelSource)); | |
| 70 } | |
| 71 | |
| 72 void LayerTextureSubImage::uploadWithMapTexSubImage(const uint8_t* image, const
IntRect& imageRect, | |
| 73 const IntRect& sourceRect, c
onst IntSize& destOffset, | |
| 74 GC3Denum format, WebGraphics
Context3D* context) | |
| 75 { | |
| 76 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithMapTexSubImage"); | |
| 77 // Offset from image-rect to source-rect. | |
| 78 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); | |
| 79 | |
| 80 // Upload tile data via a mapped transfer buffer | |
| 81 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)); | |
| 82 | |
| 83 if (!pixelDest) { | |
| 84 uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format,
context); | |
| 85 return; | |
| 86 } | |
| 87 | |
| 88 unsigned int componentsPerPixel = 0; | |
| 89 switch (format) { | |
| 90 case GraphicsContext3D::RGBA: | |
| 91 case Extensions3D::BGRA_EXT: | |
| 92 componentsPerPixel = 4; | |
| 93 break; | |
| 94 case GraphicsContext3D::LUMINANCE: | |
| 95 componentsPerPixel = 1; | |
| 96 break; | |
| 97 default: | |
| 98 ASSERT_NOT_REACHED(); | |
| 99 } | |
| 100 unsigned int bytesPerComponent = 1; | |
| 101 | |
| 102 if (imageRect.width() == sourceRect.width() && !offset.x()) | |
| 103 memcpy(pixelDest, &image[offset.y() * imageRect.width() * componentsPerP
ixel * bytesPerComponent], imageRect.width() * sourceRect.height() * componentsP
erPixel * bytesPerComponent); | |
| 104 else { | |
| 105 // Strides not equal, so do a row-by-row memcpy from the | |
| 106 // paint results into the pixelDest | |
| 107 for (int row = 0; row < sourceRect.height(); ++row) | |
| 108 memcpy(&pixelDest[sourceRect.width() * row * componentsPerPixel * by
tesPerComponent], | |
| 109 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], | |
| 110 sourceRect.width() * componentsPerPixel * bytesPerComponent); | |
| 111 } | |
| 112 GLC(context, context->unmapTexSubImage2DCHROMIUM(pixelDest)); | |
| 113 } | |
| 114 | |
| 115 } // namespace cc | |
| 116 | |
| 117 #endif // USE(ACCELERATED_COMPOSITING) | |
| OLD | NEW |