SigreTexture.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2014 Sony Computer Entertainment Inc.
  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. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "SigreTexture.h"
  27. #if USE(ACCELERATED_COMPOSITING) && USE(ACAGI)
  28. #include <stdio.h>
  29. #define DBG_TRACE printf("%s %d\n", __PRETTY_FUNCTION__, __LINE__)
  30. namespace WebCore {
  31. PassRefPtr<SigreTexture> SigreTexture::create(Allocator* allocator, IntSize textureSize)
  32. {
  33. SigreTexture* texture = new SigreTexture(allocator, textureSize);
  34. return adoptRef(texture);
  35. }
  36. PassRefPtr<SigreTexture> SigreTexture::duplicate(PassRefPtr<SigreTexture> original)
  37. {
  38. SigreTexture* texture = new SigreTexture(original->m_allocator, original->textureSize());
  39. if (texture && texture->isValid() && original->isValid())
  40. memcpy(texture->m_texture.buffer, original->m_texture.buffer, texture->m_texture.stride * texture->m_texture.height);
  41. return adoptRef(texture);
  42. }
  43. SigreTexture::SigreTexture(Allocator* allocator, IntSize textureSize)
  44. : m_allocator(allocator)
  45. {
  46. ASSERT(m_allocator);
  47. m_texture = m_allocator->allocateTexture(tilebackend::IntSize(textureSize.width(), textureSize.height()), tilebackend::kARGB32);
  48. }
  49. SigreTexture::~SigreTexture()
  50. {
  51. m_allocator->freeTexture(m_texture);
  52. }
  53. void SigreTexture::updateContents(const void* srcData, const IntRect& targetRect, const IntPoint& sourceOffset, int bytesPerLine)
  54. {
  55. IntRect dstRect(IntPoint(), textureSize());
  56. dstRect.intersect(targetRect);
  57. uint8_t* dst = (uint8_t*)m_texture.buffer;
  58. uint8_t* src = (uint8_t*)srcData;
  59. if (!dstRect.x() && !sourceOffset.x() && dstRect.width() == m_texture.width && bytesPerLine == m_texture.stride) {
  60. dst += dstRect.y() * m_texture.stride;
  61. src += sourceOffset.y() * bytesPerLine;
  62. size_t copySize = dstRect.height() * bytesPerLine;
  63. memcpy(dst, src, copySize);
  64. return;
  65. }
  66. const int bpp = 4;
  67. dst += dstRect.x() * bpp + dstRect.y() * m_texture.stride;
  68. src += sourceOffset.x() * bpp + sourceOffset.y() * bytesPerLine;
  69. size_t copySize = dstRect.width() * bpp;
  70. for (int y = 0; y < dstRect.height(); y++) {
  71. memcpy(dst, src, copySize);
  72. dst += m_texture.stride;
  73. src += bytesPerLine;
  74. }
  75. }
  76. }
  77. #endif