mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
webgl: texImage2D with a canvas argument
This commit is contained in:
parent
a58e731abd
commit
e2b7a01055
5 changed files with 78 additions and 71 deletions
|
@ -2,7 +2,7 @@
|
|||
* 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 canvas_traits::CanvasMsg;
|
||||
use canvas_traits::{CanvasMsg, FromLayoutMsg};
|
||||
use dom::attr::Attr;
|
||||
use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods;
|
||||
|
@ -22,7 +22,7 @@ use dom::node::{Node, NodeTypeId, window_from_node};
|
|||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext};
|
||||
use euclid::size::Size2D;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use js::jsapi::{HandleValue, JSContext};
|
||||
use offscreen_gl_context::GLContextAttributes;
|
||||
use std::cell::Cell;
|
||||
|
@ -150,6 +150,17 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> {
|
|||
|
||||
|
||||
impl HTMLCanvasElement {
|
||||
pub fn ipc_renderer(&self) -> Option<IpcSender<CanvasMsg>> {
|
||||
if let Some(context) = self.context.get() {
|
||||
match context {
|
||||
CanvasContext::Context2d(context) => Some(context.root().r().ipc_renderer()),
|
||||
CanvasContext::WebGL(context) => Some(context.root().r().ipc_renderer()),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_or_init_2d_context(&self) -> Option<Root<CanvasRenderingContext2D>> {
|
||||
if self.context.get().is_none() {
|
||||
let window = window_from_node(self);
|
||||
|
@ -200,6 +211,27 @@ impl HTMLCanvasElement {
|
|||
pub fn is_valid(&self) -> bool {
|
||||
self.height.get() != 0 && self.width.get() != 0
|
||||
}
|
||||
|
||||
pub fn fetch_all_data(&self) -> Option<(Vec<u8>, Size2D<i32>)> {
|
||||
let size = self.get_size();
|
||||
|
||||
if size.width == 0 || size.height == 0 {
|
||||
return None
|
||||
}
|
||||
|
||||
let renderer = match self.ipc_renderer() {
|
||||
Some(renderer) => renderer,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender));
|
||||
renderer.send(msg).unwrap();
|
||||
|
||||
let data = receiver.recv().unwrap().to_vec();
|
||||
|
||||
Some((data, size))
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue