-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #1807 - glennw:canvas1, r=nical
Add canvas as a more general version of the shadow primitive. This doesn't add any functional changes, but it lays the foundation for moving box shadows and other render task operations over to unified as canvas primitives. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1807) <!-- Reviewable:end -->
- Loading branch information
Showing
6 changed files
with
230 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
use api::{ClipAndScrollInfo, Shadow}; | ||
use prim_store::PrimitiveIndex; | ||
use render_task::RenderTaskId; | ||
|
||
/* | ||
A picture represents a dynamically rendered image. It consists of: | ||
* A number of primitives that are drawn onto the picture. | ||
* A composite operation describing how to composite this | ||
picture into its parent. | ||
* A configuration describing how to draw the primitives on | ||
this picture (e.g. in screen space or local space). | ||
*/ | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct PrimitiveRun { | ||
pub prim_index: PrimitiveIndex, | ||
pub count: usize, | ||
pub clip_and_scroll: ClipAndScrollInfo, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum CompositeOp { | ||
Shadow(Shadow), | ||
|
||
// TODO(gw): Support other composite ops, such | ||
// as blur, blend etc. | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct PicturePrimitive { | ||
pub prim_runs: Vec<PrimitiveRun>, | ||
pub composite_op: CompositeOp, | ||
pub render_task_id: Option<RenderTaskId>, | ||
|
||
// TODO(gw): Add a mode that specifies if this | ||
// picture should be rasterized in | ||
// screen-space or local-space. | ||
} | ||
|
||
impl PicturePrimitive { | ||
pub fn new_shadow(shadow: Shadow) -> PicturePrimitive { | ||
PicturePrimitive { | ||
prim_runs: Vec::new(), | ||
composite_op: CompositeOp::Shadow(shadow), | ||
render_task_id: None, | ||
} | ||
} | ||
|
||
pub fn as_shadow(&self) -> &Shadow { | ||
match self.composite_op { | ||
CompositeOp::Shadow(ref shadow) => shadow, | ||
} | ||
} | ||
|
||
pub fn add_primitive( | ||
&mut self, | ||
prim_index: PrimitiveIndex, | ||
clip_and_scroll: ClipAndScrollInfo | ||
) { | ||
if let Some(ref mut run) = self.prim_runs.last_mut() { | ||
if run.clip_and_scroll == clip_and_scroll && | ||
run.prim_index.0 + run.count == prim_index.0 { | ||
run.count += 1; | ||
return; | ||
} | ||
} | ||
|
||
self.prim_runs.push(PrimitiveRun { | ||
prim_index, | ||
count: 1, | ||
clip_and_scroll, | ||
}); | ||
} | ||
} |
Oops, something went wrong.