Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/zen/renderer/gl-texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ void znr_gl_texture_image_2d(struct znr_gl_texture *self, uint32_t target,
int32_t border, uint32_t format, uint32_t type,
struct zwnr_mem_storage *storage);

void znr_gl_texture_sub_image_2d(struct znr_gl_texture *self, uint32_t target,
int32_t level, int32_t xoffset, int32_t yoffset, uint32_t width, uint32_t height,
uint32_t format, uint32_t type, struct zwnr_mem_storage *storage);

void znr_gl_texture_generate_mipmap(
struct znr_gl_texture *self, uint32_t target);

Expand Down
1 change: 1 addition & 0 deletions include/zen/view-child.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct zn_view_child_interface {
struct zn_view_child {
void *user_data;
struct wlr_surface *surface; // nonnull
bool surface_on_partial_updates;

const struct zn_view_child_interface *impl;

Expand Down
3 changes: 3 additions & 0 deletions include/zen/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct zn_view_interface {
struct zn_view {
void *user_data;
struct wlr_surface *surface; // nonnull
bool surface_on_partial_updates;

const struct zn_view_interface *impl;

Expand Down Expand Up @@ -87,6 +88,8 @@ void zn_view_move(

void zn_view_set_maximized(struct zn_view *self, bool maximized);

void zn_view_reset_partial_updates(struct zn_view *self);

/** lifetime of given wlr_surface must be longer than zn_view */
struct zn_view *zn_view_create(struct wlr_surface *surface,
const struct zn_view_interface *impl, void *user_data);
Expand Down
6 changes: 6 additions & 0 deletions zen/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "zen/screen/output.h"
#include "zen/virtual-object.h"
#include "zen/wlr/render/glew.h"
#include "zen/view.h"

static struct zn_server *server_singleton = NULL;

Expand Down Expand Up @@ -79,6 +80,7 @@ zn_server_change_display_system(
struct zn_server *self, enum zn_display_system_state display_system)
{
struct zn_screen *screen;
struct zn_view *view;

if (self->display_system == display_system) return;

Expand All @@ -88,6 +90,10 @@ zn_server_change_display_system(
zn_screen_damage_whole(screen);
}

wl_list_for_each (view, &self->scene->view_list, link) {
zn_view_reset_partial_updates(view);
}

self->display_system = display_system;

wl_signal_emit(&self->events.display_system_changed, &self->display_system);
Expand Down
1 change: 1 addition & 0 deletions zen/view-child.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ zn_view_child_create(struct wlr_surface *surface, struct zn_view *view,

self->user_data = user_data;
self->surface = surface;
self->surface_on_partial_updates = false;
self->impl = impl;
self->view = view;

Expand Down
5 changes: 5 additions & 0 deletions zen/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ zn_view_set_maximized(struct zn_view *self, bool maximized)
self->maximize_status.maximized = maximized;
}

void zn_view_reset_partial_updates(struct zn_view *self){
self->surface_on_partial_updates = false;
}

struct zn_view *
zn_view_create(struct wlr_surface *surface,
const struct zn_view_interface *impl, void *user_data)
Expand All @@ -282,6 +286,7 @@ zn_view_create(struct wlr_surface *surface,
}

self->surface = surface;
self->surface_on_partial_updates = false;
self->impl = impl;
self->user_data = user_data;

Expand Down
78 changes: 62 additions & 16 deletions zna/base-unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <GL/glew.h>
#include <endian.h>
#include <stdio.h>
#include <pixman.h>
#include <zen-common.h>
#include <zwnr/gl-sampler.h>

Expand Down Expand Up @@ -79,7 +80,8 @@ zna_base_unit_read_cairo_surface(

void
zna_base_unit_read_wlr_texture(
struct zna_base_unit *self, struct wlr_texture *texture)
struct zna_base_unit *self, struct wlr_texture *texture,
pixman_region32_t* damage, bool *on_partial_updates)
{
struct zn_server *server = zn_server_get_singleton();
struct zwnr_mem_storage *storage;
Expand All @@ -90,9 +92,6 @@ zna_base_unit_read_wlr_texture(
return;
}

storage =
zwnr_mem_storage_create(NULL, 32 * texture->width * texture->height);

struct wlr_glew_texture_attribs texture_attrib;
wlr_glew_texture_get_attribs(texture, &texture_attrib);

Expand Down Expand Up @@ -122,25 +121,72 @@ zna_base_unit_read_wlr_texture(
glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture, 0);

glReadPixels(0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_BYTE,
storage->data);

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteTextures(1, &depth_texture);
glDeleteFramebuffers(1, &framebuffer);

zn_wlr_egl_unset_current(egl);

if (self->has_texture_data == false) {
self->has_texture_data = true;
znr_gl_base_technique_bind_texture(
self->technique, 0, "", self->texture0, GL_TEXTURE_2D, self->sampler0);
}

znr_gl_texture_image_2d(self->texture0, GL_TEXTURE_2D, 0, GL_RGBA,
texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, storage);
bool need_to_full_load_texture = true;

zwnr_mem_storage_unref(storage);
if (damage != NULL) {
if (on_partial_updates != NULL) {
if (*on_partial_updates == true)
{
need_to_full_load_texture = false;
}
}
}

if (need_to_full_load_texture) {
storage =
zwnr_mem_storage_create(NULL, 32 * texture->width * texture->height);

glReadPixels(0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_BYTE,
storage->data);

znr_gl_texture_image_2d(self->texture0, GL_TEXTURE_2D, 0, GL_RGBA,
texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, storage);


if (on_partial_updates != NULL) {
*on_partial_updates = true;
}

zwnr_mem_storage_unref(storage);
} else {
struct wlr_fbox damage_box;
pixman_box32_t *rects;
int rect_count;
rects = pixman_region32_rectangles(damage, &rect_count);

for (int i = 0; i < rect_count; ++i) {
damage_box.x = rects[i].x1;
damage_box.y = rects[i].y1;
damage_box.width = rects[i].x2 - rects[i].x1;
damage_box.height = rects[i].y2 - rects[i].y1;

storage =
zwnr_mem_storage_create(NULL, 32 * damage_box.width * damage_box.height);

glReadPixels(damage_box.x, damage_box.y, damage_box.width, damage_box.height,
GL_RGBA, GL_UNSIGNED_BYTE,
storage->data);

znr_gl_texture_sub_image_2d(self->texture0, GL_TEXTURE_2D, 0, damage_box.x,
damage_box.y, damage_box.width, damage_box.height, GL_RGBA,
GL_UNSIGNED_BYTE, storage);

zwnr_mem_storage_unref(storage);
}

}

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteTextures(1, &depth_texture);
glDeleteFramebuffers(1, &framebuffer);

zn_wlr_egl_unset_current(egl);
}

void
Expand Down
4 changes: 3 additions & 1 deletion zna/base-unit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cairo.h>
#include <pixman.h>
#include <wayland-server-core.h>
#include <wlr/render/wlr_texture.h>
#include <zwnr/gl-base-technique.h>
Expand Down Expand Up @@ -55,7 +56,8 @@ void zna_base_unit_read_cairo_surface(
struct zna_base_unit *self, cairo_surface_t *surface);

void zna_base_unit_read_wlr_texture(
struct zna_base_unit *self, struct wlr_texture *texture);
struct zna_base_unit *self, struct wlr_texture *texture,
pixman_region32_t *damage, bool *on_partial_updates);

void zna_base_unit_setup_renderer_objects(struct zna_base_unit *self,
struct znr_dispatcher *dispatcher,
Expand Down
2 changes: 1 addition & 1 deletion zna/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ zna_cursor_commit(struct zna_cursor *self, uint32_t damage)

if (damage & ZNA_CURSOR_DAMAGE_TEXTURE) {
zna_base_unit_read_wlr_texture(
self->base_unit, zn_cursor_get_texture(self->zn_cursor));
self->base_unit, zn_cursor_get_texture(self->zn_cursor), NULL, NULL);
znr_gl_sampler_parameter_i(
self->base_unit->sampler0, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
znr_gl_sampler_parameter_i(
Expand Down
4 changes: 3 additions & 1 deletion zna/view-child.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ zna_view_child_commit(struct zna_view_child *self, uint32_t damage)
struct wlr_texture *texture =
wlr_surface_get_texture(self->zn_view_child->surface);
if (texture) {
zna_base_unit_read_wlr_texture(self->base_unit, texture);
zna_base_unit_read_wlr_texture(self->base_unit, texture,
&self->zn_view_child->surface->buffer_damage,
&self->zn_view_child->surface_on_partial_updates);
znr_gl_texture_generate_mipmap(self->base_unit->texture0, GL_TEXTURE_2D);
znr_gl_sampler_parameter_i(
self->base_unit->sampler0, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Expand Down
4 changes: 3 additions & 1 deletion zna/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ zna_view_commit(struct zna_view *self, uint32_t damage)
struct wlr_texture *texture =
wlr_surface_get_texture(self->zn_view->surface);
if (texture) {
zna_base_unit_read_wlr_texture(self->base_unit, texture);
zna_base_unit_read_wlr_texture(self->base_unit, texture,
&self->zn_view->surface->buffer_damage,
&self->zn_view->surface_on_partial_updates);
znr_gl_texture_generate_mipmap(self->base_unit->texture0, GL_TEXTURE_2D);
znr_gl_sampler_parameter_i(
self->base_unit->sampler0, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Expand Down
18 changes: 18 additions & 0 deletions znr-remote/src/gl-texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ znr_gl_texture_image_2d(struct znr_gl_texture *self, uint32_t target,
border, format, type, std::move(buffer));
}

void
znr_gl_texture_sub_image_2d(struct znr_gl_texture *self, uint32_t target,
int32_t level, int32_t xoffset, int32_t yoffset, uint32_t width, uint32_t height,
uint32_t format, uint32_t type,
struct zwnr_mem_storage *storage)
{
auto loop = std::make_unique<Loop>(wl_display_get_event_loop(self->display));

zwnr_mem_storage_ref(storage);

auto buffer = zen::remote::server::CreateBuffer(
storage->data, [storage] { zwnr_mem_storage_unref(storage); },
std::move(loop));

self->proxy->GlTexSubImage2D(target, level, xoffset, yoffset, width, height,
format, type, std::move(buffer));
}

void
znr_gl_texture_generate_mipmap(struct znr_gl_texture *self, uint32_t target)
{
Expand Down