Doug Horn | 1427b6a | 2018-12-11 13:19:16 -0800 | [diff] [blame] | 1 | // Copyright 2017 The Fuchsia Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef LIB_UI_SCENIC_CPP_COMMANDS_H_ |
| 6 | #define LIB_UI_SCENIC_CPP_COMMANDS_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <fuchsia/images/cpp/fidl.h> |
| 11 | #include <fuchsia/ui/gfx/cpp/fidl.h> |
| 12 | #include <fuchsia/ui/scenic/cpp/fidl.h> |
| 13 | |
| 14 | namespace scenic { |
| 15 | |
| 16 | constexpr float kZeroesFloat3[3] = {0.f, 0.f, 0.f}; |
| 17 | constexpr float kOnesFloat3[3] = {1.f, 1.f, 1.f}; |
| 18 | // A quaterion that has no rotation. |
| 19 | constexpr float kQuaternionDefault[4] = {0.f, 0.f, 0.f, 1.f}; |
| 20 | |
| 21 | // Helper function for wrapping a GFX command as a Scenic command. |
| 22 | fuchsia::ui::scenic::Command NewCommand(fuchsia::ui::gfx::Command command); |
| 23 | |
| 24 | // Helper function for wrapping an input command as a Scenic command. |
| 25 | fuchsia::ui::scenic::Command NewCommand(fuchsia::ui::input::Command command); |
| 26 | |
| 27 | // Resource creation. |
| 28 | fuchsia::ui::gfx::Command NewCreateMemoryCmd( |
| 29 | uint32_t id, zx::vmo vmo, uint64_t allocation_size, |
| 30 | fuchsia::images::MemoryType memory_type); |
| 31 | fuchsia::ui::gfx::Command NewCreateImageCmd(uint32_t id, uint32_t memory_id, |
| 32 | uint32_t memory_offset, |
| 33 | fuchsia::images::ImageInfo info); |
| 34 | fuchsia::ui::gfx::Command NewCreateImageCmd( |
| 35 | uint32_t id, uint32_t memory_id, uint32_t memory_offset, |
| 36 | fuchsia::images::PixelFormat format, |
| 37 | fuchsia::images::ColorSpace color_space, fuchsia::images::Tiling tiling, |
| 38 | uint32_t width, uint32_t height, uint32_t stride); |
| 39 | fuchsia::ui::gfx::Command NewCreateImagePipeCmd( |
| 40 | uint32_t id, ::fidl::InterfaceRequest<fuchsia::images::ImagePipe> request); |
| 41 | fuchsia::ui::gfx::Command NewCreateBufferCmd(uint32_t id, uint32_t memory_id, |
| 42 | uint32_t memory_offset, |
| 43 | uint32_t num_bytes); |
| 44 | |
| 45 | fuchsia::ui::gfx::Command NewCreateCompositorCmd(uint32_t id); |
| 46 | fuchsia::ui::gfx::Command NewCreateDisplayCompositorCmd(uint32_t id); |
| 47 | fuchsia::ui::gfx::Command NewCreateLayerStackCmd(uint32_t id); |
| 48 | fuchsia::ui::gfx::Command NewCreateLayerCmd(uint32_t id); |
| 49 | |
| 50 | fuchsia::ui::gfx::Command NewCreateSceneCmd(uint32_t id); |
| 51 | fuchsia::ui::gfx::Command NewCreateCameraCmd(uint32_t id, uint32_t scene_id); |
| 52 | fuchsia::ui::gfx::Command NewCreateStereoCameraCmd(uint32_t id, |
| 53 | uint32_t scene_id); |
| 54 | fuchsia::ui::gfx::Command NewCreateRendererCmd(uint32_t id); |
| 55 | fuchsia::ui::gfx::Command NewCreateAmbientLightCmd(uint32_t id); |
| 56 | fuchsia::ui::gfx::Command NewCreateDirectionalLightCmd(uint32_t id); |
| 57 | |
| 58 | fuchsia::ui::gfx::Command NewCreateCircleCmd(uint32_t id, float radius); |
| 59 | fuchsia::ui::gfx::Command NewCreateRectangleCmd(uint32_t id, float width, |
| 60 | float height); |
| 61 | fuchsia::ui::gfx::Command NewCreateRoundedRectangleCmd( |
| 62 | uint32_t id, float width, float height, float top_left_radius, |
| 63 | float top_right_radius, float bottom_right_radius, |
| 64 | float bottom_left_radius); |
| 65 | |
| 66 | // Variant of NewCreateCircleCmd that uses a variable radius instead of a |
| 67 | // constant one set at construction time. |
| 68 | fuchsia::ui::gfx::Command NewCreateVarCircleCmd(uint32_t id, |
| 69 | uint32_t radius_var_id); |
| 70 | // Variant of NewCreateRectangleCmd that uses a variable width/height |
| 71 | // instead of constant ones set at construction time. |
| 72 | fuchsia::ui::gfx::Command NewCreateVarRectangleCmd(uint32_t id, |
| 73 | uint32_t width_var_id, |
| 74 | uint32_t height_var_id); |
| 75 | // Variant of NewCreateRoundedRectangleCmd that uses a variable |
| 76 | // width/height/etc. instead of constant ones set at construction time. |
| 77 | fuchsia::ui::gfx::Command NewCreateVarRoundedRectangleCmd( |
| 78 | uint32_t id, uint32_t width_var_id, uint32_t height_var_id, |
| 79 | uint32_t top_left_radius_var_id, uint32_t top_right_radius_var_id, |
| 80 | uint32_t bottom_left_radius_var_id, uint32_t bottom_right_radius_var_id); |
| 81 | |
| 82 | fuchsia::ui::gfx::Command NewCreateMeshCmd(uint32_t id); |
| 83 | fuchsia::ui::gfx::Command NewCreateMaterialCmd(uint32_t id); |
| 84 | fuchsia::ui::gfx::Command NewCreateClipNodeCmd(uint32_t id); |
| 85 | fuchsia::ui::gfx::Command NewCreateEntityNodeCmd(uint32_t id); |
| 86 | fuchsia::ui::gfx::Command NewCreateOpacityNodeCmd(uint32_t id); |
| 87 | fuchsia::ui::gfx::Command NewCreateShapeNodeCmd(uint32_t id); |
| 88 | fuchsia::ui::gfx::Command NewCreateViewCmd(uint32_t id, zx::eventpair token, |
| 89 | const std::string& debug_name); |
| 90 | fuchsia::ui::gfx::Command NewCreateViewHolderCmd(uint32_t id, |
| 91 | zx::eventpair token, |
| 92 | const std::string& debug_name); |
| 93 | fuchsia::ui::gfx::Command NewCreateVariableCmd(uint32_t id, |
| 94 | fuchsia::ui::gfx::Value value); |
| 95 | |
| 96 | fuchsia::ui::gfx::Command NewReleaseResourceCmd(uint32_t id); |
| 97 | |
| 98 | // Export & Import operations. |
| 99 | fuchsia::ui::gfx::Command NewExportResourceCmd(uint32_t resource_id, |
| 100 | zx::eventpair export_token); |
| 101 | fuchsia::ui::gfx::Command NewImportResourceCmd( |
| 102 | uint32_t resource_id, fuchsia::ui::gfx::ImportSpec spec, |
| 103 | zx::eventpair import_token); |
| 104 | |
| 105 | // Exports the resource and returns an import token in |out_import_token| |
| 106 | // which allows it to be imported into other sessions. |
| 107 | fuchsia::ui::gfx::Command NewExportResourceCmdAsRequest( |
| 108 | uint32_t resource_id, zx::eventpair* out_import_token); |
| 109 | |
| 110 | // Imports the resource and returns an export token in |out_export_token| |
| 111 | // by which another session can export a resource to associate with this import. |
| 112 | fuchsia::ui::gfx::Command NewImportResourceCmdAsRequest( |
| 113 | uint32_t resource_id, fuchsia::ui::gfx::ImportSpec import_spec, |
| 114 | zx::eventpair* out_export_token); |
| 115 | |
| 116 | // View/ViewHolder commands. |
| 117 | fuchsia::ui::gfx::Command NewSetViewPropertiesCmd( |
| 118 | uint32_t view_holder_id, const float bounding_box_min[3], |
| 119 | const float bounding_box_max[3], const float inset_from_min[3], |
| 120 | const float inset_from_max[3]); |
| 121 | fuchsia::ui::gfx::Command NewSetViewPropertiesCmd( |
| 122 | uint32_t view_holder_id, const fuchsia::ui::gfx::ViewProperties& props); |
| 123 | |
| 124 | // Node operations. |
| 125 | fuchsia::ui::gfx::Command NewAddChildCmd(uint32_t node_id, uint32_t child_id); |
| 126 | fuchsia::ui::gfx::Command NewAddPartCmd(uint32_t node_id, uint32_t part_id); |
| 127 | fuchsia::ui::gfx::Command NewDetachCmd(uint32_t node_id); |
| 128 | fuchsia::ui::gfx::Command NewDetachChildrenCmd(uint32_t node_id); |
| 129 | fuchsia::ui::gfx::Command NewSetTranslationCmd(uint32_t node_id, |
| 130 | const float translation[3]); |
| 131 | fuchsia::ui::gfx::Command NewSetTranslationCmd(uint32_t node_id, |
| 132 | uint32_t variable_id); |
| 133 | fuchsia::ui::gfx::Command NewSetScaleCmd(uint32_t node_id, |
| 134 | const float scale[3]); |
| 135 | fuchsia::ui::gfx::Command NewSetScaleCmd(uint32_t node_id, |
| 136 | uint32_t variable_id); |
| 137 | fuchsia::ui::gfx::Command NewSetRotationCmd(uint32_t node_id, |
| 138 | const float quaternion[4]); |
| 139 | fuchsia::ui::gfx::Command NewSetRotationCmd(uint32_t node_id, |
| 140 | uint32_t variable_id); |
| 141 | fuchsia::ui::gfx::Command NewSetAnchorCmd(uint32_t node_id, |
| 142 | const float anchor[3]); |
| 143 | fuchsia::ui::gfx::Command NewSetAnchorCmd(uint32_t node_id, |
| 144 | uint32_t variable_id); |
| 145 | |
| 146 | fuchsia::ui::gfx::Command NewSetOpacityCmd(uint32_t node_id, float opacity); |
| 147 | fuchsia::ui::gfx::Command NewSendSizeChangeHintCmdHACK( |
| 148 | uint32_t node_id, float width_change_factor, float height_change_factor); |
| 149 | fuchsia::ui::gfx::Command NewSetShapeCmd(uint32_t node_id, uint32_t shape_id); |
| 150 | fuchsia::ui::gfx::Command NewSetMaterialCmd(uint32_t node_id, |
| 151 | uint32_t material_id); |
| 152 | fuchsia::ui::gfx::Command NewSetClipCmd(uint32_t node_id, uint32_t clip_id, |
| 153 | bool clip_to_self); |
| 154 | fuchsia::ui::gfx::Command NewSetTagCmd(uint32_t node_id, uint32_t tag_value); |
| 155 | fuchsia::ui::gfx::Command NewSetHitTestBehaviorCmd( |
| 156 | uint32_t node_id, fuchsia::ui::gfx::HitTestBehavior hit_test_behavior); |
| 157 | fuchsia::ui::gfx::Command NewTakeSnapshotCmdHACK( |
| 158 | uint32_t id, fuchsia::ui::gfx::SnapshotCallbackHACKPtr callback); |
| 159 | |
| 160 | // Camera and lighting operations. |
| 161 | |
| 162 | fuchsia::ui::gfx::Command NewSetCameraCmd(uint32_t renderer_id, |
| 163 | uint32_t camera_id); |
| 164 | fuchsia::ui::gfx::Command NewSetCameraTransformCmd(uint32_t camera_id, |
| 165 | const float eye_position[3], |
| 166 | const float eye_look_at[3], |
| 167 | const float eye_up[3]); |
| 168 | fuchsia::ui::gfx::Command NewSetCameraProjectionCmd(uint32_t camera_id, |
| 169 | const float fovy); |
| 170 | |
| 171 | fuchsia::ui::gfx::Command NewSetCameraPoseBufferCmd(uint32_t camera_id, |
| 172 | uint32_t buffer_id, |
| 173 | uint32_t num_entries, |
| 174 | int64_t base_time, |
| 175 | uint64_t time_interval); |
| 176 | |
| 177 | fuchsia::ui::gfx::Command NewSetStereoCameraProjectionCmd( |
| 178 | uint32_t camera_id, const float left_projection[16], |
| 179 | const float right_projection[16]); |
| 180 | |
| 181 | fuchsia::ui::gfx::Command NewSetLightColorCmd(uint32_t light_id, |
| 182 | const float rgb[3]); |
| 183 | fuchsia::ui::gfx::Command NewSetLightColorCmd(uint32_t light_id, |
| 184 | uint32_t variable_id); |
| 185 | fuchsia::ui::gfx::Command NewSetLightDirectionCmd(uint32_t light_id, |
| 186 | const float direction[3]); |
| 187 | fuchsia::ui::gfx::Command NewSetLightDirectionCmd(uint32_t light_id, |
| 188 | uint32_t variable_id); |
| 189 | fuchsia::ui::gfx::Command NewAddLightCmd(uint32_t scene_id, uint32_t light_id); |
| 190 | fuchsia::ui::gfx::Command NewDetachLightCmd(uint32_t light_id); |
| 191 | fuchsia::ui::gfx::Command NewDetachLightsCmd(uint32_t scene_id); |
| 192 | |
| 193 | // Material operations. |
| 194 | fuchsia::ui::gfx::Command NewSetTextureCmd(uint32_t node_id, uint32_t image_id); |
| 195 | fuchsia::ui::gfx::Command NewSetColorCmd(uint32_t node_id, uint8_t red, |
| 196 | uint8_t green, uint8_t blue, |
| 197 | uint8_t alpha); |
| 198 | |
| 199 | // Mesh operations. |
| 200 | fuchsia::ui::gfx::MeshVertexFormat NewMeshVertexFormat( |
| 201 | fuchsia::ui::gfx::ValueType position_type, |
| 202 | fuchsia::ui::gfx::ValueType normal_type, |
| 203 | fuchsia::ui::gfx::ValueType tex_coord_type); |
| 204 | // These arguments are documented in commands.fidl; see BindMeshBuffersCmd. |
| 205 | fuchsia::ui::gfx::Command NewBindMeshBuffersCmd( |
| 206 | uint32_t mesh_id, uint32_t index_buffer_id, |
| 207 | fuchsia::ui::gfx::MeshIndexFormat index_format, uint64_t index_offset, |
| 208 | uint32_t index_count, uint32_t vertex_buffer_id, |
| 209 | fuchsia::ui::gfx::MeshVertexFormat vertex_format, uint64_t vertex_offset, |
| 210 | uint32_t vertex_count, const float bounding_box_min[3], |
| 211 | const float bounding_box_max[3]); |
| 212 | |
| 213 | // Layer / LayerStack / Compositor operations. |
| 214 | fuchsia::ui::gfx::Command NewAddLayerCmd(uint32_t layer_stack_id, |
| 215 | uint32_t layer_id); |
| 216 | fuchsia::ui::gfx::Command NewRemoveLayerCmd(uint32_t layer_stack_id, |
| 217 | uint32_t layer_id); |
| 218 | fuchsia::ui::gfx::Command NewRemoveAllLayersCmd(uint32_t layer_stack_id); |
| 219 | fuchsia::ui::gfx::Command NewSetLayerStackCmd(uint32_t compositor_id, |
| 220 | uint32_t layer_stack_id); |
| 221 | fuchsia::ui::gfx::Command NewSetRendererCmd(uint32_t layer_id, |
| 222 | uint32_t renderer_id); |
| 223 | fuchsia::ui::gfx::Command NewSetRendererParamCmd( |
| 224 | uint32_t renderer_id, fuchsia::ui::gfx::RendererParam param); |
| 225 | fuchsia::ui::gfx::Command NewSetSizeCmd(uint32_t node_id, const float size[2]); |
| 226 | |
| 227 | // Event operations. |
| 228 | fuchsia::ui::gfx::Command NewSetEventMaskCmd(uint32_t resource_id, |
| 229 | uint32_t event_mask); |
| 230 | |
| 231 | // Diagnostic operations. |
| 232 | fuchsia::ui::gfx::Command NewSetLabelCmd(uint32_t resource_id, |
| 233 | const std::string& label); |
| 234 | |
| 235 | // Debugging operations. |
| 236 | fuchsia::ui::gfx::Command NewSetDisableClippingCmd(uint32_t resource_id, |
| 237 | bool disable_clipping); |
| 238 | |
| 239 | // Basic types. |
| 240 | fuchsia::ui::gfx::FloatValue NewFloatValue(float value); |
| 241 | fuchsia::ui::gfx::Vector2Value NewVector2Value(const float value[2]); |
| 242 | fuchsia::ui::gfx::Vector2Value NewVector2Value(uint32_t variable_id); |
| 243 | fuchsia::ui::gfx::Vector3Value NewVector3Value(const float value[3]); |
| 244 | fuchsia::ui::gfx::Vector3Value NewVector3Value(uint32_t variable_id); |
| 245 | fuchsia::ui::gfx::Vector4Value NewVector4Value(const float value[4]); |
| 246 | fuchsia::ui::gfx::Vector4Value NewVector4Value(uint32_t variable_id); |
| 247 | fuchsia::ui::gfx::QuaternionValue NewQuaternionValue(const float value[4]); |
| 248 | fuchsia::ui::gfx::QuaternionValue NewQuaternionValue(uint32_t variable_id); |
| 249 | fuchsia::ui::gfx::Matrix4Value NewMatrix4Value(const float value[16]); |
| 250 | fuchsia::ui::gfx::Matrix4Value NewMatrix4Value(uint32_t variable_id); |
| 251 | fuchsia::ui::gfx::ColorRgbValue NewColorRgbValue(float red, float green, |
| 252 | float blue); |
| 253 | fuchsia::ui::gfx::ColorRgbValue NewColorRgbValue(uint32_t variable_id); |
| 254 | fuchsia::ui::gfx::ColorRgbaValue NewColorRgbaValue(const uint8_t value[4]); |
| 255 | fuchsia::ui::gfx::ColorRgbaValue NewColorRgbaValue(uint32_t variable_id); |
| 256 | fuchsia::ui::gfx::QuaternionValue NewQuaternionValue(const float value[4]); |
| 257 | fuchsia::ui::gfx::vec2 NewVector2(const float value[2]); |
| 258 | fuchsia::ui::gfx::vec3 NewVector3(const float value[3]); |
| 259 | fuchsia::ui::gfx::vec4 NewVector4(const float value[4]); |
| 260 | |
| 261 | // Utilities. |
| 262 | |
| 263 | bool ImageInfoEquals(const fuchsia::images::ImageInfo& a, |
| 264 | const fuchsia::images::ImageInfo& b); |
| 265 | |
| 266 | } // namespace scenic |
| 267 | |
| 268 | #endif // LIB_UI_SCENIC_CPP_COMMANDS_H_ |