WebOverlay_p.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Copyright (C) 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 WebOverlay_p_h
  19. #define WebOverlay_p_h
  20. #if USE(ACCELERATED_COMPOSITING)
  21. #include "GraphicsLayer.h"
  22. #include "LayerCompositingThread.h"
  23. #include "LayerTexture.h"
  24. #include "WebOverlay.h"
  25. #include "WebOverlayOverride.h"
  26. #include <TiledImage.h>
  27. #include <pthread.h>
  28. #include <wtf/OwnPtr.h>
  29. #include <wtf/RefPtr.h>
  30. namespace WTF {
  31. class String;
  32. }
  33. namespace WebCore {
  34. class Animation;
  35. class KeyframeValueList;
  36. }
  37. namespace BlackBerry {
  38. namespace WebKit {
  39. class WebOverlayClient;
  40. class WebPagePrivate;
  41. class WebOverlayPrivate {
  42. public:
  43. WebOverlayPrivate()
  44. : q(0)
  45. , parent(0)
  46. , m_page(0)
  47. {
  48. nativeThread = pthread_self();
  49. }
  50. virtual ~WebOverlayPrivate()
  51. {
  52. ASSERT(pthread_self() == nativeThread);
  53. }
  54. WebPagePrivate* page() const;
  55. void setPage(WebPagePrivate* page) { m_page = page; }
  56. void setClient(WebOverlayClient* c) { client = c; }
  57. WebOverlayOverride* override();
  58. virtual WebCore::FloatPoint position() const = 0;
  59. virtual void setPosition(const WebCore::FloatPoint&) = 0;
  60. virtual WebCore::FloatPoint anchorPoint() const = 0;
  61. virtual void setAnchorPoint(const WebCore::FloatPoint&) = 0;
  62. virtual WebCore::FloatSize size() const = 0;
  63. virtual void setSize(const WebCore::FloatSize&) = 0;
  64. virtual bool sizeIsScaleInvariant() const = 0;
  65. virtual void setSizeIsScaleInvariant(bool) = 0;
  66. virtual WebCore::TransformationMatrix transform() const = 0;
  67. virtual void setTransform(const WebCore::TransformationMatrix&) = 0;
  68. virtual float opacity() const = 0;
  69. virtual void setOpacity(float) = 0;
  70. virtual void addAnimation(const WTF::String& name, WebCore::Animation*, const WebCore::KeyframeValueList&) = 0;
  71. virtual void removeAnimation(const WTF::String&) = 0;
  72. virtual Platform::IntRect pixelViewportRect() const = 0;
  73. virtual void addChild(WebOverlayPrivate*) = 0;
  74. virtual void removeFromParent() = 0;
  75. virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize, WebOverlay::ImageDataAdoptionType) = 0;
  76. virtual void setContentsToColor(const WebCore::Color&) = 0;
  77. virtual void setDrawsContent(bool) = 0;
  78. virtual void clear() = 0;
  79. virtual void invalidate() = 0;
  80. void drawContents(Platform::Graphics::Drawable*);
  81. virtual void resetOverrides() = 0;
  82. void scheduleCompositingRun();
  83. // Never 0
  84. WebCore::LayerCompositingThread* layerCompositingThread() const { return m_layerCompositingThread.get(); }
  85. // Can be 0
  86. virtual WebCore::GraphicsLayer* graphicsLayer() const { return 0; }
  87. WebOverlay* q;
  88. WebOverlayClient* client;
  89. WebOverlay* parent;
  90. pthread_t nativeThread;
  91. protected:
  92. RefPtr<WebCore::LayerCompositingThread> m_layerCompositingThread;
  93. OwnPtr<WebOverlayOverride> m_override;
  94. WebPagePrivate* m_page;
  95. };
  96. class WebOverlayPrivateWebKitThread : public WebOverlayPrivate, public WebCore::GraphicsLayerClient {
  97. public:
  98. WebOverlayPrivateWebKitThread(WebCore::GraphicsLayerClient* = 0);
  99. virtual WebCore::FloatPoint position() const;
  100. virtual void setPosition(const WebCore::FloatPoint&);
  101. virtual WebCore::FloatPoint anchorPoint() const;
  102. virtual void setAnchorPoint(const WebCore::FloatPoint&);
  103. virtual WebCore::FloatSize size() const;
  104. virtual void setSize(const WebCore::FloatSize&);
  105. virtual bool sizeIsScaleInvariant() const;
  106. virtual void setSizeIsScaleInvariant(bool);
  107. virtual WebCore::TransformationMatrix transform() const;
  108. virtual void setTransform(const WebCore::TransformationMatrix&);
  109. virtual float opacity() const;
  110. virtual void setOpacity(float);
  111. virtual void addAnimation(const WTF::String& name, WebCore::Animation*, const WebCore::KeyframeValueList&);
  112. virtual void removeAnimation(const WTF::String& name);
  113. virtual Platform::IntRect pixelViewportRect() const;
  114. virtual void addChild(WebOverlayPrivate*);
  115. virtual void removeFromParent();
  116. virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize, WebOverlay::ImageDataAdoptionType);
  117. virtual void setContentsToColor(const WebCore::Color&);
  118. virtual void setDrawsContent(bool);
  119. virtual void clear();
  120. virtual void invalidate();
  121. virtual void resetOverrides();
  122. virtual WebCore::GraphicsLayer* graphicsLayer() const { return m_layer.get(); }
  123. // GraphicsLayerClient
  124. virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double) { }
  125. virtual void notifyFlushRequired(const WebCore::GraphicsLayer*);
  126. virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect&);
  127. private:
  128. OwnPtr<WebCore::GraphicsLayer> m_layer;
  129. };
  130. // The LayerCompositingThreadClient's life cycle is tied to the LayerCompositingThread,
  131. // so it needs to be a separate object from the WebOverlayPrivateCompositingThread.
  132. class WebOverlayLayerCompositingThreadClient : public WebCore::LayerCompositingThreadClient {
  133. public:
  134. WebOverlayLayerCompositingThreadClient(WebOverlayPrivate*);
  135. virtual ~WebOverlayLayerCompositingThreadClient() { }
  136. WebOverlayPrivate* overlay() const { return m_overlay; }
  137. void overlayDestroyed() { m_overlay = 0; }
  138. bool drawsContent() const { return m_drawsContent; }
  139. void setDrawsContent(bool);
  140. void invalidate();
  141. void setContentsToImage(const BlackBerry::Platform::Graphics::TiledImage&);
  142. void setContentsToColor(const WebCore::Color&);
  143. const BlackBerry::Platform::Graphics::TiledImage& image() const { return m_image; }
  144. // LayerCompositingThreadClient
  145. virtual void layerCompositingThreadDestroyed(WebCore::LayerCompositingThread*);
  146. virtual void layerVisibilityChanged(WebCore::LayerCompositingThread*, bool visible);
  147. virtual void uploadTexturesIfNeeded(WebCore::LayerCompositingThread*);
  148. virtual void drawTextures(WebCore::LayerCompositingThread*, const Platform::Graphics::GLES2Program&, double scale, const WebCore::FloatRect& clipRect);
  149. virtual void deleteTextures(WebCore::LayerCompositingThread*);
  150. private:
  151. void clearUploadedContents();
  152. private:
  153. bool m_drawsContent;
  154. RefPtr<WebCore::LayerTexture> m_texture;
  155. BlackBerry::Platform::Graphics::TiledImage m_image;
  156. BlackBerry::Platform::Graphics::TiledImage m_uploadedImage;
  157. WebCore::Color m_color;
  158. WebOverlayPrivate* m_overlay;
  159. };
  160. class WebOverlayPrivateCompositingThread : public WebOverlayPrivate {
  161. public:
  162. WebOverlayPrivateCompositingThread(PassRefPtr<WebCore::LayerCompositingThread>);
  163. WebOverlayPrivateCompositingThread();
  164. ~WebOverlayPrivateCompositingThread();
  165. virtual WebCore::FloatPoint position() const;
  166. virtual void setPosition(const WebCore::FloatPoint&);
  167. virtual WebCore::FloatPoint anchorPoint() const;
  168. virtual void setAnchorPoint(const WebCore::FloatPoint&);
  169. virtual WebCore::FloatSize size() const;
  170. virtual void setSize(const WebCore::FloatSize&);
  171. virtual bool sizeIsScaleInvariant() const;
  172. virtual void setSizeIsScaleInvariant(bool);
  173. virtual WebCore::TransformationMatrix transform() const;
  174. virtual void setTransform(const WebCore::TransformationMatrix&);
  175. virtual float opacity() const;
  176. virtual void setOpacity(float);
  177. virtual void addAnimation(const WTF::String& name, WebCore::Animation*, const WebCore::KeyframeValueList&);
  178. virtual void removeAnimation(const WTF::String& name);
  179. virtual Platform::IntRect pixelViewportRect() const;
  180. virtual void addChild(WebOverlayPrivate*);
  181. virtual void removeFromParent();
  182. virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize, WebOverlay::ImageDataAdoptionType);
  183. virtual void setContentsToColor(const WebCore::Color&);
  184. virtual void setDrawsContent(bool);
  185. virtual void clear();
  186. virtual void invalidate();
  187. virtual void resetOverrides();
  188. private:
  189. WebOverlayLayerCompositingThreadClient* m_layerCompositingThreadClient;
  190. const unsigned char* m_data;
  191. };
  192. }
  193. }
  194. #endif // USE(ACCELERATED_COMPOSITING)
  195. #endif // WebOverlay_p_h