Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor WebGL implementation to move logic inside the DOM interfaces #6380

Merged
merged 4 commits into from Jul 6, 2015

Conversation

@emilio
Copy link
Member

emilio commented Jun 14, 2015

This improves the encapsulation and consistency in our WebGL
implementation.

Also allows to implement new methods such as getShaderSource().

It will also allow us to use delete() in the destructors of them (note
that we will probably want to keep track of them from the context before).

Some concerns:

Trait method repetition:
I'm aware that the traits WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers are basically the same, but delete() and id() methods are everywhere. I've thought something like:

pub trait WebGLIdentifiable {
    type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
    fn id(&self) -> Self::WebGLId;
}

pub trait WebGLBindable {
    fn bind(&self);
}

pub trait WebGLDeletable {
    fn delete(&self);
}

But I'd want to know your opinion first.

renderer repetition:
Thought of moving the field: renderer: Sender<CanvasMsg> to WebGLObject, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (WebGLObject will never interact with the field directly). It would also mean that all WebGLObjects should have one, which is true at this moment, but maybe not with WebGL 2, for example.

Review on Reviewable

@hoppipolla-critic-bot
Copy link

hoppipolla-critic-bot commented Jun 14, 2015

Critic review: https://critic.hoppipolla.co.uk/r/5279

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

@bors-servo
Copy link
Contributor

bors-servo commented Jun 15, 2015

