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 bool gecko_profiler_thread_is_being_profiled();
34 
35 // IMPORTANT: Keep this synchronized with enumerate_interners in
36 // gfx/wr/webrender_api
37 #define WEBRENDER_FOR_EACH_INTERNER(macro) \
38   macro(clip);                             \
39   macro(prim);                             \
40   macro(normal_border);                    \
41   macro(image_border);                     \
42   macro(image);                            \
43   macro(yuv_image);                        \
44   macro(line_decoration);                  \
45   macro(linear_grad);                      \
46   macro(radial_grad);                      \
47   macro(conic_grad);                       \
48   macro(picture);                          \
49   macro(text_run);                         \
50   macro(filterdata);                       \
51   macro(backdrop);                         \
52   macro(polyon);
53 
54 // Prelude of types necessary before including webrender_ffi_generated.h
55 namespace mozilla {
56 namespace wr {
57 
58 // Because this struct is macro-generated on the Rust side, cbindgen can't see
59 // it. Work around that by re-declaring it here.
60 #define DECLARE_MEMBER(id) uintptr_t id;
61 struct InternerSubReport {
62   WEBRENDER_FOR_EACH_INTERNER(DECLARE_MEMBER)
63 };
64 
65 #undef DECLARE_MEMBER
66 
67 struct Transaction;
68 struct WrWindowId;
69 struct DocumentId;
70 struct WrPipelineInfo;
71 
72 struct WrPipelineIdAndEpoch;
73 using WrPipelineIdEpochs = nsTArray<WrPipelineIdAndEpoch>;
74 
75 const uint64_t ROOT_CLIP_CHAIN = ~0;
76 
77 }  // namespace wr
78 }  // namespace mozilla
79 
80 void apz_register_updater(mozilla::wr::WrWindowId aWindowId);
81 void apz_pre_scene_swap(mozilla::wr::WrWindowId aWindowId);
82 void apz_post_scene_swap(mozilla::wr::WrWindowId aWindowId,
83                          const mozilla::wr::WrPipelineInfo* aInfo);
84 void apz_run_updater(mozilla::wr::WrWindowId aWindowId);
85 void apz_deregister_updater(mozilla::wr::WrWindowId aWindowId);
86 
87 void apz_register_sampler(mozilla::wr::WrWindowId aWindowId);
88 void apz_sample_transforms(mozilla::wr::WrWindowId aWindowId,
89                            const uint64_t* aGeneratedFrameId,
90                            mozilla::wr::Transaction* aTransaction);
91 void apz_deregister_sampler(mozilla::wr::WrWindowId aWindowId);
92 
93 void omta_register_sampler(mozilla::wr::WrWindowId aWindowId);
94 void omta_sample(mozilla::wr::WrWindowId aWindowId,
95                  mozilla::wr::Transaction* aTransaction);
96 void omta_deregister_sampler(mozilla::wr::WrWindowId aWindowId);
97 }  // extern "C"
98 
99 // Work-around wingdi.h define which conflcits with WR color constant
100 #pragma push_macro("TRANSPARENT")
101 #undef TRANSPARENT
102 
103 #include "webrender_ffi_generated.h"
104 
105 #pragma pop_macro("TRANSPARENT")
106 
107 template struct mozilla::wr::Point2D<int32_t, mozilla::wr::DevicePixel>;
108 template struct mozilla::wr::Point2D<int, mozilla::wr::WorldPixel>;
109 template struct mozilla::wr::Point2D<float, mozilla::wr::WorldPixel>;
110 template struct mozilla::wr::Box2D<int32_t, mozilla::wr::DevicePixel>;
111 template struct mozilla::wr::Box2D<int, mozilla::wr::LayoutPixel>;
112 
113 // More functions invoked from Rust code. These are down here because they
114 // refer to data structures from webrender_ffi_generated.h
115 extern "C" {
116 void record_telemetry_time(mozilla::wr::TelemetryProbe aProbe,
117                            uint64_t aTimeNs);
118 }
119 
120 namespace mozilla {
121 namespace wr {
122 
123 // Cast a blob image key into a regular image for use in
124 // a display item.
125 inline ImageKey AsImageKey(BlobImageKey aKey) { return aKey._0; }
126 
127 }  // namespace wr
128 }  // namespace mozilla
129 
130 #endif  // WR_h
131