1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18 #pragma once 19 20 #include <stdint.h> 21 #include <mutex> 22 23 #include <wayland-server-core.h> 24 25 namespace wayland { 26 27 class Surfaces; 28 29 // Tracks the buffer associated with a Wayland surface. 30 class Surface { 31 public: 32 Surface(std::uint32_t display_number, Surfaces& surfaces); 33 virtual ~Surface() = default; 34 35 Surface(const Surface& rhs) = delete; 36 Surface& operator=(const Surface& rhs) = delete; 37 38 Surface(Surface&& rhs) = delete; 39 Surface& operator=(Surface&& rhs) = delete; 40 41 struct Region { 42 int32_t x; 43 int32_t y; 44 int32_t w; 45 int32_t h; 46 }; 47 48 void SetRegion(const Region& region); 49 50 // Sets the buffer of the pending frame. 51 void Attach(struct wl_resource* buffer); 52 53 // Commits the pending frame state. 54 void Commit(); 55 56 private: 57 std::uint32_t display_number_; 58 Surfaces& surfaces_; 59 60 struct State { 61 uint32_t current_frame_number = 0; 62 63 // The buffer for the current committed frame. 64 struct wl_resource* current_buffer = nullptr; 65 66 // The buffer for the next frame. 67 struct wl_resource* pending_buffer = nullptr; 68 69 // The buffers expected dimensions. 70 Region region; 71 }; 72 73 std::mutex state_mutex_; 74 State state_; 75 }; 76 77 } // namespace wayland 78