This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm_tools: sommelier: Attach xshape to window
This patch adds the ability to listens to incoming shape events to Sommelier. This data is then attached the appropriate window. This is added to support subsequent patches which will perform the necessary image manipulations in order to display the shaped window correctly. BUG=b:223232234 TEST=Ensured no crashes when using both regular and shaped applications Change-Id: I86d5a9df940677c0782a5915fff6db053846b5f7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3880723 Tested-by: Isaac Bosompem <[email protected]> Reviewed-by: Nic Hollingum <[email protected]> Commit-Queue: Isaac Bosompem <[email protected]>
- Loading branch information
Isaac Bosompem
authored and
Chromeos LUCI
committed
Oct 6, 2022
1 parent
93e3af9
commit 836c972
Showing
7 changed files
with
155 additions
and
1 deletion.
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
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,100 @@ | ||
// Copyright 2022 The ChromiumOS Authors. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <assert.h> | ||
#include <pixman.h> | ||
|
||
#include "sommelier.h" // NOLINT(build/include_directory) | ||
#include "sommelier-tracing.h" // NOLINT(build/include_directory) | ||
#include "sommelier-xshape.h" // NOLINT(build/include_directory) | ||
|
||
static void sl_clear_shape_region(sl_window* window) { | ||
window->shaped = false; | ||
pixman_region32_fini(&window->shape_rectangles); | ||
} | ||
|
||
static void sl_attach_shape_region(struct sl_context* ctx, | ||
xcb_window_t window) { | ||
sl_window* sl_window = nullptr; | ||
xcb_shape_get_rectangles_reply_t* reply; | ||
int i; | ||
|
||
sl_window = sl_lookup_window(ctx, window); | ||
if (!sl_window) | ||
return; | ||
|
||
reply = xcb_shape_get_rectangles_reply( | ||
ctx->connection, | ||
xcb_shape_get_rectangles(ctx->connection, window, XCB_SHAPE_SK_BOUNDING), | ||
NULL); | ||
|
||
if (!reply) | ||
return; | ||
|
||
int nrects = xcb_shape_get_rectangles_rectangles_length(reply); | ||
xcb_rectangle_t* rects = xcb_shape_get_rectangles_rectangles(reply); | ||
|
||
if (!rects || nrects <= 0) | ||
return; | ||
|
||
pixman_box32_t* boxes = | ||
static_cast<pixman_box32_t*>(calloc(sizeof(pixman_box32_t), nrects)); | ||
|
||
if (!boxes) { | ||
free(reply); | ||
return; | ||
} | ||
|
||
for (i = 0; i < nrects; i++) { | ||
boxes[i].x1 = rects[i].x; | ||
boxes[i].y1 = rects[i].y; | ||
|
||
boxes[i].x2 = rects[i].x + rects[i].width; | ||
boxes[i].y2 = rects[i].y + rects[i].height; | ||
} | ||
|
||
pixman_region32_init_rects(&sl_window->shape_rectangles, boxes, nrects); | ||
free(boxes); | ||
free(reply); | ||
|
||
sl_window->shaped = true; | ||
} | ||
|
||
void sl_handle_shape_notify(struct sl_context* ctx, | ||
struct xcb_shape_notify_event_t* event) { | ||
sl_window* window = nullptr; | ||
|
||
window = sl_lookup_window(ctx, event->affected_window); | ||
|
||
if (!window) | ||
return; | ||
|
||
sl_clear_shape_region(window); | ||
|
||
if (event->shaped) | ||
sl_attach_shape_region(ctx, event->affected_window); | ||
|
||
return; | ||
} | ||
|
||
void sl_shape_query(struct sl_context* ctx, xcb_window_t xwindow) { | ||
xcb_shape_query_extents_reply_t* reply; | ||
sl_window* sl_window = nullptr; | ||
|
||
sl_window = sl_lookup_window(ctx, xwindow); | ||
if (!sl_window) | ||
return; | ||
|
||
reply = xcb_shape_query_extents_reply( | ||
ctx->connection, xcb_shape_query_extents(ctx->connection, xwindow), NULL); | ||
|
||
if (!reply) | ||
return; | ||
|
||
sl_clear_shape_region(sl_window); | ||
|
||
if (reply->bounding_shaped) { | ||
sl_attach_shape_region(ctx, xwindow); | ||
} | ||
} |
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,17 @@ | ||
// Copyright 2022 The ChromiumOS Authors. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef VM_TOOLS_SOMMELIER_SOMMELIER_XSHAPE_H_ | ||
#define VM_TOOLS_SOMMELIER_SOMMELIER_XSHAPE_H_ | ||
|
||
#include <xcb/shape.h> | ||
#include <xcb/xcb.h> | ||
#include "sommelier-ctx.h" // NOLINT(build/include_directory) | ||
|
||
void sl_handle_shape_notify(struct sl_context* ctx, | ||
struct xcb_shape_notify_event_t* event); | ||
|
||
void sl_shape_query(struct sl_context* ctx, xcb_window_t xwindow); | ||
|
||
#endif // VM_TOOLS_SOMMELIER_SOMMELIER_XSHAPE_H_ |
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