Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
ultralight::Surface Class Referenceabstract

#include <Ultralight/platform/Surface.h>

Details

Offscreen pixel buffer surface.

(Premultiplied BGRA 32-bit format)

When using the CPU renderer, each View is painted to its own Surface.

You can provide your own Surface implementation to make the renderer paint directly to a block of memory controlled by you (this is useful for lower-latency uploads to GPU memory or other platform-specific bitmaps).

A default Surface implementation, BitmapSurface, is automatically provided by the library when you call Renderer::Create() without defining a custom SurfaceFactory.

To provide your own custom Surface implementation, you should inherit from this class, handle the virtual member functions, and then define a custom SurfaceFactory that creates/destroys an instance of your class. After that, you should pass an instance of your custom SurfaceFactory class to Platform::instance().set_font_loader() before calling App::Create() or Renderer::Create().

Inheritance diagram for ultralight::Surface:
ultralight::BitmapSurface

Public Member Functions

virtual ~Surface ()
 
virtual uint32_t width () const =0
 Width (in pixels).
 
virtual uint32_t height () const =0
 Height (in pixels).
 
virtual uint32_t row_bytes () const =0
 Number of bytes between rows (usually width * 4)
 
virtual size_t size () const =0
 Size in bytes.
 
virtual void * LockPixels ()=0
 Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing.
 
virtual void UnlockPixels ()=0
 Unlock the pixel buffer.
 
virtual void Resize (uint32_t width, uint32_t height)=0
 Resize the pixel buffer to a certain width and height (both in pixels).
 
virtual void set_dirty_bounds (const IntRect &bounds)
 Set the dirty bounds to a certain value.
 
virtual IntRect dirty_bounds () const
 Get the dirty bounds.
 
virtual void ClearDirtyBounds ()
 Clear the dirty bounds.
 

Protected Member Functions

 Surface ()
 

Protected Attributes

IntRect dirty_bounds_
 

Constructor & Destructor Documentation

◆ ~Surface()

virtual ultralight::Surface::~Surface ( )
virtual

◆ Surface()

ultralight::Surface::Surface ( )
protected

Member Function Documentation

◆ ClearDirtyBounds()

virtual void ultralight::Surface::ClearDirtyBounds ( )
virtual

Clear the dirty bounds.

You should call this after you're done displaying the Surface.

◆ dirty_bounds()

virtual IntRect ultralight::Surface::dirty_bounds ( ) const
virtual

Get the dirty bounds.

This value can be used to determine which portion of the pixel buffer has been updated since the last call to ClearDirtyBounds().

The general algorithm to determine if a Surface needs display is:

  if (!surface.dirty_bounds().IsEmpty()) {
      // Surface pixels are dirty and needs display.
      // Cast Surface to native Surface and use it here (pseudo code)
      DisplaySurface(surface);

      // Once you're done, clear the dirty bounds:
      surface.ClearDirtyBounds();
 }
 

◆ height()

virtual uint32_t ultralight::Surface::height ( ) const
pure virtual

Height (in pixels).

Implemented in ultralight::BitmapSurface.

◆ LockPixels()

virtual void * ultralight::Surface::LockPixels ( )
pure virtual

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

Native pixel format is premultiplied BGRA 32-bit (8 bits per channel).

Implemented in ultralight::BitmapSurface.

◆ Resize()

virtual void ultralight::Surface::Resize ( uint32_t  width,
uint32_t  height 
)
pure virtual

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

This should never be called while pixels are locked.

Implemented in ultralight::BitmapSurface.

◆ row_bytes()

virtual uint32_t ultralight::Surface::row_bytes ( ) const
pure virtual

Number of bytes between rows (usually width * 4)

Implemented in ultralight::BitmapSurface.

◆ set_dirty_bounds()

virtual void ultralight::Surface::set_dirty_bounds ( const IntRect bounds)
virtual

Set the dirty bounds to a certain value.

This is called after the Renderer paints to an area of the pixel buffer. (The new value will be joined with the existing dirty_bounds())

◆ size()

virtual size_t ultralight::Surface::size ( ) const
pure virtual

Size in bytes.

Implemented in ultralight::BitmapSurface.

◆ UnlockPixels()

virtual void ultralight::Surface::UnlockPixels ( )
pure virtual

Unlock the pixel buffer.

Implemented in ultralight::BitmapSurface.

◆ width()

virtual uint32_t ultralight::Surface::width ( ) const
pure virtual

Width (in pixels).

Implemented in ultralight::BitmapSurface.

Member Data Documentation

◆ dirty_bounds_

IntRect ultralight::Surface::dirty_bounds_
protected

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