RemoteLayerBackingStore.h [plain text]
#ifndef RemoteLayerBackingStore_h
#define RemoteLayerBackingStore_h
#include "ShareableBitmap.h"
#include <WebCore/FloatRect.h>
#include <WebCore/IOSurface.h>
#include <WebCore/Region.h>
#include <chrono>
OBJC_CLASS CALayer;
namespace WebCore {
typedef Vector<WebCore::FloatRect, 5> RepaintRectList;
}
namespace WebKit {
class PlatformCALayerRemote;
class RemoteLayerBackingStore {
WTF_MAKE_NONCOPYABLE(RemoteLayerBackingStore);
WTF_MAKE_FAST_ALLOCATED;
public:
RemoteLayerBackingStore(PlatformCALayerRemote*);
~RemoteLayerBackingStore();
void ensureBackingStore(WebCore::FloatSize, float scale, bool acceleratesDrawing, bool isOpaque);
void setNeedsDisplay(const WebCore::IntRect);
void setNeedsDisplay();
bool display();
WebCore::FloatSize size() const { return m_size; }
float scale() const { return m_scale; }
bool acceleratesDrawing() const { return m_acceleratesDrawing; }
bool isOpaque() const { return m_isOpaque; }
PlatformCALayerRemote* layer() const { return m_layer; }
void applyBackingStoreToLayer(CALayer *);
void encode(IPC::ArgumentEncoder&) const;
static bool decode(IPC::ArgumentDecoder&, RemoteLayerBackingStore&);
void enumerateRectsBeingDrawn(CGContextRef, void (^)(CGRect));
bool hasFrontBuffer() const
{
#if USE(IOSURFACE)
if (m_acceleratesDrawing)
return !!m_frontBuffer.surface;
#endif
return !!m_frontBuffer.bitmap;
}
RetainPtr<CGContextRef> takeFrontContextPendingFlush();
enum class BufferType {
Front,
Back,
SecondaryBack
};
bool setBufferVolatility(BufferType type, bool isVolatile);
std::chrono::steady_clock::time_point lastDisplayTime() const { return m_lastDisplayTime; }
private:
void drawInContext(WebCore::GraphicsContext&, CGImageRef backImage);
void clearBackingStore();
void swapToValidFrontBuffer();
PlatformCALayerRemote* m_layer;
WebCore::FloatSize m_size;
float m_scale;
bool m_isOpaque;
WebCore::Region m_dirtyRegion;
struct Buffer {
RefPtr<ShareableBitmap> bitmap;
#if USE(IOSURFACE)
RefPtr<WebCore::IOSurface> surface;
bool isVolatile = false;
#endif
explicit operator bool() const
{
#if USE(IOSURFACE)
if (surface)
return true;
#endif
if (bitmap)
return true;
return false;
}
void discard();
};
Buffer m_frontBuffer;
Buffer m_backBuffer;
#if USE(IOSURFACE)
Buffer m_secondaryBackBuffer;
#endif
RetainPtr<CGContextRef> m_frontContextPendingFlush;
bool m_acceleratesDrawing;
WebCore::RepaintRectList m_paintingRects;
std::chrono::steady_clock::time_point m_lastDisplayTime;
};
}
#endif // RemoteLayerBackingStore_h