From patchwork Tue Oct 29 10:52:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 21266 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 833F620354 for ; Tue, 29 Oct 2013 10:52:30 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id vb8sf17880726obc.0 for ; Tue, 29 Oct 2013 03:52:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:to:from:subject :message-id:date:reply-to:sender:errors-to:precedence :x-original-sender:x-original-authentication-results:mailing-list :list-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=k1Vd5zyIugVL6Awc8P8SnCphEQQuH058vukRjWtdqDw=; b=Nq203XVtQzA0/GRh12klP1Reo/9c6ySTAE3qnlk70vRvp6ekTuOcJK5Rka/Fvw050b ZhpmyD6lnVdcUVIVbvbKeJhSsILg/cFOXmoRdNs2vEPeEztPsNXiXuT43CD+zF81/Dy2 4PnD4vtT15tkI26OmRLVk+3d0saIaLTsOoFisAKfm1KclxL5bUmQaJWfCAk1GQqGCLi6 IosEfWKpzZJghp2Gb7XpNX2lZLLjeorv/bbX4C4xvvSAavrlTHAQSWb4rCOubIq5n7Lt 1KYbFCUnX1LOgW8iOICNqIFlfjw1C0HaEOuQbNM6IjD0ga3p4VsS3BTAAcO+0xH88C9c T4yg== X-Gm-Message-State: ALoCoQlDMXqGuN2fgrJaiPkBR6d/QWLTkFaBQ2XTlU459ibXgYT7nhG7YHqBDec2EVpY9Qw9TVo+ X-Received: by 10.42.60.130 with SMTP id q2mr9055597ich.21.1383043950114; Tue, 29 Oct 2013 03:52:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.48.66 with SMTP id j2ls16100qen.90.gmail; Tue, 29 Oct 2013 03:52:30 -0700 (PDT) X-Received: by 10.52.170.111 with SMTP id al15mr935166vdc.43.1383043950002; Tue, 29 Oct 2013 03:52:30 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id uw4si6783027vec.115.2013.10.29.03.52.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Oct 2013 03:52:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id c14so4489859vea.0 for ; Tue, 29 Oct 2013 03:52:29 -0700 (PDT) X-Received: by 10.58.39.97 with SMTP id o1mr16467444vek.15.1383043949906; Tue, 29 Oct 2013 03:52:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp192466vcz; Tue, 29 Oct 2013 03:52:29 -0700 (PDT) X-Received: by 10.224.160.83 with SMTP id m19mr8323462qax.108.1383043949205; Tue, 29 Oct 2013 03:52:29 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id z2si12268019qal.74.2013.10.29.03.52.28 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 29 Oct 2013 03:52:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Vb6uS-0001pA-5C for ; Tue, 29 Oct 2013 10:52:28 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 16A39E0013 for ; Tue, 29 Oct 2013 10:52:28 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 285 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 285: NativeStateMir: Update for newest Mir client API Message-Id: <20131029105228.12635.90857.launchpad@ackee.canonical.com> Date: Tue, 29 Oct 2013 10:52:28 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: list X-Generated-By: Launchpad (canonical.com); Revision="16818"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: a7f689d9334a8c20078be9b5b300a917d86c5e6b X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: noreply@launchpad.net X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , ------------------------------------------------------------ revno: 285 committer: Alexandros Frantzis branch nick: update-mir timestamp: Fri 2013-10-18 17:57:00 +0300 message: NativeStateMir: Update for newest Mir client API modified: src/native-state-mir.cpp src/native-state-mir.h --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'src/native-state-mir.cpp' --- src/native-state-mir.cpp 2013-03-05 17:37:01 +0000 +++ src/native-state-mir.cpp 2013-10-18 14:57:00 +0000 @@ -29,25 +29,89 @@ namespace { -void -connected_callback(MirConnection *connection, void *client_context) -{ - MirConnection **con = static_cast(client_context); - *con = connection; -} - -void -surface_created_callback(MirSurface *surface, void *client_context) -{ - MirSurface **surf = static_cast(client_context); - *surf = surface; -} - -void -null_surface_callback(MirSurface * /*obj*/, void * /*client_context*/) -{ -} - +const MirDisplayOutput* +find_active_output(const MirDisplayConfiguration* conf) +{ + const MirDisplayOutput *output = NULL; + + for (uint32_t d = 0; d < conf->num_outputs; d++) + { + const MirDisplayOutput* out = &conf->outputs[d]; + + if (out->used && out->connected && + out->num_modes && out->current_mode < out->num_modes) + { + output = out; + break; + } + } + + return output; +} + +MirPixelFormat +find_best_surface_format(MirConnection* connection) +{ + static const unsigned int formats_size = 10; + MirPixelFormat formats[formats_size]; + unsigned int num_valid_formats = 0; + MirPixelFormat best_format = mir_pixel_format_invalid; + + mir_connection_get_available_surface_formats(connection, + formats, + formats_size, + &num_valid_formats); + + /* + * Surface formats come sorted in largest active bits order. + * Prefer opaque formats over formats with alpha, and largest + * formats over smaller ones. + */ + for (unsigned int i = 0; i < num_valid_formats; i++) + { + if (formats[i] == mir_pixel_format_xbgr_8888 || + formats[i] == mir_pixel_format_xrgb_8888 || + formats[i] == mir_pixel_format_bgr_888) + { + best_format = formats[i]; + break; + } + else if (best_format == mir_pixel_format_invalid) + { + best_format = formats[i]; + } + } + + return best_format; +} + +class DisplayConfiguration +{ +public: + DisplayConfiguration(MirConnection* connection) + : display_config(mir_connection_create_display_config(connection)) + { + } + + ~DisplayConfiguration() + { + if (display_config) + mir_display_config_destroy(display_config); + } + + bool is_valid() + { + return display_config != 0; + } + + operator MirDisplayConfiguration*() const + { + return display_config; + } + +private: + MirDisplayConfiguration* display_config; +}; } volatile sig_atomic_t NativeStateMir::should_quit_(false); @@ -55,8 +119,8 @@ NativeStateMir::~NativeStateMir() { if (mir_surface_) - mir_wait_for(mir_surface_release(mir_surface_, null_surface_callback, 0)); - if (mir_connection_is_valid(mir_connection_)) + mir_surface_release_sync(mir_surface_); + if (mir_connection_) mir_connection_release(mir_connection_); } @@ -71,11 +135,10 @@ sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); - mir_wait_for(mir_connect("/tmp/mir_socket", "glmark2", - connected_callback, &mir_connection_)); + mir_connection_ = mir_connect_sync(NULL, "glmark2"); if (!mir_connection_is_valid(mir_connection_)) { - Log::error("Failed to connect to mir\n"); + Log::error("Couldn't connect to the Mir display server\n"); return false; } @@ -97,7 +160,8 @@ static const char *win_name("glmark2 "GLMARK_VERSION); if (!mir_connection_is_valid(mir_connection_)) { - Log::error("No connection to mir!\n"); + Log::error("Cannot create a Mir surface without a valid connection " + "to the Mir display server!\n"); return false; } @@ -108,7 +172,7 @@ (properties_.width != properties.width || properties_.height != properties.height))) { - mir_wait_for(mir_surface_release(mir_surface_, null_surface_callback, 0)); + mir_surface_release_sync(mir_surface_); mir_surface_ = 0; } else @@ -117,28 +181,55 @@ } } - MirDisplayInfo display_info; - mir_connection_get_display_info(mir_connection_, &display_info); + uint32_t output_id = mir_display_output_id_invalid; properties_ = properties; if (properties_.fullscreen) { - properties_.width = display_info.width; - properties_.height = display_info.height; - } + DisplayConfiguration display_config(mir_connection_); + if (!display_config.is_valid()) { + Log::error("Couldn't get display configuration from the Mir display server!\n"); + return false; + } + + const MirDisplayOutput* active_output = find_active_output(display_config); + if (active_output == NULL) { + Log::error("Couldn't find an active output in the Mir display server!\n"); + return false; + } + + const MirDisplayMode* current_mode = + &active_output->modes[active_output->current_mode]; + + properties_.width = current_mode->horizontal_resolution; + properties_.height = current_mode->vertical_resolution; + output_id = active_output->output_id; + + Log::debug("Making Mir surface fullscreen on output %u (%ux%u)\n", + output_id, properties_.width, properties_.height); + } + + MirPixelFormat surface_format = find_best_surface_format(mir_connection_); + if (surface_format == mir_pixel_format_invalid) { + Log::error("Couldn't find a pixel format to use for the Mir surface!\n"); + return false; + } + + Log::debug("Using pixel format %u for the Mir surface\n", surface_format); MirSurfaceParameters surface_parameters = { win_name, properties_.width, properties_.height, - display_info.supported_pixel_format[0], - mir_buffer_usage_hardware + surface_format, + mir_buffer_usage_hardware, + output_id }; - mir_wait_for(mir_surface_create(mir_connection_, &surface_parameters, - surface_created_callback, &mir_surface_)); + mir_surface_ = mir_connection_create_surface_sync(mir_connection_, + &surface_parameters); - if (!mir_surface_) { - Log::error("Failed to create mir surface!\n"); + if (!mir_surface_ || !mir_surface_is_valid(mir_surface_)) { + Log::error("Failed to create Mir surface!\n"); return false; } === modified file 'src/native-state-mir.h' --- src/native-state-mir.h 2013-03-05 17:04:09 +0000 +++ src/native-state-mir.h 2013-10-18 14:57:00 +0000 @@ -23,7 +23,7 @@ #define GLMARK2_NATIVE_STATE_MIR_H_ #include "native-state.h" -#include +#include #include class NativeStateMir : public NativeState