1#include <stdio.h> 2 3#include <Accelerant.h> 4#include <DirectWindow.h> 5 6#include "DWindowBuffer.h" 7 8// constructor 9DWindowBuffer::DWindowBuffer() 10 : fBits(NULL), 11 fWidth(0), 12 fHeight(0), 13 fBytesPerRow(0), 14 fFormat(B_NO_COLOR_SPACE), 15 fWindowClipping() 16{ 17} 18 19// destructor 20DWindowBuffer::~DWindowBuffer() 21{ 22} 23 24// InitCheck 25status_t 26DWindowBuffer::InitCheck() const 27{ 28 if (fBits) 29 return B_OK; 30 31 return B_NO_INIT; 32} 33 34// ColorSpace 35color_space 36DWindowBuffer::ColorSpace() const 37{ 38 return fFormat; 39} 40 41// Bits 42void* 43DWindowBuffer::Bits() const 44{ 45 return (void*)fBits; 46} 47 48// BytesPerRow 49uint32 50DWindowBuffer::BytesPerRow() const 51{ 52 return fBytesPerRow; 53} 54 55// Width 56uint32 57DWindowBuffer::Width() const 58{ 59 return fWidth; 60} 61 62// Height 63uint32 64DWindowBuffer::Height() const 65{ 66 return fHeight; 67} 68 69// Set 70void 71DWindowBuffer::SetTo(direct_buffer_info* info) 72{ 73 fWindowClipping.MakeEmpty(); 74 75 if (info) { 76 int32 xOffset = info->window_bounds.left; 77 int32 yOffset = info->window_bounds.top; 78 // Get clipping information 79 for (uint32 i = 0; i < info->clip_list_count; i++) { 80 fWindowClipping.Include(info->clip_list[i]); 81 } 82 fWindowClipping.OffsetBy(xOffset, yOffset); 83 84 fBytesPerRow = info->bytes_per_row; 85 fBits = (uint8*)info->bits; 86 fFormat = info->pixel_format; 87 fWidth = info->window_bounds.right - info->window_bounds.left + 1; 88 fHeight = info->window_bounds.bottom - info->window_bounds.top + 1; 89 // offset bits to left top corner of window 90 fBits += xOffset * 4 + yOffset * fBytesPerRow; 91 } else { 92 fBits = NULL; 93 fWidth = 0; 94 fHeight = 0; 95 fBytesPerRow = 0; 96 fFormat = B_NO_COLOR_SPACE; 97 } 98} 99 100// SetTo 101void 102DWindowBuffer::SetTo(frame_buffer_config* config, 103 uint32 x, uint32 y, 104 uint32 width, uint32 height, 105 color_space format) 106{ 107 fBits = (uint8*)config->frame_buffer; 108 fBytesPerRow = config->bytes_per_row; 109 fBits += x * 4 + y * fBytesPerRow; 110 fWidth = width; 111 fHeight = height; 112 fFormat = format; 113} 114