diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-25 00:09:14 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-25 00:09:14 +0000 |
commit | 94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679 (patch) | |
tree | 530f51d5c75459999e4adf2a6895884ce1c15ce0 /cc/LayerTextureSubImage.cpp | |
parent | 56235947f2b023fc63cfad692c56df4e92199848 (diff) | |
download | chromium_src-94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679.zip chromium_src-94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679.tar.gz chromium_src-94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679.tar.bz2 |
Here are gyp targets and stubs for compiling libcc and the webkit_compositor bindings in chromium. Everything is guarded behind the off-by-default use_libcc_for_compositor gyp variable. I haven't included the actual code here, but there are scripts to sync. I plan to land + manually sync the code into place until we're ready to flip the gyp switch.
Snapshot from r126652
BUG=
Review URL: https://chromiumcodereview.appspot.com/10828381
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153354 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/LayerTextureSubImage.cpp')
-rw-r--r-- | cc/LayerTextureSubImage.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/cc/LayerTextureSubImage.cpp b/cc/LayerTextureSubImage.cpp new file mode 100644 index 0000000..f555fa1 --- /dev/null +++ b/cc/LayerTextureSubImage.cpp @@ -0,0 +1,109 @@ +// Copyright 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" + +#if USE(ACCELERATED_COMPOSITING) + +#include "LayerTextureSubImage.h" + +#include "CCRendererGL.h" // For the GLC() macro. +#include "Extensions3DChromium.h" +#include "TraceEvent.h" +#include <public/WebGraphicsContext3D.h> + +using WebKit::WebGraphicsContext3D; + +namespace WebCore { + +LayerTextureSubImage::LayerTextureSubImage(bool useMapTexSubImage) + : m_useMapTexSubImage(useMapTexSubImage) + , m_subImageSize(0) +{ +} + +LayerTextureSubImage::~LayerTextureSubImage() +{ +} + +void LayerTextureSubImage::upload(const uint8_t* image, const IntRect& imageRect, + const IntRect& sourceRect, const IntSize& destOffset, + GC3Denum format, WebGraphicsContext3D* context) +{ + if (m_useMapTexSubImage) + uploadWithMapTexSubImage(image, imageRect, sourceRect, destOffset, format, context); + else + uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format, context); +} + +void LayerTextureSubImage::uploadWithTexSubImage(const uint8_t* image, const IntRect& imageRect, + const IntRect& sourceRect, const IntSize& destOffset, + GC3Denum format, WebGraphicsContext3D* context) +{ + TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithTexSubImage"); + + // Offset from image-rect to source-rect. + IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y()); + + const uint8_t* pixelSource; + if (imageRect.width() == sourceRect.width() && !offset.x()) + pixelSource = &image[4 * offset.y() * imageRect.width()]; + else { + size_t neededSize = 4 * sourceRect.width() * sourceRect.height(); + if (m_subImageSize < neededSize) { + m_subImage = adoptArrayPtr(new uint8_t[neededSize]); + m_subImageSize = neededSize; + } + // Strides not equal, so do a row-by-row memcpy from the + // paint results into a temp buffer for uploading. + for (int row = 0; row < sourceRect.height(); ++row) + memcpy(&m_subImage[sourceRect.width() * 4 * row], + &image[4 * (offset.x() + (offset.y() + row) * imageRect.width())], + sourceRect.width() * 4); + + pixelSource = &m_subImage[0]; + } + + GLC(context, context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, destOffset.width(), destOffset.height(), sourceRect.width(), sourceRect.height(), format, GraphicsContext3D::UNSIGNED_BYTE, pixelSource)); +} + +void LayerTextureSubImage::uploadWithMapTexSubImage(const uint8_t* image, const IntRect& imageRect, + const IntRect& sourceRect, const IntSize& destOffset, + GC3Denum format, WebGraphicsContext3D* context) +{ + TRACE_EVENT0("cc", "LayerTextureSubImage::uploadWithMapTexSubImage"); + // Offset from image-rect to source-rect. + IntPoint offset(sourceRect.x() - imageRect.x(), sourceRect.y() - imageRect.y()); + + // Upload tile data via a mapped transfer buffer + uint8_t* pixelDest = static_cast<uint8_t*>(context->mapTexSubImage2DCHROMIUM(GraphicsContext3D::TEXTURE_2D, 0, destOffset.width(), destOffset.height(), sourceRect.width(), sourceRect.height(), format, GraphicsContext3D::UNSIGNED_BYTE, Extensions3DChromium::WRITE_ONLY)); + + if (!pixelDest) { + uploadWithTexSubImage(image, imageRect, sourceRect, destOffset, format, context); + return; + } + + unsigned int componentsPerPixel; + unsigned int bytesPerComponent; + if (!GraphicsContext3D::computeFormatAndTypeParameters(format, GraphicsContext3D::UNSIGNED_BYTE, &componentsPerPixel, &bytesPerComponent)) { + ASSERT_NOT_REACHED(); + return; + } + + if (imageRect.width() == sourceRect.width() && !offset.x()) + memcpy(pixelDest, &image[offset.y() * imageRect.width() * componentsPerPixel * bytesPerComponent], imageRect.width() * sourceRect.height() * componentsPerPixel * bytesPerComponent); + else { + // Strides not equal, so do a row-by-row memcpy from the + // paint results into the pixelDest + for (int row = 0; row < sourceRect.height(); ++row) + memcpy(&pixelDest[sourceRect.width() * row * componentsPerPixel * bytesPerComponent], + &image[4 * (offset.x() + (offset.y() + row) * imageRect.width())], + sourceRect.width() * componentsPerPixel * bytesPerComponent); + } + GLC(context, context->unmapTexSubImage2DCHROMIUM(pixelDest)); +} + +} // namespace WebCore + +#endif // USE(ACCELERATED_COMPOSITING) |