BackingStoreTile.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2009, 2010, 2011, 2012 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 BackingStoreTile_h
  19. #define BackingStoreTile_h
  20. #include "BlackBerryPlatformIntRectRegion.h"
  21. #include "BlackBerryPlatformMisc.h"
  22. #include "BlackBerryPlatformPrimitives.h"
  23. #include <wtf/PassRefPtr.h>
  24. #include <wtf/RefCounted.h>
  25. #include <wtf/RefPtr.h>
  26. namespace BlackBerry {
  27. namespace Platform {
  28. namespace Graphics {
  29. struct Buffer;
  30. }
  31. }
  32. namespace WebKit {
  33. // Represents a fence that has been inserted into the command stream. You can wait on the corresponding platform sync
  34. // object to make sure that previous commands have been completed.
  35. // There is no reason to wait twice on the same platform sync object, so the only mechanism provided to access the sync
  36. // object will also clear it to prevent anyone from waiting again.
  37. // Fence is only refcounted on the compositing thread, so RefCounted will suffice, we don't need ThreadSafeRefCounted.
  38. class Fence : public RefCounted<Fence> {
  39. public:
  40. static PassRefPtr<Fence> create(void* platformSync = 0)
  41. {
  42. return adoptRef(new Fence(platformSync));
  43. }
  44. // Returns 0 if this fence is stale (someone already waited on it)
  45. // Otherwise returns the platform sync object and clears the sync
  46. // object so no-one waits again.
  47. void* takePlatformSync()
  48. {
  49. void* tmp = m_platformSync;
  50. m_platformSync = 0;
  51. return tmp;
  52. }
  53. ~Fence();
  54. private:
  55. Fence(void* platformSync)
  56. : m_platformSync(platformSync)
  57. {
  58. }
  59. void* m_platformSync;
  60. };
  61. class TileBuffer {
  62. public:
  63. TileBuffer(const Platform::IntSize&);
  64. ~TileBuffer();
  65. Platform::IntSize size() const;
  66. Platform::IntRect surfaceRect() const;
  67. Platform::IntRect pixelContentsRect() const;
  68. Platform::IntPoint lastRenderOrigin() const { return m_lastRenderOrigin; }
  69. void setLastRenderOrigin(const Platform::IntPoint& origin) { m_lastRenderOrigin = origin; }
  70. double lastRenderScale() const { return m_lastRenderScale; }
  71. void setLastRenderScale(double scale) { m_lastRenderScale = scale; }
  72. bool isRendered(double scale) const;
  73. bool isRendered(const Platform::IntRectRegion& pixelContentsRegion, double scale) const;
  74. void clearRenderedRegion();
  75. void clearRenderedRegion(const Platform::IntRectRegion&);
  76. void addRenderedRegion(const Platform::IntRectRegion&);
  77. Platform::IntRectRegion renderedRegion() const;
  78. Platform::IntRectRegion notRenderedRegion() const;
  79. Platform::Graphics::Buffer* nativeBuffer() const;
  80. bool wasNativeBufferCreated() const;
  81. bool backgroundPainted() const { return m_backgroundPainted; }
  82. void paintBackground();
  83. Fence* fence() const { return m_fence.get(); }
  84. void setFence(PassRefPtr<Fence> fence) { m_fence = fence; }
  85. private:
  86. Platform::IntPoint m_lastRenderOrigin;
  87. Platform::IntSize m_size;
  88. Platform::IntRectRegion m_renderedRegion;
  89. RefPtr<Fence> m_fence;
  90. mutable Platform::Graphics::Buffer* m_nativeBuffer;
  91. double m_lastRenderScale;
  92. bool m_backgroundPainted;
  93. DISABLE_COPY(TileBuffer)
  94. };
  95. } // namespace WebKit
  96. } // namespace BlackBerry
  97. #endif // BackingStoreTile_h