Skip to content

Commit 753d691

Browse files
committed
chore: updates
1 parent 3f178fa commit 753d691

File tree

38 files changed

+1293
-1068
lines changed

38 files changed

+1293
-1068
lines changed

crates/canvas-2d/src/context/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub enum SurfaceEngine {
136136
}
137137

138138

139+
#[derive(Debug, Copy, Clone)]
139140
pub struct SurfaceData {
140141
pub(crate) bounds: skia_safe::Rect,
141142
pub(crate) scale: f32,

crates/canvas-2d/src/context/surface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Context {
3535
};
3636

3737
let info = ImageInfo::new(
38-
ISize::new((width * density).floor() as i32, (height * density).floor() as i32),
38+
ISize::new(width as i32, height as i32),
3939
color_type,
4040
alpha_type,
4141
None,
@@ -124,7 +124,7 @@ impl Context {
124124
return;
125125
}
126126
let info = ImageInfo::new(
127-
ISize::new((width as f32 * density).floor() as i32, (height as f32 * density).floor() as i32),
127+
ISize::new(width as i32, height as i32),
128128
ColorType::RGBA8888,
129129
AlphaType::Unknown,
130130
None,

crates/canvas-2d/src/context/surface_gl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl Context {
180180
0,
181181
frame_buffer,
182182
);
183+
183184
let surface_props = skia_safe::SurfaceProps::new(
184185
skia_safe::SurfacePropsFlags::default(),
185186
PixelGeometry::Unknown,
@@ -203,6 +204,7 @@ impl Context {
203204
surface
204205
};
205206

207+
206208
if let Some(surface) = surface {
207209
context.direct_context = direct_context;
208210
context.surface_data.engine = engine;

crates/canvas-android/src/jni_compat/org_nativescript_canvas_NSCCanvas.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ pub extern "system" fn nativeUpdateGLSurface(
298298
unsafe {
299299
if let Some(window) = NativeWindow::from_surface(env.get_native_interface(), surface) {
300300
let handle = to_raw_window_handler(&window);
301+
301302
context.gl_context.set_window_surface(
302303
&mut context.contextAttributes,
303304
window.width(),
@@ -329,8 +330,7 @@ pub extern "system" fn nativeUpdate2DSurface(
329330
if let Some(window) = NativeWindow::from_surface(env.get_native_interface(), surface) {
330331
let width = window.width() as f32;
331332
let height = window.height() as f32;
332-
let density = context.get_context().density();
333-
context.resize((width / density).floor(), (height / density).floor())
333+
context.resize(width, height)
334334
}
335335
drop(env);
336336
}

crates/canvas-c/src/c2d/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@ fn to_data_url(context: &mut CanvasRenderingContext2D, format: &str, quality: u3
7070
#[cfg(feature = "gl")]
7171
pub fn resize_gl(context: &mut CanvasRenderingContext2D, width: f32, height: f32) {
7272
let alpha = context.alpha;
73+
let gl = &context.gl_context;
74+
context.make_current();
7375
let context = &mut context.context;
7476
let density = context.get_surface_data().scale();
7577
let ppi = context.get_surface_data().ppi();
7678

7779
let mut fb = [0];
7880

7981
unsafe {
82+
gl_bindings::Viewport(0, 0, width as i32, height as i32);
8083
gl_bindings::ClearColor(0., 0., 0., 0.);
8184
gl_bindings::Clear(gl_bindings::COLOR_BUFFER_BIT);
82-
gl_bindings::Viewport(0, 0, (width * density).floor() as i32, (height * density).floor() as i32);
8385
gl_bindings::GetIntegerv(gl_bindings::FRAMEBUFFER_BINDING, fb.as_mut_ptr());
8486
}
87+
gl.swap_buffers();
8588

8689
Context::resize_gl(context, width, height, density, fb[0], 0, alpha, ppi)
8790
}
@@ -197,7 +200,6 @@ impl CanvasRenderingContext2D {
197200
}
198201

199202
pub fn resize(&mut self, width: f32, height: f32) {
200-
self.gl_context.make_current();
201203
resize(self, width, height);
202204
}
203205

crates/canvas-core/src/gl/android.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ impl GLContext {
685685
NonZeroU32::try_from(height as u32).unwrap(),
686686
);
687687

688+
688689
let surface = display
689690
.create_window_surface(&config, &surface_attr)
690691
.map(SurfaceHelper::Window)

packages/canvas-pixi/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,29 @@ class NSCPIXIApplication extends Pixii.Application {
99
let clientWidth = 300;
1010
let clientHeight = 150;
1111
if (context) {
12-
clientWidth = context.canvas.width;
13-
clientHeight = context.canvas.height;
14-
}
15-
if (view) {
16-
clientWidth = view.width;
17-
clientHeight = view.height;
12+
clientWidth = context.canvas.width * Screen.mainScreen.scale;
13+
clientHeight = context.canvas.height * Screen.mainScreen.scale;
1814
}
1915
if (!view) {
2016
view = context.canvas.toHTMLCanvas();
2117
}
18+
19+
if (view) {
20+
clientWidth = view.clientWidth;
21+
clientHeight = view.clientHeight;
22+
}
23+
24+
view.width = view.clientWidth * Screen.mainScreen.scale;
25+
view.height = view.clientHeight * Screen.mainScreen.scale;
26+
2227
const width = props.width || clientWidth;
2328
const height = props.height || clientHeight;
2429

2530
// PIXI.settings.RESOLUTION = 1;
2631

2732
super({
2833
...props,
29-
resolution: 1,
34+
resolution: Screen.mainScreen.scale,
3035
view,
3136
width,
3237
height,

packages/canvas-polyfill/DOM/Element.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,14 @@ export class Element extends Node {
302302

303303
get innerWidth() {
304304
if (this.nativeElement) {
305-
return this.nativeElement['width'] as never;
305+
return this.nativeElement['innerWidth'] ?? (this.nativeElement['width'] as never);
306306
}
307307
return this['width'];
308308
}
309309

310310
get innerHeight() {
311311
if (this.nativeElement) {
312-
return this.nativeElement['height'] as never;
312+
return this.nativeElement['innerHeight'] ?? (this.nativeElement['height'] as never);
313313
}
314314
return this['height'];
315315
}

packages/canvas-polyfill/DOM/HTMLCanvasElement.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,28 @@ export class HTMLCanvasElement extends HTMLElement {
1919
if (!this.nativeElement.__domElement) {
2020
this.nativeElement.__domElement = new DOMParser().parseFromString('<canvas></canvas>', 'text/html').documentElement as never;
2121
}
22-
23-
this.style.nativeElement = new WeakRef(this.nativeElement);
2422
}
2523

2624
get _canvas() {
2725
return this.nativeElement;
2826
}
2927

28+
get innerWidth() {
29+
return this.clientWidth;
30+
}
31+
32+
get innerHeight() {
33+
return this.clientHeight;
34+
}
35+
36+
get clientWidth() {
37+
return this.nativeElement['clientWidth'] as never;
38+
}
39+
40+
get clientHeight() {
41+
return this.nativeElement['clientHeight'] as never;
42+
}
43+
3044
set width(value) {
3145
setValue(this.nativeElement, 'width', value);
3246
}

packages/canvas-polyfill/DOM/HTMLElement.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ export class Style {
2121
}
2222

2323
get width() {
24-
return 0;
24+
return this._values.get('width');
2525
}
2626
set width(value) {
27-
console.log('style.width', value);
27+
this._values.set('width', value);
2828
}
2929

3030
get height() {
31-
return 0;
31+
return this._values.get('height');
3232
}
3333
set height(value) {
34-
console.log('style.height', value);
34+
this._values.set('height', value);
3535
}
3636
}
3737

@@ -44,6 +44,9 @@ export class HTMLElement extends Element {
4444
}
4545

4646
get style() {
47+
if (this._nativeElement) {
48+
return this._nativeElement.style;
49+
}
4750
return this._style;
4851
}
4952

0 commit comments

Comments
 (0)