WebCoordinatedSurface.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
  3. Copyright (C) 2012 Company 100, 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 WebCoordinatedSurface_h
  18. #define WebCoordinatedSurface_h
  19. #if USE(COORDINATED_GRAPHICS)
  20. #include "ShareableBitmap.h"
  21. #include <WebCore/CoordinatedSurface.h>
  22. #if USE(GRAPHICS_SURFACE)
  23. #include "GraphicsSurface.h"
  24. #endif
  25. namespace WebCore {
  26. class BitmapTexture;
  27. class GraphicsContext;
  28. }
  29. namespace WebKit {
  30. class WebCoordinatedSurface : public WebCore::CoordinatedSurface {
  31. public:
  32. class Handle {
  33. WTF_MAKE_NONCOPYABLE(Handle);
  34. public:
  35. Handle();
  36. void encode(CoreIPC::ArgumentEncoder&) const;
  37. static bool decode(CoreIPC::ArgumentDecoder&, Handle&);
  38. #if USE(GRAPHICS_SURFACE)
  39. WebCore::GraphicsSurfaceToken graphicsSurfaceToken() const { return m_graphicsSurfaceToken; }
  40. #endif
  41. private:
  42. friend class WebCoordinatedSurface;
  43. mutable ShareableBitmap::Handle m_bitmapHandle;
  44. #if USE(GRAPHICS_SURFACE)
  45. WebCore::GraphicsSurfaceToken m_graphicsSurfaceToken;
  46. #endif
  47. WebCore::IntSize m_size;
  48. WebCore::CoordinatedSurface::Flags m_flags;
  49. };
  50. // Create a new WebCoordinatedSurface, and allocate either a GraphicsSurface or a ShareableBitmap as backing.
  51. static PassRefPtr<WebCoordinatedSurface> create(const WebCore::IntSize&, Flags);
  52. // Create a shareable surface from a handle.
  53. static PassRefPtr<WebCoordinatedSurface> create(const Handle&);
  54. // Create a handle.
  55. bool createHandle(Handle&);
  56. virtual ~WebCoordinatedSurface();
  57. virtual WebCore::IntSize size() const OVERRIDE { return m_size; }
  58. virtual void paintToSurface(const WebCore::IntRect&, WebCore::CoordinatedSurface::Client*) OVERRIDE;
  59. #if USE(TEXTURE_MAPPER)
  60. virtual void copyToTexture(PassRefPtr<WebCore::BitmapTexture>, const WebCore::IntRect& target, const WebCore::IntPoint& sourceOffset) OVERRIDE;
  61. #endif
  62. private:
  63. WebCoordinatedSurface(const WebCore::IntSize&, Flags, PassRefPtr<ShareableBitmap>);
  64. virtual Flags flags() const OVERRIDE { return m_flags; }
  65. // Create a WebCoordinatedSurface referencing an existing ShareableBitmap.
  66. static PassRefPtr<WebCoordinatedSurface> create(const WebCore::IntSize&, Flags, PassRefPtr<ShareableBitmap>);
  67. PassOwnPtr<WebCore::GraphicsContext> createGraphicsContext(const WebCore::IntRect&);
  68. #if USE(GRAPHICS_SURFACE)
  69. WebCoordinatedSurface(const WebCore::IntSize&, Flags, PassRefPtr<WebCore::GraphicsSurface>);
  70. // Create a shareable bitmap backed by a graphics surface.
  71. static PassRefPtr<WebCoordinatedSurface> createWithSurface(const WebCore::IntSize&, Flags);
  72. // Create a WebCoordinatedSurface referencing an existing GraphicsSurface.
  73. static PassRefPtr<WebCoordinatedSurface> create(const WebCore::IntSize&, Flags, PassRefPtr<WebCore::GraphicsSurface>);
  74. bool isBackedByGraphicsSurface() const { return !!m_graphicsSurface; }
  75. #endif
  76. WebCore::IntSize m_size;
  77. Flags m_flags;
  78. RefPtr<ShareableBitmap> m_bitmap;
  79. #if USE(GRAPHICS_SURFACE)
  80. RefPtr<WebCore::GraphicsSurface> m_graphicsSurface;
  81. #endif
  82. };
  83. } // namespace WebKit
  84. #endif // USE(COORDINATED_GRAPHICS)
  85. #endif // WebCoordinatedSurface_h