The latest upstream changes (presumably #6388) made this pull request unmergeable. Please resolve the merge conflicts.

@emilio emilio force-pushed the emilio:webgl-refactoring branch from b58f37d to d17d555 Jun 15, 2015
@emilio
Copy link
Member Author

emilio commented Jun 15, 2015

@nox
Copy link
Member

nox commented Jun 16, 2015

DOM changes are blocked until #6150 lands.

@bors-servo
Copy link
Contributor

bors-servo commented Jun 19, 2015

The latest upstream changes (presumably #6423) made this pull request unmergeable. Please resolve the merge conflicts.

@Ms2ger
Copy link
Contributor

Ms2ger commented Jun 20, 2015

Please rebase on master.

@emilio emilio force-pushed the emilio:webgl-refactoring branch from d17d555 to 4212b60 Jun 20, 2015
@emilio
Copy link
Member Author

emilio commented Jun 20, 2015

Rebased, also added the getError call :P

@bors-servo
Copy link
Contributor

bors-servo commented Jun 26, 2015

The latest upstream changes (presumably #6477) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm jdm added the S-needs-rebase label Jun 26, 2015
@jdm
Copy link
Member

jdm commented Jul 6, 2015

-S-awaiting-review +S-needs-code-changes


Reviewed 12 of 12 files at r3.
Review status: all files reviewed at latest revision, 18 unresolved discussions, some commit checks failed.


components/canvas_traits/lib.rs, line 133 [r3] (raw file):
I'm inclined to remove this and use Option<WebGLError> wherever necessary.


components/script/dom/webglbuffer.rs, line 38 [r3] (raw file):

let result = receiver.recv().unwrap();
result.map(...)

components/script/dom/webglframebuffer.rs, line 38 [r3] (raw file):
Same as previous.


components/script/dom/webglprogram.rs, line 46 [r3] (raw file):
Same as previously.


components/script/dom/webglprogram.rs, line 90 [r3] (raw file):
Differentiate


components/script/dom/webglrenderbuffer.rs, line 38 [r3] (raw file):
Same as previously.


components/script/dom/webglrenderingcontext.rs, line 31 [r3] (raw file):
nit: move this above std::mem.


components/script/dom/webglrenderingcontext.rs, line 36 [r3] (raw file):
nit: no space before :


components/script/dom/webglrenderingcontext.rs, line 56 [r3] (raw file):
Option<WebGLError>


components/script/dom/webglrenderingcontext.rs, line 235 [r3] (raw file):
Let's split this out as

let cmd = CanvasWebGLMsg::BindFramebuffer(target, WebGLFramebufferBindingRequest::Default);
self.renderer.send(CanvasMsg::WebGL(cmd)).unwrap();

components/script/dom/webglrenderingcontext.rs, line 443 [r3] (raw file):
shader.map(|shader| shader.source())


components/script/dom/webglshader.rs, line 24 [r3] (raw file):
Yes, since layout will never be touching this.


components/script/dom/webglshader.rs, line 27 [r3] (raw file):
Evaluate, maybe?


components/script/dom/webglshader.rs, line 49 [r3] (raw file):
Same as previously.


components/script/dom/webglshader.rs, line 85 [r3] (raw file):
Change it how?


components/script/dom/webglshader.rs, line 90 [r3] (raw file):
tr?


components/script/dom/webglshader.rs, line 119 [r3] (raw file):
Is the * necessary?


components/script/dom/webgltexture.rs, line 38 [r3] (raw file):
Same as previously.


Comments from the review on Reviewable.io

emilio added 3 commits Jun 14, 2015
This improves the encapsulation and consistency in our WebGL
implementation.

Also allows to implement new methods such as `getShaderSource()`.

It will also allow us to use `delete()` in the destructors of them (note
that we will want to keep track of them from the context).
@emilio emilio force-pushed the emilio:webgl-refactoring branch from f00f975 to b26fd77 Jul 6, 2015
@emilio
Copy link
Member Author

emilio commented Jul 6, 2015

Review status: 3 of 12 files reviewed at latest revision, 17 unresolved discussions, some commit checks pending.


components/canvas_traits/lib.rs, line 133 [r3] (raw file):
Done.


components/script/dom/webglframebuffer.rs, line 38 [r3] (raw file):
Done.


components/script/dom/webglprogram.rs, line 46 [r3] (raw file):
Done.


components/script/dom/webglprogram.rs, line 90 [r3] (raw file):
Done.


components/script/dom/webglrenderbuffer.rs, line 38 [r3] (raw file):
Done.


components/script/dom/webglrenderingcontext.rs, line 31 [r3] (raw file):
Done.


components/script/dom/webglrenderingcontext.rs, line 36 [r3] (raw file):
Done.


components/script/dom/webglrenderingcontext.rs, line 56 [r3] (raw file):
Done.


components/script/dom/webglrenderingcontext.rs, line 235 [r3] (raw file):
Done.


components/script/dom/webglrenderingcontext.rs, line 443 [r3] (raw file):
We can't do that, that would return an Option<Option<DOMString>>.


components/script/dom/webglshader.rs, line 24 [r3] (raw file):
Done.


components/script/dom/webglshader.rs, line 27 [r3] (raw file):
Done.


components/script/dom/webglshader.rs, line 49 [r3] (raw file):
Done.


components/script/dom/webglshader.rs, line 85 [r3] (raw file):
This was before implementing getError. At that point I thought that the getError call would need to interact with gl, which was false.

Removed


components/script/dom/webglshader.rs, line 90 [r3] (raw file):
Wrong, good catch :P


components/script/dom/webglshader.rs, line 119 [r3] (raw file):
Nope, you're right :P


components/script/dom/webgltexture.rs, line 38 [r3] (raw file):
Done.


Comments from the review on Reviewable.io

@emilio emilio force-pushed the emilio:webgl-refactoring branch from b26fd77 to 8438db8 Jul 6, 2015
@jdm
Copy link
Member

jdm commented Jul 6, 2015

@bors-servo: r+
-S-awaiting-review +S-awaiting-merge -S-needs-rebase


Reviewed 9 of 9 files at r4.
Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from the review on Reviewable.io

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2015

📌 Commit 8438db8 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2015

Testing commit 8438db8 with merge 0f8095b...

bors-servo pushed a commit that referenced this pull request Jul 6, 2015
Refactor WebGL implementation to move logic inside the DOM interfaces

This improves the encapsulation and consistency in our WebGL
implementation.

Also allows to implement new methods such as `getShaderSource()`.

It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).

Some concerns:

**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:

```rust
pub trait WebGLIdentifiable {
    type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
    fn id(&self) -> Self::WebGLId;
}

pub trait WebGLBindable {
    fn bind(&self);
}

pub trait WebGLDeletable {
    fn delete(&self);
}
```

But I'd want to know your opinion first.

**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6380)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2015

☀️ Test successful - android, gonk, linux1, linux2, linux3, mac1, mac2, mac3

@bors-servo bors-servo merged commit 8438db8 into servo:master Jul 6, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.