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"
21 #include "GalliumContext.h"
25 # define TRACE(x...) printf("GalliumFramebuffer: " x)
26 # define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
31 #define ERROR(x...) printf("GalliumFramebuffer: " x)
35 hgl_framebuffer_flush_front(struct st_context_iface
*stctx
,
36 struct st_framebuffer_iface
* stfb
, enum st_attachment_type statt
)
40 hgl_context
* context
= (hgl_context
*)stfb
->st_manager_private
;
43 ERROR("%s: Couldn't obtain valid hgl_context!\n", __func__
);
48 struct stw_st_framebuffer
*stwfb
= stw_st_framebuffer(stfb
);
49 pipe_mutex_lock(stwfb
->fb
->mutex
);
51 struct pipe_resource
* resource
= textures
[statt
];
53 stw_framebuffer_present_locked(...);
61 hgl_framebuffer_validate(struct st_context_iface
* stctx
,
62 struct st_framebuffer_iface
* stfb
,
63 const enum st_attachment_type
* statts
, unsigned count
,
64 struct pipe_resource
** out
)
69 ERROR("%s: Invalid st framebuffer interface!\n", __func__
);
73 hgl_context
* context
= (hgl_context
*)stfb
->st_manager_private
;
76 ERROR("%s: Couldn't obtain valid hgl_context!\n", __func__
);
82 get_bitmap_size(context
->bitmap
, &width
, &height
);
84 struct pipe_resource templat
;
85 memset(&templat
, 0, sizeof(templat
));
86 templat
.target
= PIPE_TEXTURE_RECT
;
87 templat
.width0
= width
;
88 templat
.height0
= height
;
90 templat
.array_size
= 1;
91 templat
.usage
= PIPE_USAGE_DEFAULT
;
93 if (context
->stVisual
&& context
->manager
&& context
->manager
->screen
) {
94 TRACE("%s: Updating resources\n", __func__
);
96 for (i
= 0; i
< count
; i
++) {
97 enum pipe_format format
= PIPE_FORMAT_NONE
;
101 case ST_ATTACHMENT_FRONT_LEFT
:
102 format
= context
->stVisual
->color_format
;
103 bind
= PIPE_BIND_RENDER_TARGET
;
105 case ST_ATTACHMENT_DEPTH_STENCIL
:
106 format
= context
->stVisual
->depth_stencil_format
;
107 bind
= PIPE_BIND_DEPTH_STENCIL
;
109 case ST_ATTACHMENT_ACCUM
:
110 format
= context
->stVisual
->accum_format
;
111 bind
= PIPE_BIND_RENDER_TARGET
;
114 ERROR("%s: Unexpected attachment type!\n", __func__
);
116 templat
.format
= format
;
119 struct pipe_screen
* screen
= context
->manager
->screen
;
120 context
->textures
[i
] = screen
->resource_create(screen
, &templat
);
121 out
[i
] = context
->textures
[i
];
129 GalliumFramebuffer::GalliumFramebuffer(struct st_visual
* visual
,
130 void* privateContext
)
135 fBuffer
= CALLOC_STRUCT(st_framebuffer_iface
);
137 ERROR("%s: Couldn't calloc framebuffer!\n", __func__
);
140 fBuffer
->visual
= visual
;
141 fBuffer
->flush_front
= hgl_framebuffer_flush_front
;
142 fBuffer
->validate
= hgl_framebuffer_validate
;
143 fBuffer
->st_manager_private
= privateContext
;
145 pipe_mutex_init(fMutex
);
149 GalliumFramebuffer::~GalliumFramebuffer()
152 // We lock and unlock to try and make sure we wait for anything
153 // using the framebuffer to finish
156 ERROR("%s: Strange, no Gallium Framebuffer to free?\n", __func__
);
162 pipe_mutex_destroy(fMutex
);
167 GalliumFramebuffer::Lock()
170 pipe_mutex_lock(fMutex
);
176 GalliumFramebuffer::Unlock()
179 pipe_mutex_unlock(fMutex
);