1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef WR_h
8 #define WR_h
9 
10 #include "mozilla/gfx/Types.h"
11 #include "nsTArray.h"
12 
13 extern "C" {
14 
15 // ----
16 // Functions invoked from Rust code
17 // ----
18 
19 bool is_in_compositor_thread();
20 bool is_in_main_thread();
21 bool is_in_render_thread();
22 bool is_glcontext_gles(void* glcontext_ptr);
23 bool is_glcontext_angle(void* glcontext_ptr);
24 bool gfx_use_wrench();
25 const char* gfx_wr_resource_path_override();
26 bool gfx_wr_use_optimized_shaders();
27 void gfx_critical_note(const char* msg);
28 void gfx_critical_error(const char* msg);
29 void gecko_printf_stderr_output(const char* msg);
30 void* get_proc_address_from_glcontext(void* glcontext_ptr,
31                                       const char* procname);
32 
33 void gecko_profiler_start_marker(const char* name);
34 void gecko_profiler_end_marker(const char* name);
35 void gecko_profiler_event_marker(const char* name);
36 void gecko_profiler_add_text_marker(const char* name, const char* text_ptr,
37                                     size_t text_len, uint64_t microseconds);
38 bool gecko_profiler_thread_is_being_profiled();
39 
40 // IMPORTANT: Keep this synchronized with enumerate_interners in
41 // gfx/wr/webrender_api
42 #define WEBRENDER_FOR_EACH_INTERNER(macro) \
43   macro(clip);                             \
44   macro(prim);                             \
45   macro(normal_border);                    \
46   macro(image_border);                     \
47   macro(image);                            \
48   macro(yuv_image);                        \
49   macro(line_decoration);                  \
50   macro(linear_grad);                      \
51   macro(radial_grad);                      \
52   macro(conic_grad);                       \
53   macro(picture);                          \
54   macro(text_run);                         \
55   macro(filterdata);                       \
56   macro(backdrop);                         \
57   macro(polyon);
58 
59 // Prelude of types necessary before including webrender_ffi_generated.h
60 namespace mozilla {
61 namespace wr {
62 
63 // Because this struct is macro-generated on the Rust side, cbindgen can't see
64 // it. Work around that by re-declaring it here.
65 #define DECLARE_MEMBER(id) uintptr_t id;
66 struct InternerSubReport {
67   WEBRENDER_FOR_EACH_INTERNER(DECLARE_MEMBER)
68 };
69 
70 #undef DECLARE_MEMBER
71 
72 struct Transaction;
73 struct WrWindowId;
74 struct DocumentId;
75 struct WrPipelineInfo;
76 
77 struct WrPipelineIdAndEpoch;
78 using WrPipelineIdEpochs = nsTArray<WrPipelineIdAndEpoch>;
79 
80 const uint64_t ROOT_CLIP_CHAIN = ~0;
81 
82 }  // namespace wr
83 }  // namespace mozilla
84 
85 void apz_register_updater(mozilla::wr::WrWindowId aWindowId);
86 void apz_pre_scene_swap(mozilla::wr::WrWindowId aWindowId);
87 void apz_post_scene_swap(mozilla::wr::WrWindowId aWindowId,
88                          const mozilla::wr::WrPipelineInfo* aInfo);
89 void apz_run_updater(mozilla::wr::WrWindowId aWindowId);
90 void apz_deregister_updater(mozilla::wr::WrWindowId aWindowId);
91 
92 void apz_register_sampler(mozilla::wr::WrWindowId aWindowId);
93 void apz_sample_transforms(mozilla::wr::WrWindowId aWindowId,
94                            const uint64_t* aGeneratedFrameId,
95                            mozilla::wr::Transaction* aTransaction);
96 void apz_deregister_sampler(mozilla::wr::WrWindowId aWindowId);
97 
98 void omta_register_sampler(mozilla::wr::WrWindowId aWindowId);
99 void omta_sample(mozilla::wr::WrWindowId aWindowId,
100                  mozilla::wr::Transaction* aTransaction);
101 void omta_deregister_sampler(mozilla::wr::WrWindowId aWindowId);
102 }  // extern "C"
103 
104 // Work-around wingdi.h define which conflcits with WR color constant
105 #pragma push_macro("TRANSPARENT")
106 #undef TRANSPARENT
107 
108 #include "webrender_ffi_generated.h"
109 
110 #pragma pop_macro("TRANSPARENT")
111 
112 // More functions invoked from Rust code. These are down here because they
113 // refer to data structures from webrender_ffi_generated.h
114 extern "C" {
115 void record_telemetry_time(mozilla::wr::TelemetryProbe aProbe,
116                            uint64_t aTimeNs);
117 }
118 
119 namespace mozilla {
120 namespace wr {
121 
122 // Cast a blob image key into a regular image for use in
123 // a display item.
AsImageKey(BlobImageKey aKey)124 inline ImageKey AsImageKey(BlobImageKey aKey) { return aKey._0; }
125 
126 }  // namespace wr
127 }  // namespace mozilla
128 
129 #endif  // WR_h
130