OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions |
| 6 * are met: |
| 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. |
| 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ |
| 25 |
| 26 #include "config.h" |
| 27 |
| 28 #if USE(ACCELERATED_COMPOSITING) |
| 29 |
| 30 #include "LayerTextureSubImage.h" |
| 31 |
| 32 #include "Extensions3DChromium.h" |
| 33 #include "LayerRendererChromium.h" // For GLC() macro |
| 34 #include "TraceEvent.h" |
| 35 #include "cc/CCGraphicsContext.h" |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 LayerTextureSubImage::LayerTextureSubImage(bool useMapTexSubImage) |
| 40 : m_useMapTexSubImage(useMapTexSubImage) |
| 41 { |
| 42 } |
| 43 |
| 44 LayerTextureSubImage::~LayerTextureSubImage() |
| 45 { |
| 46 } |
| 47 |
| 48 void LayerTextureSubImage::setSubImageSize(const IntSize& subImageSize) |
| 49 { |
| 50 if (subImageSize == m_subImageSize) |
| 51 return; |
| 52 |
| 53 m_subImageSize = subImageSize; |
| 54 m_subImage.clear(); |
| 55 } |
| 56 |
| 57 void LayerTextureSubImage::upload(const uint8_t* image, const IntRect& imageRect
, |
| 58 const IntRect& sourceRect, const IntRect& dest
Rect, |
| 59 GC3Denum format, CCGraphicsContext* context) |
| 60 { |
| 61 if (m_useMapTexSubImage) |
| 62 uploadWithMapTexSubImage(image, imageRect, sourceRect, destRect, format,
context); |
| 63 else |
| 64 uploadWithTexSubImage(image, imageRect, sourceRect, destRect, format, co
ntext); |
| 65 } |
| 66 |
| 67 void LayerTextureSubImage::uploadWithTexSubImage(const uint8_t* image, const Int
Rect& imageRect, |
| 68 const IntRect& sourceRect, cons
t IntRect& destRect, |
| 69 GC3Denum format, CCGraphicsCont
ext* context) |
| 70 { |
| 71 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithTexSubImage"); |
| 72 if (!m_subImage) |
| 73 m_subImage = adoptArrayPtr(new uint8_t[m_subImageSize.width() * m_subIma
geSize.height() * 4]); |
| 74 |
| 75 // Offset from image-rect to source-rect. |
| 76 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); |
| 77 |
| 78 const uint8_t* pixelSource; |
| 79 if (imageRect.width() == sourceRect.width() && !offset.x()) |
| 80 pixelSource = &image[4 * offset.y() * imageRect.width()]; |
| 81 else { |
| 82 // Strides not equal, so do a row-by-row memcpy from the |
| 83 // paint results into a temp buffer for uploading. |
| 84 for (int row = 0; row < destRect.height(); ++row) |
| 85 memcpy(&m_subImage[destRect.width() * 4 * row], |
| 86 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], |
| 87 destRect.width() * 4); |
| 88 |
| 89 pixelSource = &m_subImage[0]; |
| 90 } |
| 91 |
| 92 WebKit::WebGraphicsContext3D* context3d = context->context3D(); |
| 93 if (!context3d) { |
| 94 // FIXME: Implement this path for software compositing. |
| 95 return; |
| 96 } |
| 97 GLC(context3d, context3d->texSubImage2D(GL_TEXTURE_2D, 0, destRect.x(), dest
Rect.y(), destRect.width(), destRect.height(), format, GL_UNSIGNED_BYTE, pixelSo
urce)); |
| 98 } |
| 99 |
| 100 void LayerTextureSubImage::uploadWithMapTexSubImage(const uint8_t* image, const
IntRect& imageRect, |
| 101 const IntRect& sourceRect, c
onst IntRect& destRect, |
| 102 GC3Denum format, CCGraphicsC
ontext* context) |
| 103 { |
| 104 TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithMapTexSubImage"); |
| 105 WebKit::WebGraphicsContext3D* context3d = context->context3D(); |
| 106 if (!context3d) { |
| 107 // FIXME: Implement this path for software compositing. |
| 108 return; |
| 109 } |
| 110 |
| 111 // Offset from image-rect to source-rect. |
| 112 IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y
()); |
| 113 |
| 114 // Upload tile data via a mapped transfer buffer |
| 115 uint8_t* pixelDest = static_cast<uint8_t*>(context3d->mapTexSubImage2DCHROMI
UM(GL_TEXTURE_2D, 0, destRect.x(), destRect.y(), destRect.width(), destRect.heig
ht(), format, GL_UNSIGNED_BYTE, GL_WRITE_ONLY)); |
| 116 |
| 117 if (!pixelDest) { |
| 118 uploadWithTexSubImage(image, imageRect, sourceRect, destRect, format, co
ntext); |
| 119 return; |
| 120 } |
| 121 |
| 122 unsigned int componentsPerPixel = 4; |
| 123 unsigned int bytesPerComponent = 1; |
| 124 |
| 125 if (imageRect.width() == sourceRect.width() && !offset.x()) |
| 126 memcpy(pixelDest, &image[offset.y() * imageRect.width() * componentsPerP
ixel * bytesPerComponent], imageRect.width() * destRect.height() * componentsPer
Pixel * bytesPerComponent); |
| 127 else { |
| 128 // Strides not equal, so do a row-by-row memcpy from the |
| 129 // paint results into the pixelDest |
| 130 for (int row = 0; row < destRect.height(); ++row) |
| 131 memcpy(&pixelDest[destRect.width() * row * componentsPerPixel * byte
sPerComponent], |
| 132 &image[4 * (offset.x() + (offset.y() + row) * imageRect.width
())], |
| 133 destRect.width() * componentsPerPixel * bytesPerComponent); |
| 134 } |
| 135 GLC(context3d, context3d->unmapTexSubImage2DCHROMIUM(pixelDest)); |
| 136 } |
| 137 |
| 138 } // namespace WebCore |
| 139 |
| 140 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |