AcagiBitmapTexture.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  3. Copyright (C) 2014 Sony Computer Entertainment Inc.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef AcagiBitmapTexture_h
  18. #define AcagiBitmapTexture_h
  19. #if USE(ACCELERATED_COMPOSITING) && USE(ACAGI)
  20. #include "AcagiPlatformTexture.h"
  21. #include "GraphicsContext.h"
  22. #include "IntRect.h"
  23. #include "IntSize.h"
  24. #include "TransformationMatrix.h"
  25. #include <wtf/Noncopyable.h>
  26. namespace WebCore {
  27. class GraphicsLayer;
  28. class AcagiCompositor;
  29. // A 2D texture
  30. class AcagiBitmapTexture : public RefCounted<AcagiBitmapTexture> {
  31. WTF_MAKE_NONCOPYABLE(AcagiBitmapTexture)
  32. typedef AcagiPlatformTexture PlatformTexture;
  33. public:
  34. enum Flag {
  35. SupportsAlpha = 0x01
  36. };
  37. enum UpdateContentsFlag {
  38. UpdateCanModifyOriginalImageData,
  39. UpdateCannotModifyOriginalImageData
  40. };
  41. typedef unsigned Flags;
  42. AcagiBitmapTexture(AcagiCompositor*);
  43. ~AcagiBitmapTexture();
  44. IntSize size() const;
  45. void updateContents(Image*, const IntRect&, const IntPoint& offset, UpdateContentsFlag);
  46. void updateContents(AcagiCompositor*, GraphicsLayer*, const IntRect& targetRect, const IntPoint& targetOffset, const FloatRect& sourceRect, UpdateContentsFlag);
  47. void updateContents(const void*, const IntRect& target, const IntPoint& offset, int bytesPerLine, UpdateContentsFlag);
  48. bool isValid() const;
  49. inline Flags flags() const { return m_flags; }
  50. int bpp() const;
  51. bool canReuseWith(const IntSize& contentsSize, Flags = 0);
  52. void reset(const IntSize& size, Flags flags = 0)
  53. {
  54. m_flags = flags;
  55. m_contentSize = size;
  56. didReset();
  57. }
  58. void didReset();
  59. void duplicate(const AcagiBitmapTexture&);
  60. inline IntSize contentSize() const { return m_contentSize; }
  61. inline int numberOfBytes() const { return size().width() * size().height() * bpp() >> 3; }
  62. inline bool isOpaque() const { return !(m_flags & SupportsAlpha); }
  63. PassRefPtr<PlatformTexture> platformTexture() const { return m_texture; }
  64. private:
  65. IntSize textureSize() const { return m_texture ? m_texture->textureSize() : IntSize(); }
  66. void resetTexture(const IntSize& newSize);
  67. private:
  68. Flags m_flags;
  69. IntSize m_contentSize;
  70. AcagiCompositor* m_compositor;
  71. RefPtr<PlatformTexture> m_texture;
  72. bool m_shouldClear;
  73. };
  74. }
  75. #endif
  76. #endif