Gecko:Layers: Difference between revisions
(Created page with 'Layer API Proposals == Roc == == Jeff == == Bas ==') |
(→Roc) |
||
| Line 2: | Line 2: | ||
== Roc == | == 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 == | == Jeff == | ||
== Bas == | == Bas == | ||
Revision as of 22:51, 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.