1 /* 2 * Copyright 2005 Michael Lotz <mmlr@mlotz.ch> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 6 //! A RenderingBuffer implementation that accesses graphics memory directly. 7 8 9 #include "AccelerantBuffer.h" 10 11 12 AccelerantBuffer::AccelerantBuffer() 13 : fDisplayModeSet(false), 14 fFrameBufferConfigSet(false), 15 fIsOffscreenBuffer(false) 16 { 17 } 18 19 20 AccelerantBuffer::AccelerantBuffer(const display_mode& mode, 21 const frame_buffer_config& config) 22 : fDisplayModeSet(false), 23 fFrameBufferConfigSet(false), 24 fIsOffscreenBuffer(false) 25 { 26 SetDisplayMode(mode); 27 SetFrameBufferConfig(config); 28 } 29 30 31 AccelerantBuffer::AccelerantBuffer(const AccelerantBuffer& other, 32 bool offscreenBuffer) 33 : fDisplayMode(other.fDisplayMode), 34 fFrameBufferConfig(other.fFrameBufferConfig), 35 fDisplayModeSet(other.fDisplayModeSet), 36 fFrameBufferConfigSet(other.fFrameBufferConfigSet), 37 fIsOffscreenBuffer(other.fIsOffscreenBuffer || offscreenBuffer) 38 { 39 } 40 41 42 AccelerantBuffer::~AccelerantBuffer() 43 { 44 } 45 46 47 status_t 48 AccelerantBuffer::InitCheck() const 49 { 50 if (fDisplayModeSet && fFrameBufferConfigSet) 51 return B_OK; 52 53 return B_NO_INIT; 54 } 55 56 57 color_space 58 AccelerantBuffer::ColorSpace() const 59 { 60 if (InitCheck() == B_OK) 61 return (color_space)fDisplayMode.space; 62 63 return B_NO_COLOR_SPACE; 64 } 65 66 67 void* 68 AccelerantBuffer::Bits() const 69 { 70 if (InitCheck() != B_OK) 71 return NULL; 72 73 uint8* bits = (uint8*)fFrameBufferConfig.frame_buffer; 74 75 if (fIsOffscreenBuffer) 76 bits += fDisplayMode.virtual_height * fFrameBufferConfig.bytes_per_row; 77 78 return bits; 79 } 80 81 82 uint32 83 AccelerantBuffer::BytesPerRow() const 84 { 85 if (InitCheck() == B_OK) 86 return fFrameBufferConfig.bytes_per_row; 87 88 return 0; 89 } 90 91 92 uint32 93 AccelerantBuffer::Width() const 94 { 95 if (InitCheck() == B_OK) 96 return fDisplayMode.virtual_width; 97 98 return 0; 99 } 100 101 102 uint32 103 AccelerantBuffer::Height() const 104 { 105 if (InitCheck() == B_OK) 106 return fDisplayMode.virtual_height; 107 108 return 0; 109 } 110 111 112 void 113 AccelerantBuffer::SetDisplayMode(const display_mode& mode) 114 { 115 fDisplayMode = mode; 116 fDisplayModeSet = true; 117 } 118 119 120 void 121 AccelerantBuffer::SetFrameBufferConfig(const frame_buffer_config& config) 122 { 123 fFrameBufferConfig = config; 124 fFrameBufferConfigSet = true; 125 } 126 127 128 void 129 AccelerantBuffer::SetOffscreenBuffer(bool offscreenBuffer) 130 { 131 fIsOffscreenBuffer = offscreenBuffer; 132 } 133