Implemented BGLView::DirectConnected(). I don't know if it works, since
the gldirect_mode test app crashes at startup (also before this commit). Style changes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20636 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+156
-57
@@ -26,13 +26,25 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <DirectWindow.h>
|
||||||
#include <GLView.h>
|
#include <GLView.h>
|
||||||
#include <GLRenderer.h>
|
#include <GLRenderer.h>
|
||||||
|
|
||||||
#include "GLRendererRoster.h"
|
#include "GLRendererRoster.h"
|
||||||
|
|
||||||
|
struct glview_direct_info {
|
||||||
|
direct_buffer_info *direct_info;
|
||||||
|
bool direct_connected;
|
||||||
|
|
||||||
|
glview_direct_info();
|
||||||
|
~glview_direct_info();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
BGLView::BGLView(BRect rect, char *name, ulong resizingMode, ulong mode, ulong options)
|
BGLView::BGLView(BRect rect, char *name, ulong resizingMode, ulong mode, ulong options)
|
||||||
: BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS), // | B_FULL_UPDATE_ON_RESIZE)
|
: BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS), // | B_FULL_UPDATE_ON_RESIZE)
|
||||||
fRenderer(NULL)
|
m_clip_info(NULL),
|
||||||
|
fRenderer(NULL)
|
||||||
{
|
{
|
||||||
fRoster = new GLRendererRoster(this, options);
|
fRoster = new GLRendererRoster(this, options);
|
||||||
}
|
}
|
||||||
@@ -40,11 +52,14 @@ BGLView::BGLView(BRect rect, char *name, ulong resizingMode, ulong mode, ulong o
|
|||||||
|
|
||||||
BGLView::~BGLView()
|
BGLView::~BGLView()
|
||||||
{
|
{
|
||||||
|
delete (glview_direct_info *)m_clip_info;
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
fRenderer->Release();
|
fRenderer->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::LockGL()
|
|
||||||
|
void
|
||||||
|
BGLView::LockGL()
|
||||||
{
|
{
|
||||||
// TODO: acquire the OpenGL API lock it on this glview
|
// TODO: acquire the OpenGL API lock it on this glview
|
||||||
|
|
||||||
@@ -52,7 +67,9 @@ void BGLView::LockGL()
|
|||||||
fRenderer->LockGL();
|
fRenderer->LockGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::UnlockGL()
|
|
||||||
|
void
|
||||||
|
BGLView::UnlockGL()
|
||||||
{
|
{
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
fRenderer->UnlockGL();
|
fRenderer->UnlockGL();
|
||||||
@@ -60,23 +77,31 @@ void BGLView::UnlockGL()
|
|||||||
// TODO: release the GL API lock to others glviews
|
// TODO: release the GL API lock to others glviews
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::SwapBuffers()
|
|
||||||
|
void
|
||||||
|
BGLView::SwapBuffers()
|
||||||
{
|
{
|
||||||
SwapBuffers(false);
|
SwapBuffers(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::SwapBuffers(bool vSync)
|
|
||||||
|
void
|
||||||
|
BGLView::SwapBuffers(bool vSync)
|
||||||
{
|
{
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
fRenderer->SwapBuffers(vSync);
|
fRenderer->SwapBuffers(vSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
BView * BGLView::EmbeddedView()
|
|
||||||
|
BView *
|
||||||
|
BGLView::EmbeddedView()
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
|
|
||||||
|
status_t
|
||||||
|
BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
|
||||||
{
|
{
|
||||||
if (!fRenderer)
|
if (!fRenderer)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -87,7 +112,9 @@ status_t BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
|
|||||||
return fRenderer->CopyPixelsOut(source, dest);
|
return fRenderer->CopyPixelsOut(source, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
|
|
||||||
|
status_t
|
||||||
|
BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
|
||||||
{
|
{
|
||||||
if (!fRenderer)
|
if (!fRenderer)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -98,12 +125,14 @@ status_t BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
|
|||||||
return fRenderer->CopyPixelsIn(source, dest);
|
return fRenderer->CopyPixelsIn(source, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Mesa's GLenum is not ulong but uint, so we can't use GLenum
|
/* Mesa's GLenum is not ulong but uint, so we can't use GLenum
|
||||||
without breaking this method signature.
|
without breaking this method signature.
|
||||||
Instead, we have to use the effective BeOS's SGI OpenGL GLenum type:
|
Instead, we have to use the effective BeOS's SGI OpenGL GLenum type:
|
||||||
unsigned long.
|
unsigned long.
|
||||||
*/
|
*/
|
||||||
void BGLView::ErrorCallback(unsigned long errorCode)
|
void
|
||||||
|
BGLView::ErrorCallback(unsigned long errorCode)
|
||||||
{
|
{
|
||||||
char msg[32];
|
char msg[32];
|
||||||
sprintf(msg, "GL: Error code $%04lx.", errorCode);
|
sprintf(msg, "GL: Error code $%04lx.", errorCode);
|
||||||
@@ -111,7 +140,9 @@ void BGLView::ErrorCallback(unsigned long errorCode)
|
|||||||
fprintf(stderr, "%s\n", msg);
|
fprintf(stderr, "%s\n", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::Draw(BRect updateRect)
|
|
||||||
|
void
|
||||||
|
BGLView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
return fRenderer->Draw(updateRect);
|
return fRenderer->Draw(updateRect);
|
||||||
@@ -121,7 +152,9 @@ void BGLView::Draw(BRect updateRect)
|
|||||||
DrawString("No OpenGL renderer available!");
|
DrawString("No OpenGL renderer available!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::AttachedToWindow()
|
|
||||||
|
void
|
||||||
|
BGLView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
BView::AttachedToWindow();
|
BView::AttachedToWindow();
|
||||||
|
|
||||||
@@ -143,12 +176,16 @@ void BGLView::AttachedToWindow()
|
|||||||
// SetFontSize(16);
|
// SetFontSize(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::AllAttached()
|
|
||||||
|
void
|
||||||
|
BGLView::AllAttached()
|
||||||
{
|
{
|
||||||
BView::AllAttached();
|
BView::AllAttached();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::DetachedFromWindow()
|
|
||||||
|
void
|
||||||
|
BGLView::DetachedFromWindow()
|
||||||
{
|
{
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
fRenderer->Release();
|
fRenderer->Release();
|
||||||
@@ -157,106 +194,155 @@ void BGLView::DetachedFromWindow()
|
|||||||
BView::DetachedFromWindow();
|
BView::DetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::AllDetached()
|
|
||||||
|
void
|
||||||
|
BGLView::AllDetached()
|
||||||
{
|
{
|
||||||
BView::AllDetached();
|
BView::AllDetached();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::FrameResized(float width, float height)
|
|
||||||
|
void
|
||||||
|
BGLView::FrameResized(float width, float height)
|
||||||
{
|
{
|
||||||
|
m_bounds.Set(0, 0, width, height);
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
fRenderer->FrameResized(width, height);
|
fRenderer->FrameResized(width, height);
|
||||||
|
|
||||||
BView::FrameResized(width, height);
|
BView::FrameResized(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BGLView::Perform(perform_code d, void *arg)
|
|
||||||
|
status_t
|
||||||
|
BGLView::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return BView::Perform(d, arg);
|
return BView::Perform(d, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t BGLView::Archive(BMessage *data, bool deep) const
|
status_t
|
||||||
|
BGLView::Archive(BMessage *data, bool deep) const
|
||||||
{
|
{
|
||||||
return BView::Archive(data, deep);
|
return BView::Archive(data, deep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::MessageReceived(BMessage *msg)
|
|
||||||
|
void
|
||||||
|
BGLView::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::SetResizingMode(uint32 mode)
|
|
||||||
|
void
|
||||||
|
BGLView::SetResizingMode(uint32 mode)
|
||||||
{
|
{
|
||||||
BView::SetResizingMode(mode);
|
BView::SetResizingMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::Show()
|
|
||||||
|
void
|
||||||
|
BGLView::Show()
|
||||||
{
|
{
|
||||||
BView::Show();
|
BView::Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::Hide()
|
|
||||||
|
void
|
||||||
|
BGLView::Hide()
|
||||||
{
|
{
|
||||||
BView::Hide();
|
BView::Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
BHandler *BGLView::ResolveSpecifier(BMessage *msg, int32 index,
|
|
||||||
|
BHandler *
|
||||||
|
BGLView::ResolveSpecifier(BMessage *msg, int32 index,
|
||||||
BMessage *specifier, int32 form,
|
BMessage *specifier, int32 form,
|
||||||
const char *property)
|
const char *property)
|
||||||
{
|
{
|
||||||
return BView::ResolveSpecifier(msg, index, specifier, form, property);
|
return BView::ResolveSpecifier(msg, index, specifier, form, property);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t BGLView::GetSupportedSuites(BMessage *data)
|
|
||||||
|
status_t
|
||||||
|
BGLView::GetSupportedSuites(BMessage *data)
|
||||||
{
|
{
|
||||||
return BView::GetSupportedSuites(data);
|
return BView::GetSupportedSuites(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::DirectConnected( direct_buffer_info *info )
|
|
||||||
|
void
|
||||||
|
BGLView::DirectConnected(direct_buffer_info *info)
|
||||||
{
|
{
|
||||||
/* TODO:
|
// TODO: Locking !!!!!
|
||||||
- update local copy of caller's BDirectWindow's direct_buffer_info
|
// TODO: We should probably prevent the renderer to draw anything
|
||||||
- clip it against BGLView's visible region
|
// (lock_draw() ??) while we are in this method
|
||||||
- pass the view's clipped direct_buffer_info to renderer's DirectConnect()
|
|
||||||
*/
|
if (!m_clip_info/* && m_direct_connection_disabled*/)
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (! m_direct_connected && m_direct_connection_disabled)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
direct_info_locker->Lock();
|
glview_direct_info *glviewDirectInfo = (glview_direct_info *)m_clip_info;
|
||||||
|
direct_buffer_info *localInfo = glviewDirectInfo->direct_info;
|
||||||
|
//direct_info_locker->Lock();
|
||||||
switch(info->buffer_state & B_DIRECT_MODE_MASK) {
|
switch(info->buffer_state & B_DIRECT_MODE_MASK) {
|
||||||
case B_DIRECT_START:
|
case B_DIRECT_START:
|
||||||
m_direct_connected = true;
|
glviewDirectInfo->direct_connected = true;
|
||||||
case B_DIRECT_MODIFY:
|
case B_DIRECT_MODIFY:
|
||||||
// Get clipping information
|
{
|
||||||
if (m_clip_list)
|
localInfo->buffer_state = info->buffer_state;
|
||||||
free(m_clip_list);
|
localInfo->driver_state = info->driver_state;
|
||||||
m_clip_list_count = info->clip_list_count;
|
localInfo->bits = info->bits;
|
||||||
m_clip_list = (clipping_rect *) malloc(m_clip_list_count*sizeof(clipping_rect));
|
localInfo->pci_bits = info->pci_bits;
|
||||||
if (m_clip_list) {
|
localInfo->bytes_per_row = info->bytes_per_row;
|
||||||
memcpy(m_clip_list, info->clip_list, m_clip_list_count*sizeof(clipping_rect));
|
localInfo->bits_per_pixel = info->bits_per_pixel;
|
||||||
fBits = (uint8 *) info->bits;
|
localInfo->pixel_format = info->pixel_format;
|
||||||
fRowBytes = info->bytes_per_row;
|
localInfo->layout = info->layout;
|
||||||
fFormat = info->pixel_format;
|
localInfo->orientation = info->orientation;
|
||||||
fBounds = info->window_bounds;
|
//memcpy(&localInfo->_reserved, info->_reserved, sizeof(info->_reserved));
|
||||||
fDirty = true;
|
//localInfo->_dd_type_ = info->_dd_type_;
|
||||||
}
|
//localInfo->_dd_token_ = info->_dd_token_;
|
||||||
break;
|
|
||||||
case B_DIRECT_STOP:
|
localInfo->window_bounds = info->window_bounds;
|
||||||
fConnected = false;
|
|
||||||
break;
|
// Collect the rects into a BRegion, then clip to the view's bounds
|
||||||
|
BRegion region;
|
||||||
|
for (uint32 c = 0; c < info->clip_list_count; c++)
|
||||||
|
region.Include(info->clip_list[c]);
|
||||||
|
// TODO: I have the feeling that this Bounds() call won't work here.
|
||||||
|
// Probably m_bounds should be used, but it should then be maintained correctly
|
||||||
|
// on view resizing/moving...
|
||||||
|
BRegion boundsRegion = Bounds();
|
||||||
|
region.IntersectWith(&boundsRegion);
|
||||||
|
|
||||||
|
localInfo->clip_list_count = region.CountRects();
|
||||||
|
localInfo->clip_bounds = region.FrameInt();
|
||||||
|
|
||||||
|
for (uint32 c = 0; c < localInfo->clip_list_count; c++)
|
||||||
|
localInfo->clip_list[c] = region.RectAtInt(c);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B_DIRECT_STOP:
|
||||||
|
glviewDirectInfo->direct_connected = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
direct_info_locker->Unlock();
|
//direct_info_locker->Unlock();
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
fRenderer->DirectConnected(info);
|
fRenderer->DirectConnected(localInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BGLView::EnableDirectMode( bool enabled )
|
|
||||||
|
void
|
||||||
|
BGLView::EnableDirectMode(bool enabled)
|
||||||
{
|
{
|
||||||
|
if (!m_clip_info && enabled)
|
||||||
|
m_clip_info = new glview_direct_info();
|
||||||
|
else if (m_clip_info && !enabled) {
|
||||||
|
delete (glview_direct_info *)m_clip_info;
|
||||||
|
m_clip_info = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (fRenderer)
|
if (fRenderer)
|
||||||
fRenderer->EnableDirectMode(enabled);
|
fRenderer->EnableDirectMode(enabled);
|
||||||
}
|
}
|
||||||
@@ -413,3 +499,16 @@ const char * color_space_name(color_space space)
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
glview_direct_info::glview_direct_info()
|
||||||
|
{
|
||||||
|
// TODO: See direct_window_data() in app_server's ServerWindow.cpp
|
||||||
|
direct_info = (direct_buffer_info *)malloc(sizeof(B_PAGE_SIZE));
|
||||||
|
direct_connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
glview_direct_info::~glview_direct_info()
|
||||||
|
{
|
||||||
|
free(direct_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user