docs
Loading...
Searching...
No Matches
BitmapSurface

#include <Ultralight/platform/Surface.h>

Overview

The default surface implementation, backed by a bitmap.

This is automatically provided by the library when you call Renderer::Create() without defining a custom SurfaceFactory.

This implementation uses a Bitmap to store pixel data (retrieve it via BitmapSurface::bitmap()).

Inheritance diagram for BitmapSurface:
Surface

Public Member Functions

virtual uint32_t width () const override
 Width (in pixels).
virtual uint32_t height () const override
 Height (in pixels).
virtual uint32_t row_bytes () const override
 Number of bytes between rows (usually width * 4).
virtual size_t size () const override
 Size in bytes.
virtual void * LockPixels () override
 Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing.
virtual void UnlockPixels () override
 Unlock the pixel buffer.
virtual void Resize (uint32_t width, uint32_t height) override
 Resize the pixel buffer to a certain width and height (both in pixels).
virtual bool Scroll (const IntRect &rect, int dx, int dy) override
 Shift a rectangle of pixels by an offset.
RefPtr< Bitmap > bitmap ()
 Get the underlying Bitmap.
Public Member Functions inherited from Surface
virtual ~Surface ()
LockedPixels< Surface * > LockPixelsSafe ()
 Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
virtual void set_dirty_bounds (const IntRect &bounds)
 Add a rectangle to the dirty area.
virtual IntRect dirty_bounds () const
 Get the dirty bounds.
virtual void ClearDirtyBounds ()
 Clear the dirty bounds.
uint32_t dirty_rect_count () const
 Get the number of dirty rectangles (0 when nothing has been painted since the last clear).
IntRect dirty_rect (uint32_t index) const
 Get a dirty rectangle by index.

Protected Member Functions

 BitmapSurface (uint32_t width, uint32_t height)
virtual ~BitmapSurface ()
 BitmapSurface (const BitmapSurface &)=delete
void operator= (const BitmapSurface &)=delete
Protected Member Functions inherited from Surface
 Surface ()

Protected Attributes

void * impl_
Protected Attributes inherited from Surface
IntRect dirty_bounds_
IntRect dirty_rects_ [kMaxDirtyRects]
uint32_t dirty_rect_count_ = 0

Friends

class BitmapSurfaceFactory

Additional Inherited Members

Static Public Member Functions inherited from Surface
static void ShiftPixels (void *pixels, uint32_t row_bytes, const IntRect &rect, int dx, int dy)
 Shift a rectangle of 32-bit pixels in place.
Static Public Attributes inherited from Surface
static constexpr uint32_t kMaxDirtyRects = 8
 The most dirty rectangles the library keeps apart before merging them.

Constructor & Destructor Documentation

◆ BitmapSurface() [1/2]

BitmapSurface ( uint32_t width,
uint32_t height )
protected

◆ ~BitmapSurface()

virtual ~BitmapSurface ( )
protectedvirtual

◆ BitmapSurface() [2/2]

BitmapSurface ( const BitmapSurface & )
protecteddelete

Member Function Documentation

◆ bitmap()

RefPtr< Bitmap > bitmap ( )

Get the underlying Bitmap.

◆ height()

virtual uint32_t height ( ) const
overridevirtual

Height (in pixels).

Implements Surface.

◆ LockPixels()

virtual void * LockPixels ( )
overridevirtual

Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing.

Note
Native pixel format is premultiplied BGRA 32-bit (8 bits per channel).
Returns
Returns a pointer to the beginning of the locked pixel buffer. The buffer remains valid until UnlockPixels() is called.

Implements Surface.

◆ operator=()

void operator= ( const BitmapSurface & )
protecteddelete

◆ Resize()

virtual void Resize ( uint32_t width,
uint32_t height )
overridevirtual

Resize the pixel buffer to a certain width and height (both in pixels).

This should never be called while pixels are locked.

Implements Surface.

◆ row_bytes()

virtual uint32_t row_bytes ( ) const
overridevirtual

Number of bytes between rows (usually width * 4).

Implements Surface.

◆ Scroll()

virtual bool Scroll ( const IntRect & rect,
int dx,
int dy )
overridevirtual

Shift a rectangle of pixels by an offset.

The library calls this during Renderer::Render() when a page scrolls, moving already painted pixels instead of repainting them. Afterward, the library repaints only the exposed strip.

The Surface pixel buffer is the source the library paints into. The destination is wherever you copy those pixels to display them (eg, a GPU texture or a window). Scroll() always shifts the source.

Most implementations do this with one call to ShiftPixels().

Parameters
rectThe rectangle to shift (in pixels). This always lies inside the surface, and the shift is smaller than the rectangle on each axis.
dxThe horizontal shift, in pixels (positive moves pixels to the right).
dyThe vertical shift, in pixels (positive moves pixels down).
Returns
Return false in most cases. This means the destination was not shifted. The library then adds rect to dirty_bounds() so you copy the moved pixels from the source to the destination again. Return true only in the rare case where you shifted the destination by the same offset yourself (eg, you scrolled your window or copied within your GPU texture)– the library then reports only the newly exposed strip as dirty.
Note
This is called while pixels are locked (between LockPixels() and UnlockPixels()). Shift through the pointer you returned from LockPixels()– do not lock the buffer again.
Note
Rows may be padded. Step rows by row_bytes(), never by width * 4.

Implements Surface.

◆ size()

virtual size_t size ( ) const
overridevirtual

Size in bytes.

Implements Surface.

◆ UnlockPixels()

virtual void UnlockPixels ( )
overridevirtual

Unlock the pixel buffer.

Implements Surface.

◆ width()

virtual uint32_t width ( ) const
overridevirtual

Width (in pixels).

Implements Surface.

◆ BitmapSurfaceFactory

friend class BitmapSurfaceFactory
friend

Member Data Documentation

◆ impl_

void* impl_
protected

The documentation for this class was generated from the following file: