Gecko:Layers: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 3: Line 3:
== Roc ==
== Roc ==


// Reference counted, safe-for-cross-thread-use layer class.
// Reference counted, safe-for-cross-thread-use layer class.
// Conceptually it's just something that knows how to composite itself
// Conceptually it's just something that knows how to composite itself
// onto some parent surface/layer.
// onto some parent surface/layer.
// Layers are immutable. They might have time-varying rendering (animation), but
// Layers are immutable. They might have time-varying rendering (animation),
// you can't modify one once it's created. This makes them easy to use safely
// but you can't modify one once it's created. This makes them easy to use
// across threads.
// safely across threads.
class Layer {
class Layer {
};
};


// Generic superclass for helper object that creates a layer. This can only
// Generic superclass for helper object that creates a layer. This can only
// be used on one thread.
// be used on one thread.
class LayerBuilder {
class LayerBuilder {
  // Indicate that the given layer is related to this one, e.g., the new layer
  // Indicate that the given layer is related to this one, e.g., the new layer
  // corresponds to the same element as the given layer. This adopts the
  // corresponds to the same element as the given layer. This adopts the
  // caller's reference to the given layer. If the LayerBuilder is now the only
  // caller's reference to the given layer. If the LayerBuilder is now the only
  // thing holding a reference to the given Layer, we can recycle the Layer's
  // thing holding a reference to the given Layer, we can recycle the Layer's
  // resources here (even the Layer object itself).
  // resources here (even the Layer object itself).
  // We can also use this to predict that the new layer will be used in the
  // We can also use this to predict that the new layer will be used in the
  // same way as the given layer, for example, the eventual rendering
  // same way as the given layer, for example, the eventual rendering
  // destination(s) of the new layer can be predicted to be whatever the old
  // destination(s) of the new layer can be predicted to be whatever the old
  // layer was rendered to.
  // layer was rendered to.
  void setAffinity(Layer);
  void setAffinity(Layer);


  // Set rendering properties
  // Set rendering properties
  void setOpacity(float);
  void setOpacity(float);
  // Set the transform used to render this layer onto the destination surface
  // Set the transform used to render this layer onto the destination surface
  void setTransform(matrix);
  void setTransform(matrix);
  void setColorSpaceConversion(...);
  void setColorSpaceConversion(...);
  void setProgram(...);
  void setProgram(...);


  // Finish building and return the Layer. This can only be called once,
  // Finish building and return the Layer. This can only be called once,
  // nothing else can be done with this LayerBuilder afterward.
  // nothing else can be done with this LayerBuilder afterward.
  // In some cases this may return no layer, in particular when the builder
  // In some cases this may return no layer, in particular when the builder
  // was created by ContainerLayerBuilder::addContainerChild/addRenderedChild
  // was created by ContainerLayerBuilder::addContainerChild/addRenderedChild
  // (the layer system may have rendered the child's contents directly into the
  // (the layer system may have rendered the child's contents directly into the
  // parent).
  // parent).
  Layer finish();
  Layer finish();
};
};


class YUVLayerBuilder : LayerBuilder {
class YUVLayerBuilder : LayerBuilder {
  // Create a YUV layer with given size and format, and adopt the memory buffer
  // Create a YUV layer with given size and format, and adopt the memory buffer
  YUVLayerBuilder(size, format, bufferToAdopt);
  YUVLayerBuilder(size, format, bufferToAdopt);
};
};


class ContainerLayerBuilder : LayerBuilder {
class ContainerLayerBuilder : LayerBuilder {
  // format can be RGB, ARGB (eventually ARAGAB?).
  // format can be RGB, ARGB (eventually ARAGAB?).
  // This constructs a container layer that can be used anywhere.
  // This constructs a container layer that can be used anywhere.
  ContainerLayerBuilder(size, format);
  ContainerLayerBuilder(size, format);


  // Add an existing layer
  // Add an existing layer
  addLayer(Layer);
  addLayer(Layer);
  // Open a child container layer. This child must finish()
  // before another child can be added or this builder finishes.
  ContainerLayerBuilder addContainerChild(size, format);
  // Open a child rendered layer. This child must finish()
  // before another child can be added or this builder finishes.
  // RenderedLayers constructed this way may not need a temporary surface.
  RenderedLayerBuilder addRenderedChild(size, format);
};


  // Open a child container layer. This child must finish()
class RenderedLayerBuilder : LayerBuilder {
  // before another child can be added or this builder finishes.
  // format can be RGB, ARGB (eventually ARAGAB?)
  ContainerLayerBuilder addContainerChild(size, format);
  // This constructs a layer rendered via gfx that can be used anywhere
  // Open a child rendered layer. This child must finish()
  // (and therefore requires a temporary surface).
  // before another child can be added or this builder finishes.
  RenderedLayerBuilder(size, format);
  // RenderedLayers constructed this way may not need a temporary surface.
  RenderedLayerBuilder addRenderedChild(size, format);
};


class RenderedLayerBuilder : LayerBuilder {
  gfxContext* getContext();
  // format can be RGB, ARGB (eventually ARAGAB?)
};
  // This constructs a layer rendered via gfx that can be used anywhere
  // (and therefore requires a temporary surface).
  RenderedLayerBuilder(size, format);
 
  gfxContext* getContext();
};


Add a method gfxContext::SetSource(Layer).
Add a method gfxContext::SetSource(Layer).

Revision as of 22:53, 6 October 2009

Layer API Proposals

Roc

// Reference counted, safe-for-cross-thread-use layer class.
// Conceptually it's just something that knows how to composite itself
// onto some parent surface/layer.
// Layers are immutable. They might have time-varying rendering (animation),
// but you can't modify one once it's created. This makes them easy to use
// safely across threads.
class Layer {
};
// Generic superclass for helper object that creates a layer. This can only
// be used on one thread.
class LayerBuilder {
  // Indicate that the given layer is related to this one, e.g., the new layer
  // corresponds to the same element as the given layer. This adopts the
  // caller's reference to the given layer. If the LayerBuilder is now the only
  // thing holding a reference to the given Layer, we can recycle the Layer's
  // resources here (even the Layer object itself).
  // We can also use this to predict that the new layer will be used in the
  // same way as the given layer, for example, the eventual rendering
  // destination(s) of the new layer can be predicted to be whatever the old
  // layer was rendered to.
  void setAffinity(Layer);
  // Set rendering properties
  void setOpacity(float);
  // Set the transform used to render this layer onto the destination surface
  void setTransform(matrix);
  void setColorSpaceConversion(...);
  void setProgram(...);
  // Finish building and return the Layer. This can only be called once,
  // nothing else can be done with this LayerBuilder afterward.
  // In some cases this may return no layer, in particular when the builder
  // was created by ContainerLayerBuilder::addContainerChild/addRenderedChild
  // (the layer system may have rendered the child's contents directly into the
  // parent).
  Layer finish();
};
class YUVLayerBuilder : LayerBuilder {
  // Create a YUV layer with given size and format, and adopt the memory buffer
  YUVLayerBuilder(size, format, bufferToAdopt);
};
class ContainerLayerBuilder : LayerBuilder {
  // format can be RGB, ARGB (eventually ARAGAB?).
  // This constructs a container layer that can be used anywhere.
  ContainerLayerBuilder(size, format);
  // Add an existing layer
  addLayer(Layer);

  // Open a child container layer. This child must finish()
  // before another child can be added or this builder finishes.
  ContainerLayerBuilder addContainerChild(size, format);
  // Open a child rendered layer. This child must finish()
  // before another child can be added or this builder finishes.
  // RenderedLayers constructed this way may not need a temporary surface.
  RenderedLayerBuilder addRenderedChild(size, format);
};
class RenderedLayerBuilder : LayerBuilder {
  // format can be RGB, ARGB (eventually ARAGAB?)
  // This constructs a layer rendered via gfx that can be used anywhere
  // (and therefore requires a temporary surface).
  RenderedLayerBuilder(size, format);
  gfxContext* getContext();
};

Add a method gfxContext::SetSource(Layer).

Add a way to return a Layer from a paint event (or just set it directly on the widget), so it gets rendered, possibly asynchronously on another thread.

Jeff

Bas