2 * Copyright 2012-2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Artur Wyszynski, harakash@gmail.com
7 * Alexander von Gluck IV, kallisti5@unixzen.com
11 #include "GalliumFramebuffer.h"
14 #include "main/context.h"
15 #include "main/framebuffer.h"
16 #include "main/renderbuffer.h"
17 #include "pipe/p_format.h"
18 #include "state_tracker/st_manager.h"
19 #include "util/u_memory.h"
22 #include "GalliumContext.h"
26 # define TRACE(x...) printf("GalliumFramebuffer: " x)
27 # define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
32 #define ERROR(x...) printf("GalliumFramebuffer: " x)
36 hgl_framebuffer_flush_front(struct st_context_iface
*stctx
,
37 struct st_framebuffer_iface
* stfb
, enum st_attachment_type statt
)
41 hgl_context
* context
= (hgl_context
*)stfb
->st_manager_private
;
44 ERROR("%s: Couldn't obtain valid hgl_context!\n", __func__
);
49 struct stw_st_framebuffer
*stwfb
= stw_st_framebuffer(stfb
);
50 pipe_mutex_lock(stwfb
->fb
->mutex
);
52 struct pipe_resource
* resource
= textures
[statt
];
54 stw_framebuffer_present_locked(...);
62 hgl_framebuffer_validate(struct st_context_iface
* stctx
,
63 struct st_framebuffer_iface
* stfb
,
64 const enum st_attachment_type
* statts
, unsigned count
,
65 struct pipe_resource
** out
)
70 ERROR("%s: Invalid st framebuffer interface!\n", __func__
);
74 hgl_context
* context
= (hgl_context
*)stfb
->st_manager_private
;
77 ERROR("%s: Couldn't obtain valid hgl_context!\n", __func__
);
83 get_bitmap_size(context
->bitmap
, &width
, &height
);
85 struct pipe_resource templat
;
86 memset(&templat
, 0, sizeof(templat
));
87 templat
.target
= PIPE_TEXTURE_RECT
;
88 templat
.width0
= width
;
89 templat
.height0
= height
;
91 templat
.array_size
= 1;
92 templat
.usage
= PIPE_USAGE_DEFAULT
;
94 if (context
->stVisual
&& context
->manager
&& context
->manager
->screen
) {
95 TRACE("%s: Updating resources\n", __func__
);
97 for (i
= 0; i
< count
; i
++) {
98 enum pipe_format format
= PIPE_FORMAT_NONE
;
102 case ST_ATTACHMENT_FRONT_LEFT
:
103 case ST_ATTACHMENT_BACK_LEFT
:
104 format
= context
->stVisual
->color_format
;
105 bind
= PIPE_BIND_DISPLAY_TARGET
106 | PIPE_BIND_RENDER_TARGET
;
108 case ST_ATTACHMENT_DEPTH_STENCIL
:
109 format
= context
->stVisual
->depth_stencil_format
;
110 bind
= PIPE_BIND_DEPTH_STENCIL
;
112 case ST_ATTACHMENT_ACCUM
:
113 format
= context
->stVisual
->accum_format
;
114 bind
= PIPE_BIND_RENDER_TARGET
;
117 format
= PIPE_FORMAT_NONE
;
121 if (format
!= PIPE_FORMAT_NONE
) {
122 templat
.format
= format
;
125 struct pipe_screen
* screen
= context
->manager
->screen
;
126 context
->textures
[i
] = screen
->resource_create(screen
, &templat
);
127 out
[i
] = context
->textures
[i
];
136 GalliumFramebuffer::GalliumFramebuffer(struct st_visual
* visual
,
137 void* privateContext
)
142 fBuffer
= CALLOC_STRUCT(st_framebuffer_iface
);
144 ERROR("%s: Couldn't calloc framebuffer!\n", __func__
);
147 fBuffer
->visual
= visual
;
148 fBuffer
->flush_front
= hgl_framebuffer_flush_front
;
149 fBuffer
->validate
= hgl_framebuffer_validate
;
150 fBuffer
->st_manager_private
= privateContext
;
152 pipe_mutex_init(fMutex
);
156 GalliumFramebuffer::~GalliumFramebuffer()
159 // We lock and unlock to try and make sure we wait for anything
160 // using the framebuffer to finish
163 ERROR("%s: Strange, no Gallium Framebuffer to free?\n", __func__
);
169 pipe_mutex_destroy(fMutex
);
174 GalliumFramebuffer::Lock()
177 pipe_mutex_lock(fMutex
);
183 GalliumFramebuffer::Unlock()
186 pipe_mutex_unlock(fMutex
);