SurfacePool.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2010, 2011, 2012, 2013 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser 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. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef SurfacePool_h
  19. #define SurfacePool_h
  20. #include "BackingStoreTile.h"
  21. #include "GraphicsContext.h"
  22. #include <BlackBerryPlatformGraphics.h>
  23. #include <BlackBerryPlatformPrimitives.h>
  24. #include <pthread.h>
  25. #include <set>
  26. #include <wtf/Vector.h>
  27. namespace BlackBerry {
  28. namespace WebKit {
  29. class SurfacePool {
  30. public:
  31. static SurfacePool* globalSurfacePool();
  32. void initialize(const BlackBerry::Platform::IntSize&);
  33. int isActive() const { return !m_tileBufferPool.isEmpty() && !m_buffersSuspended; }
  34. int isEmpty() const { return m_tileBufferPool.isEmpty(); }
  35. int numberOfBackingStoreFrontBuffers() const;
  36. PlatformGraphicsContext* createPlatformGraphicsContext(BlackBerry::Platform::Graphics::Drawable*) const;
  37. void destroyPlatformGraphicsContext(PlatformGraphicsContext*) const;
  38. // The surface pool will allocate as many back buffers as specified by
  39. // Platform::Settings::instance()->numberOfBackingStoreBackBuffers() which
  40. // allows for at least one back buffer to be available for drawing before
  41. // swapping buffers/geometry to the front.
  42. unsigned numberOfAvailableBackBuffers() const;
  43. TileBuffer* takeBackBuffer();
  44. void addBackBuffer(TileBuffer*);
  45. void releaseBuffers();
  46. void createBuffers();
  47. // EGLImage synchronization between WebKit and compositing threads
  48. // TODO: Figure out how to improve the BlackBerry::Platform::Graphics with API that can encapsulate
  49. // this kind of synchronisation mechanism.
  50. // WebKit thread must waitForBuffer() before rendering to EGLImage
  51. void waitForBuffer(TileBuffer*);
  52. // Compositing thread must notify the SurfacePool when EGLImages are composited
  53. void notifyBuffersComposited(const WTF::Vector<TileBuffer*>& buffers);
  54. void destroyPlatformSync(void* platformSync);
  55. private:
  56. SurfacePool();
  57. typedef WTF::Vector<TileBuffer*> TileBufferList;
  58. TileBufferList m_tileBufferPool;
  59. TileBufferList m_availableBackBufferPool;
  60. unsigned m_numberOfFrontBuffers;
  61. bool m_initialized; // SurfacePool has been set up, with or without buffers.
  62. bool m_buffersSuspended; // Buffer objects exist, but pixel memory has been freed.
  63. std::set<void*> m_garbage;
  64. bool m_hasFenceExtension;
  65. mutable pthread_mutex_t m_mutex;
  66. };
  67. }
  68. }
  69. #endif // SurfacePool_h