15 #include "pandabase.h"
17 #if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON) && !__LP64__
19 #include "tinyOsxGraphicsPipe.h"
20 #include "config_tinydisplay.h"
21 #include "tinyOsxGraphicsWindow.h"
22 #include "tinyGraphicsBuffer.h"
24 #include "subprocessWindow.h"
25 #include "nativeWindowHandle.h"
35 TinyOsxGraphicsPipe() {
36 CGRect display_bounds = CGDisplayBounds(kCGDirectMainDisplay);
37 _display_width = CGRectGetWidth(display_bounds);
38 _display_height = CGRectGetHeight(display_bounds);
47 ~TinyOsxGraphicsPipe() {
60 string TinyOsxGraphicsPipe::
61 get_interface_name()
const {
74 return new TinyOsxGraphicsPipe;
84 CGImageRef TinyOsxGraphicsPipe::
85 create_cg_image(
const PNMImage &pnm_image) {
90 size_t bytes_per_component = 2;
92 size_t bytes_per_component = 1;
94 size_t bits_per_component = bytes_per_component * 8;
97 size_t bits_per_pixel = num_components * bits_per_component;
98 size_t bytes_per_row = num_components * bytes_per_component * width;
100 size_t num_bytes = bytes_per_row * height;
104 CFStringRef color_space_name = NULL;
106 case PNMImage::CT_grayscale:
107 color_space_name = kCGColorSpaceGenericGray;
112 case PNMImage::CT_two_channel:
113 color_space_name = kCGColorSpaceGenericGray;
118 case PNMImage::CT_color:
119 color_space_name = kCGColorSpaceGenericRGB;
121 is_grayscale =
false;
124 case PNMImage::CT_four_channel:
125 color_space_name = kCGColorSpaceGenericRGB;
127 is_grayscale =
false;
130 case PNMImage::CT_invalid:
132 nassertr(
false, NULL);
135 nassertr(color_space_name != NULL, NULL);
137 CGColorSpaceRef color_space = CGColorSpaceCreateWithName(color_space_name);
138 nassertr(color_space != NULL, NULL);
140 CGBitmapInfo bitmap_info = 0;
142 bitmap_info |= kCGBitmapByteOrder16Host;
145 bitmap_info |= kCGImageAlphaLast;
150 char *char_array = (
char *)PANDA_MALLOC_ARRAY(num_bytes);
152 xelval *dp = (xelval *)char_array;
153 for (
size_t yi = 0; yi < height; ++yi) {
154 for (
size_t xi = 0; xi < width; ++xi) {
156 *dp++ = (xelval)(pnm_image.
get_gray(xi, yi) * PGM_MAXMAXVAL);
158 *dp++ = (xelval)(pnm_image.
get_red(xi, yi) * PGM_MAXMAXVAL);
159 *dp++ = (xelval)(pnm_image.
get_green(xi, yi) * PGM_MAXMAXVAL);
160 *dp++ = (xelval)(pnm_image.
get_blue(xi, yi) * PGM_MAXMAXVAL);
163 *dp++ = (xelval)(pnm_image.
get_alpha(xi, yi) * PGM_MAXMAXVAL);
167 nassertr((
void *)dp == (
void *)(char_array + num_bytes), NULL);
169 CGDataProviderRef provider =
170 CGDataProviderCreateWithData(NULL, char_array, num_bytes, release_data);
171 nassertr(provider != NULL, NULL);
173 CGImageRef image = CGImageCreate
174 (width, height, bits_per_component, bits_per_pixel, bytes_per_row,
175 color_space, bitmap_info, provider,
176 NULL,
false, kCGRenderingIntentDefault);
177 nassertr(image != NULL, NULL);
179 CGColorSpaceRelease(color_space);
180 CGDataProviderRelease(provider);
191 void TinyOsxGraphicsPipe::
192 release_data(
void *info,
const void *data,
size_t size) {
193 char *char_array = (
char *)data;
194 PANDA_FREE_ARRAY(char_array);
204 make_output(const
string &name,
220 DCAST_INTO_R(tinygsg, gsg, NULL);
226 if (((flags&BF_require_parasite)!=0)||
227 ((flags&BF_refuse_window)!=0)||
228 ((flags&BF_resizeable)!=0)||
229 ((flags&BF_size_track_host)!=0)||
230 ((flags&BF_rtt_cumulative)!=0)||
231 ((flags&BF_can_bind_color)!=0)||
232 ((flags&BF_can_bind_every)!=0)) {
235 if ((flags & BF_fb_props_optional)==0) {
236 if ((fb_prop.get_aux_rgba() > 0)||
237 (fb_prop.get_aux_hrgba() > 0)||
238 (fb_prop.get_aux_float() > 0)) {
242 WindowHandle *window_handle = win_prop.get_parent_window();
243 if (window_handle != NULL) {
244 tinydisplay_cat.info()
245 <<
"Got parent_window " << *window_handle <<
"\n";
246 #ifdef SUPPORT_SUBPROCESS_WINDOW
248 if (os_handle != NULL &&
249 os_handle->
is_of_type(NativeWindowHandle::SubprocessHandle::get_class_type())) {
250 return new SubprocessWindow(engine,
this, name, fb_prop, win_prop,
253 #endif // SUPPORT_SUBPROCESS_WINDOW
255 return new TinyOsxGraphicsWindow(engine,
this, name, fb_prop, win_prop,
261 if (((flags&BF_require_parasite)!=0)||
262 ((flags&BF_require_window)!=0)) {
265 return new TinyGraphicsBuffer(engine,
this, name, fb_prop, win_prop, flags, gsg, host);
This object represents a window on the desktop, not necessarily a Panda window.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
float get_red(int x, int y) const
Returns the red component color at the indicated pixel.
float get_blue(int x, int y) const
Returns the blue component color at the indicated pixel.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
float get_gray(int x, int y) const
Returns the gray component color at the indicated pixel.
An offscreen graphics buffer.
float get_alpha(int x, int y) const
Returns the alpha component color at the indicated pixel.
float get_green(int x, int y) const
Returns the green component color at the indicated pixel.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An object to create GraphicsOutputs that share a particular 3-D API.
This is a base class for the various different classes that represent the result of a frame of render...
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
OSHandle * get_os_handle() const
Returns the OS-specific handle stored internally to the WindowHandle wrapper.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
An interface to the TinyPanda software rendering code within this module.