#ifndef RenderQueue_h
#define RenderQueue_h
#include <BlackBerryPlatformIntRectRegion.h>
#include <BlackBerryPlatformPrimitives.h>
#include <vector>
namespace BlackBerry {
namespace WebKit {
class BackingStorePrivate;
typedef std::vector<Platform::IntRect> IntRectList;
enum SortDirection {
LeftToRight = 0,
RightToLeft,
TopToBottom,
BottomToTop,
NumSortDirections
};
class RenderRect : public Platform::IntRect {
public:
RenderRect() { }
RenderRect(const Platform::IntPoint& location, const Platform::IntSize&, int splittingFactor);
RenderRect(int x, int y, int width, int height, int splittingFactor);
RenderRect(const Platform::IntRect&);
Platform::IntRect rectForRendering();
bool isCompleted() const { return !m_subRects.size(); }
const IntRectList& subRects() const { return m_subRects; }
void updateSortDirection(SortDirection primary, SortDirection secondary);
private:
void initialize(int splittingFactor);
void split();
void quickSort();
int m_splittingFactor;
IntRectList m_subRects;
SortDirection m_primarySortDirection;
SortDirection m_secondarySortDirection;
};
typedef std::vector<RenderRect> RenderRectList;
class RenderQueue {
public:
enum JobType { VisibleZoom, VisibleScroll, RegularRender, NonVisibleScroll };
RenderQueue(BackingStorePrivate*);
void reset();
RenderRect convertToRenderRect(const Platform::IntRect&) const;
bool isEmpty(bool shouldPerformRegularRenderJobs = true) const;
bool hasCurrentRegularRenderJob() const;
bool hasCurrentVisibleZoomJob() const;
bool hasCurrentVisibleScrollJob() const;
bool isCurrentVisibleScrollJob(const Platform::IntRect&) const;
bool isCurrentVisibleScrollJobCompleted(const Platform::IntRect&) const;
bool isCurrentRegularRenderJob(const Platform::IntRect&) const;
bool currentRegularRenderJobBatchUnderPressure() const;
void setCurrentRegularRenderJobBatchUnderPressure(bool);
void eventQueueCycled();
void addToQueue(JobType, const Platform::IntRect&);
void addToQueue(JobType, const IntRectList&);
void updateSortDirection(int lastDeltaX, int lastDeltaY);
void visibleContentChanged(const Platform::IntRect&);
void clear(const Platform::IntRectRegion&, bool clearRegularRenderJobs);
void clear(const Platform::IntRect&, bool clearRegularRenderJobs);
void clearRegularRenderJobs(const Platform::IntRect&);
void clearVisibleZoom();
bool regularRenderJobsPreviouslyAttemptedButNotRendered(const Platform::IntRect&);
Platform::IntRectRegion regularRenderJobsNotRenderedRegion() const { return m_regularRenderJobsNotRenderedRegion; }
void render(bool shouldPerformRegularRenderJobs = true);
void renderAllCurrentRegularRenderJobs();
private:
void startRegularRenderJobBatchIfNeeded();
void renderVisibleZoomJob();
void renderVisibleScrollJob();
void renderRegularRenderJob();
void renderNonVisibleScrollJob();
void visibleScrollJobsCompleted(bool shouldBlit);
void nonVisibleScrollJobsCompleted();
void addToRegularQueue(const Platform::IntRect&);
void addToScrollZoomQueue(const RenderRect&, RenderRectList* queue);
void quickSort(RenderRectList*);
int splittingFactor(const Platform::IntRect&) const;
BackingStorePrivate* m_parent;
RenderRectList m_visibleZoomJobs;
RenderRectList m_visibleScrollJobs;
RenderRectList m_visibleScrollJobsCompleted;
RenderRectList m_nonVisibleScrollJobs;
RenderRectList m_nonVisibleScrollJobsCompleted;
Platform::IntRectRegion m_regularRenderJobsRegion;
IntRectList m_currentRegularRenderJobsBatch;
Platform::IntRectRegion m_currentRegularRenderJobsBatchRegion;
bool m_rectsAddedToRegularRenderJobsInCurrentCycle;
bool m_currentRegularRenderJobsBatchUnderPressure;
Platform::IntRectRegion m_regularRenderJobsNotRenderedRegion;
SortDirection m_primarySortDirection;
SortDirection m_secondarySortDirection;
};
} }
#endif // RenderQueue_h