#ifndef BackingStore_p_h
#define BackingStore_p_h
#include "BackingStore.h"
#include "Color.h"
#include "RenderQueue.h"
#include "TileIndex.h"
#include "TileIndexHash.h"
#include "Timer.h"
#include <BlackBerryPlatformGraphics.h>
#include <BlackBerryPlatformGuardedPointer.h>
#include <pthread.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
namespace WebCore {
class IntRect;
class FloatPoint;
class FloatRect;
class LayerRenderer;
class TransformationMatrix;
}
namespace BlackBerry {
namespace Platform {
class ViewportAccessor;
}
namespace WebKit {
class TileBuffer;
class WebPage;
class BackingStoreClient;
typedef WTF::HashMap<TileIndex, TileBuffer*> TileMap;
class BackingStoreGeometry {
public:
BackingStoreGeometry()
: m_numberOfTilesWide(0)
, m_numberOfTilesHigh(0)
, m_scale(0.0)
{
}
Platform::IntRect backingStoreRect() const;
Platform::IntSize backingStoreSize() const;
int numberOfTilesWide() const { return m_numberOfTilesWide; }
void setNumberOfTilesWide(int numberOfTilesWide) { m_numberOfTilesWide = numberOfTilesWide; }
int numberOfTilesHigh() const { return m_numberOfTilesHigh; }
void setNumberOfTilesHigh(int numberOfTilesHigh) { m_numberOfTilesHigh = numberOfTilesHigh; }
Platform::IntPoint backingStoreOffset() const { return m_backingStoreOffset; }
void setBackingStoreOffset(const Platform::IntPoint& offset) { m_backingStoreOffset = offset; }
Platform::IntPoint originOfTile(const TileIndex&) const;
TileBuffer* tileBufferAt(const TileIndex& index) const { return m_tileMap.get(index); }
const TileMap& tileMap() const { return m_tileMap; }
void setTileMap(const TileMap& tileMap) { m_tileMap = tileMap; }
double scale() const { return m_scale; }
void setScale(double scale) { m_scale = scale; }
bool isTileCorrespondingToBuffer(TileIndex, TileBuffer*) const;
private:
int m_numberOfTilesWide;
int m_numberOfTilesHigh;
double m_scale;
Platform::IntPoint m_backingStoreOffset;
TileMap m_tileMap;
};
class BackingStorePrivate : public BlackBerry::Platform::GuardedPointerBase {
public:
enum TileMatrixDirection { Horizontal, Vertical };
BackingStorePrivate();
void instrumentBeginFrame();
void instrumentCancelFrame();
bool isOpenGLCompositing() const;
void suspendBackingStoreUpdates();
void resumeBackingStoreUpdates();
void suspendGeometryUpdates();
void resumeGeometryUpdates();
void suspendScreenUpdates();
void resumeScreenUpdates(BackingStore::ResumeUpdateOperation);
void updateSuspendScreenUpdateState(bool* hasSyncedToUserInterfaceThread = 0);
void repaint(const Platform::IntRect& windowRect, bool contentChanged, bool immediate);
void slowScroll(const Platform::IntSize& delta, const Platform::IntRect& windowRect, bool immediate);
void scroll(const Platform::IntSize& delta, const Platform::IntRect& scrollViewRect, const Platform::IntRect& clipRect);
void scrollingStartedHelper(const Platform::IntSize& delta);
bool shouldSuppressNonVisibleRegularRenderJobs() const;
bool shouldPerformRenderJobs() const;
bool shouldPerformRegularRenderJobs() const;
void dispatchRenderJob();
void renderJob();
Platform::IntSize expandedContentsSize() const;
Platform::IntRect expandedContentsRect() const;
Platform::IntRect visibleContentsRect() const;
void setBackingStoreRect(const Platform::IntRect&, double scale);
void updateTilesAfterBackingStoreRectChange();
TileIndexList indexesForBackingStoreRect(const Platform::IntRect&) const;
TileIndexList indexesForVisibleContentsRect(BackingStoreGeometry*) const;
TileIndex indexOfTile(const Platform::IntPoint& origin, const Platform::IntRect& backingStoreRect) const;
void clearAndUpdateTileOfNotRenderedRegion(const TileIndex&, TileBuffer*, const Platform::IntRectRegion&, BackingStoreGeometry*, bool update = true);
bool isCurrentVisibleJob(const TileIndex&, BackingStoreGeometry*) const;
void clearRenderedRegion(TileBuffer*, const Platform::IntRectRegion&);
Platform::IntRect nonOverscrolled(const Platform::IntRect& viewportRect, const Platform::IntRect& contentsRect);
Platform::IntRect enclosingTileRect(const Platform::IntRect& pixelContentsRect);
Platform::IntRect desiredBackingStoreRect(const Platform::IntRect& pixelViewportRect, const Platform::IntRect& maximumReasonableRect, int deltaX, int deltaY);
void mergeDesiredBackingStoreRect(const Platform::IntRect& desiredRect, const Platform::IntRect& pixelViewportForDesiredRect);
Platform::IntRect largestTileRectForDesiredRect(const Platform::IntRect& minimumRect, const Platform::IntRect& desiredRect);
void scrollBackingStore(int deltaX, int deltaY);
TileIndexList render(const TileIndexList&);
void requestLayoutIfNeeded() const;
void renderAndBlitVisibleContentsImmediately();
void renderAndBlitImmediately(const Platform::IntRect&);
void blitVisibleContents(bool force = false);
void blitOnIdle();
Platform::IntRect blitTileRect(TileBuffer*, const Platform::IntRect&, const Platform::IntPoint&, const WebCore::TransformationMatrix&, BackingStoreGeometry*);
#if USE(ACCELERATED_COMPOSITING)
void compositeContents(WebCore::LayerRenderer*, const WebCore::TransformationMatrix&, const WebCore::FloatRect& contents, bool contentsOpaque);
bool drawLayersOnCommitIfNeeded();
void willDrawLayersOnCommit() { m_needsDrawLayersOnCommit = false; }
#endif
void blitHorizontalScrollbar();
void blitVerticalScrollbar();
bool isTileVisible(const TileIndex&, BackingStoreGeometry*) const;
bool isTileVisible(const Platform::IntPoint&) const;
TileIndexList visibleTileIndexes(BackingStoreGeometry*) const;
Platform::IntRect tileVisibleContentsRect(const TileIndex&, BackingStoreGeometry*) const;
Platform::IntRect tileContentsRect(const TileIndex&, const Platform::IntRect&, BackingStoreGeometry*) const;
void resetRenderQueue();
void resetTiles();
void updateTiles(bool updateVisible, bool immediate);
void updateTilesForScrollOrNotRenderedRegion(bool checkLoading = true);
void updateTile(const Platform::IntPoint& tileOrigin, bool immediate);
typedef std::pair<TileIndex, Platform::IntRect> TileRect;
typedef WTF::Vector<TileRect> TileRectList;
TileRectList mapFromPixelContentsToTiles(const Platform::IntRect&, BackingStoreGeometry*) const;
void setTileMatrixNeedsUpdate() { m_tileMatrixNeedsUpdate = true; }
void updateTileMatrixIfNeeded();
void contentsSizeChanged(const Platform::IntSize&);
void scrollChanged(const Platform::IntPoint&);
void transformChanged();
void actualVisibleSizeChanged(const Platform::IntSize&);
void orientationChanged();
void setGeometryOfTileMatrix(int numberOfTilesWide, int numberOfTilesHigh);
void createSurfaces();
static int tileWidth();
static int tileHeight();
static Platform::IntSize tileSize();
enum LayersToRender { RenderRootLayer, RenderAllLayers };
bool renderContents(BlackBerry::Platform::Graphics::Buffer*, const BlackBerry::Platform::IntRect& dstRect, double scale, const BlackBerry::Platform::FloatPoint& documentScrollPosition, LayersToRender) const;
void blitToWindow(const Platform::IntRect& dstRect, const BlackBerry::Platform::Graphics::Buffer* srcBuffer, const Platform::IntRect& srcRect, BlackBerry::Platform::Graphics::BlendMode, unsigned char globalAlpha);
WebCore::Color webPageBackgroundColorUserInterfaceThread() const; void setWebPageBackgroundColor(const WebCore::Color&);
bool isScrollingOrZooming() const;
void setScrollingOrZooming(bool scrollingOrZooming, bool shouldBlit = true);
BackingStoreGeometry* frontState() const;
void adoptAsFrontState(BackingStoreGeometry* newFrontState);
static void setCurrentBackingStoreOwner(WebPage*);
static WebPage* currentBackingStoreOwner() { return BackingStorePrivate::s_currentBackingStoreOwner; }
bool isActive() const;
BlackBerry::Platform::IntSize surfaceSize() const;
BlackBerry::Platform::Graphics::Buffer* buffer() const;
void didRenderContent(const Platform::IntRectRegion& renderedRegion);
static WebPage* s_currentBackingStoreOwner;
unsigned m_suspendScreenUpdateCounterWebKitThread;
unsigned m_suspendBackingStoreUpdates;
unsigned m_suspendGeometryUpdates;
BackingStore::ResumeUpdateOperation m_resumeOperation;
bool m_suspendScreenUpdatesWebKitThread;
bool m_suspendScreenUpdatesUserInterfaceThread;
bool m_suspendRenderJobs;
bool m_suspendRegularRenderJobs;
bool m_tileMatrixContainsUsefulContent;
bool m_tileMatrixNeedsUpdate;
bool m_isScrollingOrZooming;
WebPage* m_webPage;
BackingStoreClient* m_client;
OwnPtr<RenderQueue> m_renderQueue;
bool m_hasBlitJobs;
WebCore::Color m_webPageBackgroundColor;
mutable unsigned m_frontState;
Platform::IntRect m_desiredBackingStoreRect;
Platform::IntPoint m_desiredBackingStoreRectViewportLocation;
double m_desiredBackingStoreRectScale;
#if USE(ACCELERATED_COMPOSITING)
mutable bool m_needsDrawLayersOnCommit; #endif
protected:
virtual ~BackingStorePrivate();
};
} }
#endif // BackingStore_p_h