window_bounds are now coordinates of the view on the screen (was the window before)
this eases dramatically the drawing of the clip from the buffer
now allocates m_clip_info whenever needed as some apps call EnableDirectMode() after DirectConnected(), ie GLTeapot.
MesaSoftwareRenderer:
implemented DirectConnected() support in Mesa Software Renderer
tested with GLTeapot on QEmu, B_RGB16 mode only


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20797 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-04-24 17:37:51 +00:00
parent f8486a0219
commit 7cfdfca2e2
3 changed files with 289 additions and 173 deletions
@@ -16,6 +16,8 @@
#define CALLED() //printf("CALLED %s\n",__PRETTY_FUNCTION__) #define CALLED() //printf("CALLED %s\n",__PRETTY_FUNCTION__)
#include "MesaSoftwareRenderer.h" #include "MesaSoftwareRenderer.h"
#include <GraphicsDefs.h>
#include <Screen.h>
extern "C" { extern "C" {
#include "array_cache/acache.h" #include "array_cache/acache.h"
#include "extensions.h" #include "extensions.h"
@@ -99,6 +101,26 @@ extern const char * color_space_name(color_space space);
DST[ACOMP] = SRC[BE_ACOMP] DST[ACOMP] = SRC[BE_ACOMP]
#include "swrast/s_spantemp.h" #include "swrast/s_spantemp.h"
/* 16-bit RGB */
#define NAME(PREFIX) PREFIX##_RGB16
#define RB_TYPE GLubyte
#define SPAN_VARS \
MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx;
#define INIT_PIXEL_PTR(P, X, Y) \
GLushort *P = (GLushort *) (((GLubyte **) mr->GetRows())[Y] + (X) * 2)
#define INC_PIXEL_PTR(P) P += 1
#define STORE_PIXEL(DST, X, Y, VALUE) \
*DST = ( (((VALUE[RCOMP]) & 0xf8) << 8) | \
(((VALUE[GCOMP]) & 0xfc) << 3) | \
(((VALUE[BCOMP]) ) >> 3) )
#define FETCH_PIXEL(DST, SRC) \
DST[RCOMP] = ((*SRC & 0xf800) >> 8); \
DST[GCOMP] = ((*SRC & 0x07e0) >> 3); \
DST[BCOMP] = ((*SRC & 0x001f) << 3); \
DST[ACOMP] = 0xff
#include "swrast/s_spantemp.h"
extern "C" _EXPORT BGLRenderer * extern "C" _EXPORT BGLRenderer *
instanciate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher) instanciate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher)
{ {
@@ -109,9 +131,12 @@ instanciate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher)
MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDispatcher *dispatcher) MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDispatcher *dispatcher)
: BGLRenderer(view, options, dispatcher), : BGLRenderer(view, options, dispatcher),
fBitmap(NULL), fBitmap(NULL),
fDirectModeEnabled(false),
fInfo(NULL),
fContext(NULL), fContext(NULL),
fVisual(NULL), fVisual(NULL),
fFrameBuffer(NULL) fFrameBuffer(NULL),
fColorSpace(B_NO_COLOR_SPACE)
{ {
CALLED(); CALLED();
@@ -149,9 +174,9 @@ MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDisp
functions.GetString = GetString; functions.GetString = GetString;
functions.UpdateState = UpdateState; functions.UpdateState = UpdateState;
functions.Clear = Clear; //functions.Clear = Clear;
functions.ClearIndex = ClearIndex; //functions.ClearIndex = ClearIndex;
functions.ClearColor = ClearColor; //functions.ClearColor = ClearColor;
functions.Error = Error; functions.Error = Error;
functions.Viewport = Viewport; functions.Viewport = Viewport;
@@ -180,6 +205,8 @@ MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDisp
fRenderBuffer->Data = NULL; fRenderBuffer->Data = NULL;
fRenderBuffer->AllocStorage = RenderbufferStorage; fRenderBuffer->AllocStorage = RenderbufferStorage;
/*switch (fColorSpace) {
case B_RGBA32:
fRenderBuffer->GetRow = get_row_RGBA8; fRenderBuffer->GetRow = get_row_RGBA8;
fRenderBuffer->GetValues = get_values_RGBA8; fRenderBuffer->GetValues = get_values_RGBA8;
fRenderBuffer->PutRow = put_row_RGBA8; fRenderBuffer->PutRow = put_row_RGBA8;
@@ -187,6 +214,17 @@ MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView *view, ulong options, BGLDisp
fRenderBuffer->PutMonoRow = put_mono_row_RGBA8; fRenderBuffer->PutMonoRow = put_mono_row_RGBA8;
fRenderBuffer->PutValues = put_values_RGBA8; fRenderBuffer->PutValues = put_values_RGBA8;
fRenderBuffer->PutMonoValues = put_mono_values_RGBA8; fRenderBuffer->PutMonoValues = put_mono_values_RGBA8;
break;
case B_RGB16:
fRenderBuffer->GetRow = get_row_RGB16;
fRenderBuffer->GetValues = get_values_RGB16;
fRenderBuffer->PutRow = put_row_RGB16;
fRenderBuffer->PutRowRGB = put_row_rgb_RGB16;
fRenderBuffer->PutMonoRow = put_mono_row_RGB16;
fRenderBuffer->PutValues = put_values_RGB16;
fRenderBuffer->PutMonoValues = put_mono_values_RGB16;
break;
}*/
_mesa_add_renderbuffer(fFrameBuffer, BUFFER_FRONT_LEFT, fRenderBuffer); _mesa_add_renderbuffer(fFrameBuffer, BUFFER_FRONT_LEFT, fRenderBuffer);
@@ -235,14 +273,41 @@ MesaSoftwareRenderer::LockGL()
_mesa_make_current(fContext, fFrameBuffer, fFrameBuffer); _mesa_make_current(fContext, fFrameBuffer, fFrameBuffer);
BRect b = GLView()->Bounds(); BRect b = GLView()->Bounds();
color_space cs = B_RGBA32;
if (fDirectModeEnabled && fInfo != NULL) {
cs = BScreen(GLView()->Window()).ColorSpace();
}
uint32 width = b.IntegerWidth() + 1; uint32 width = b.IntegerWidth() + 1;
uint32 height = b.IntegerHeight() + 1; uint32 height = b.IntegerHeight() + 1;
if (width != fWidth || height != fHeight || !fBitmap) { if (width != fWidth || height != fHeight || !fBitmap || cs != fColorSpace) {
if (cs != fColorSpace)
switch (cs) {
case B_RGBA32:
fRenderBuffer->GetRow = get_row_RGBA8;
fRenderBuffer->GetValues = get_values_RGBA8;
fRenderBuffer->PutRow = put_row_RGBA8;
fRenderBuffer->PutRowRGB = put_row_rgb_RGBA8;
fRenderBuffer->PutMonoRow = put_mono_row_RGBA8;
fRenderBuffer->PutValues = put_values_RGBA8;
fRenderBuffer->PutMonoValues = put_mono_values_RGBA8;
break;
case B_RGB16:
fRenderBuffer->GetRow = get_row_RGB16;
fRenderBuffer->GetValues = get_values_RGB16;
fRenderBuffer->PutRow = put_row_RGB16;
fRenderBuffer->PutRowRGB = put_row_rgb_RGB16;
fRenderBuffer->PutMonoRow = put_mono_row_RGB16;
fRenderBuffer->PutValues = put_values_RGB16;
fRenderBuffer->PutMonoValues = put_mono_values_RGB16;
break;
}
// allocate new size of back buffer bitmap // allocate new size of back buffer bitmap
if (fBitmap) if (fBitmap)
delete fBitmap; delete fBitmap;
fColorSpace = cs;
BRect rect(0.0, 0.0, width - 1, height - 1); BRect rect(0.0, 0.0, width - 1, height - 1);
fBitmap = new BBitmap(rect, B_RGBA32); fBitmap = new BBitmap(rect, fColorSpace);
for (uint i = 0; i < height; i++) for (uint i = 0; i < height; i++)
fRowAddr[height - i - 1] = (GLvoid *)((GLubyte *) fBitmap->Bits() + i * fBitmap->BytesPerRow()); fRowAddr[height - i - 1] = (GLvoid *)((GLubyte *) fBitmap->Bits() + i * fBitmap->BytesPerRow());
@@ -270,9 +335,27 @@ MesaSoftwareRenderer::SwapBuffers(bool VSync)
_mesa_notifySwapBuffers(fContext); _mesa_notifySwapBuffers(fContext);
if (fBitmap) { if (fBitmap) {
if (!fDirectModeEnabled || fInfo == NULL) {
GLView()->LockLooper(); GLView()->LockLooper();
GLView()->DrawBitmap(fBitmap); GLView()->DrawBitmap(fBitmap);
GLView()->UnlockLooper(); GLView()->UnlockLooper();
} else {
uint8 bytesPerPixel = fInfo->bits_per_pixel / 8;
uint32 bytesPerRow = fBitmap->BytesPerRow();
for (int i=0; i<fInfo->clip_list_count; i++) {
clipping_rect *clip = &fInfo->clip_list[i];
int32 height = clip->bottom - clip->top + 1;
int32 bytesWidth = (clip->right - clip->left + 1) * bytesPerPixel;
uint8 *p = (uint8 *)fInfo->bits + (clip->top * fInfo->bytes_per_row) + clip->left * bytesPerPixel;
uint8 *b = (uint8 *)fBitmap->Bits() + (clip->top - fInfo->window_bounds.top) * bytesPerRow
+ (clip->left - fInfo->window_bounds.left) * bytesPerPixel;
for (int y = 0; y < height; y++) {
memcpy(p, b, bytesWidth);
p += fInfo->bytes_per_row;
b += bytesPerRow;
}
}
}
} }
} }
@@ -281,8 +364,9 @@ void
MesaSoftwareRenderer::Draw(BRect updateRect) MesaSoftwareRenderer::Draw(BRect updateRect)
{ {
CALLED(); CALLED();
if (fBitmap) if (fBitmap && (!fDirectModeEnabled || (fInfo == NULL)))
GLView()->DrawBitmap(fBitmap, updateRect, updateRect); GLView()->DrawBitmap(fBitmap, updateRect, updateRect);
} }
@@ -483,6 +567,8 @@ MesaSoftwareRenderer::ClearFront(GLcontext *ctx)
BBitmap *bitmap = mr->fBitmap; BBitmap *bitmap = mr->fBitmap;
assert(bitmap); assert(bitmap);
GLuint *start = (GLuint *) bitmap->Bits(); GLuint *start = (GLuint *) bitmap->Bits();
size_t pixelSize = 0;
get_pixel_size_for(bitmap->ColorSpace(), &pixelSize, NULL, NULL);
const GLuint *clearPixelPtr = (const GLuint *) mr->fClearColor; const GLuint *clearPixelPtr = (const GLuint *) mr->fClearColor;
const GLuint clearPixel = B_LENDIAN_TO_HOST_INT32(*clearPixelPtr); const GLuint clearPixel = B_LENDIAN_TO_HOST_INT32(*clearPixelPtr);
@@ -495,7 +581,7 @@ MesaSoftwareRenderer::ClearFront(GLcontext *ctx)
if (all) { if (all) {
const int numPixels = mr->fWidth * mr->fHeight; const int numPixels = mr->fWidth * mr->fHeight;
if (clearPixel == 0) { if (clearPixel == 0) {
memset(start, 0, numPixels * 4); memset(start, 0, numPixels * pixelSize);
} else { } else {
for (int i = 0; i < numPixels; i++) { for (int i = 0; i < numPixels; i++) {
start[i] = clearPixel; start[i] = clearPixel;
@@ -534,3 +620,17 @@ MesaSoftwareRenderer::RenderbufferStorage(GLcontext *ctx, struct gl_renderbuffer
{ {
return GL_TRUE; return GL_TRUE;
} }
void
MesaSoftwareRenderer::EnableDirectMode(bool enabled)
{
fDirectModeEnabled = enabled;
}
void
MesaSoftwareRenderer::DirectConnected(direct_buffer_info *info)
{
fInfo = info;
}
@@ -39,6 +39,9 @@ public:
GLvoid ** GetRows() { return fRowAddr; }; GLvoid ** GetRows() { return fRowAddr; };
virtual void EnableDirectMode(bool enabled);
virtual void DirectConnected(direct_buffer_info *info);
private: private:
static void Error(GLcontext *ctx); static void Error(GLcontext *ctx);
static const GLubyte * GetString(GLcontext *ctx, GLenum name); static const GLubyte * GetString(GLcontext *ctx, GLenum name);
@@ -52,6 +55,8 @@ private:
GLenum internalFormat, GLuint width, GLuint height); GLenum internalFormat, GLuint width, GLuint height);
BBitmap *fBitmap; BBitmap *fBitmap;
bool fDirectModeEnabled;
direct_buffer_info *fInfo;
GLcontext *fContext; GLcontext *fContext;
GLvisual *fVisual; GLvisual *fVisual;
@@ -62,6 +67,7 @@ private:
GLuint fClearIndex; // buffer clear color index GLuint fClearIndex; // buffer clear color index
GLuint fWidth; GLuint fWidth;
GLuint fHeight; GLuint fHeight;
color_space fColorSpace;
GLvoid * fRowAddr[MAX_HEIGHT]; /*< address of first pixel in each image row */ GLvoid * fRowAddr[MAX_HEIGHT]; /*< address of first pixel in each image row */
}; };
+25 -15
View File
@@ -1,3 +1,12 @@
/*
* Copyright 2006-2007, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jérôme Duval, [email protected]
* Philippe Houdoin, [email protected]
* Stefano Ceccherini, [email protected]
*/
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
* Version: 6.1 * Version: 6.1
@@ -35,6 +44,7 @@
struct glview_direct_info { struct glview_direct_info {
direct_buffer_info *direct_info; direct_buffer_info *direct_info;
bool direct_connected; bool direct_connected;
bool enable_direct_mode;
glview_direct_info(); glview_direct_info();
~glview_direct_info(); ~glview_direct_info();
@@ -170,6 +180,11 @@ BGLView::AttachedToWindow()
// Set default OpenGL viewport: // Set default OpenGL viewport:
glViewport(0, 0, Bounds().IntegerWidth(), Bounds().IntegerHeight()); glViewport(0, 0, Bounds().IntegerWidth(), Bounds().IntegerHeight());
if (m_clip_info) {
fRenderer->DirectConnected(((glview_direct_info *)m_clip_info)->direct_info);
fRenderer->EnableDirectMode(((glview_direct_info *)m_clip_info)->enable_direct_mode);
}
return; return;
} }
@@ -285,8 +300,9 @@ BGLView::DirectConnected(direct_buffer_info *info)
// TODO: We should probably prevent the renderer to draw anything // TODO: We should probably prevent the renderer to draw anything
// (lock_draw() ??) while we are in this method // (lock_draw() ??) while we are in this method
if (!m_clip_info/* && m_direct_connection_disabled*/) if (!m_clip_info/* && m_direct_connection_disabled*/) {
return; m_clip_info = new glview_direct_info();
}
glview_direct_info *glviewDirectInfo = (glview_direct_info *)m_clip_info; glview_direct_info *glviewDirectInfo = (glview_direct_info *)m_clip_info;
direct_buffer_info *localInfo = glviewDirectInfo->direct_info; direct_buffer_info *localInfo = glviewDirectInfo->direct_info;
@@ -309,16 +325,12 @@ BGLView::DirectConnected(direct_buffer_info *info)
//localInfo->_dd_type_ = info->_dd_type_; //localInfo->_dd_type_ = info->_dd_type_;
//localInfo->_dd_token_ = info->_dd_token_; //localInfo->_dd_token_ = info->_dd_token_;
localInfo->window_bounds = info->window_bounds;
// Collect the rects into a BRegion, then clip to the view's bounds // Collect the rects into a BRegion, then clip to the view's bounds
BRegion region; BRegion region;
for (uint32 c = 0; c < info->clip_list_count; c++) for (uint32 c = 0; c < info->clip_list_count; c++)
region.Include(info->clip_list[c]); region.Include(info->clip_list[c]);
// TODO: I have the feeling that this Bounds() call won't work here. BRegion boundsRegion = m_bounds.OffsetByCopy(info->window_bounds.left, info->window_bounds.top);
// Probably m_bounds should be used, but it should then be maintained correctly localInfo->window_bounds = boundsRegion.RectAtInt(0); // window_bounds are now view bounds
// on view resizing/moving...
BRegion boundsRegion = m_bounds.OffsetByCopy(localInfo->window_bounds.left, localInfo->window_bounds.top);
region.IntersectWith(&boundsRegion); region.IntersectWith(&boundsRegion);
localInfo->clip_list_count = region.CountRects(); localInfo->clip_list_count = region.CountRects();
@@ -343,15 +355,12 @@ BGLView::DirectConnected(direct_buffer_info *info)
void void
BGLView::EnableDirectMode(bool enabled) 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);
if (!m_clip_info) {
m_clip_info = new glview_direct_info();
}
((glview_direct_info *)m_clip_info)->enable_direct_mode = enabled;
} }
@@ -511,6 +520,7 @@ glview_direct_info::glview_direct_info()
// TODO: See direct_window_data() in app_server's ServerWindow.cpp // TODO: See direct_window_data() in app_server's ServerWindow.cpp
direct_info = (direct_buffer_info *)calloc(1, B_PAGE_SIZE); direct_info = (direct_buffer_info *)calloc(1, B_PAGE_SIZE);
direct_connected = false; direct_connected = false;
enable_direct_mode = false;
} }