Ticket #5314: ATI_AddOverlayPatch.diff

File ATI_AddOverlayPatch.diff, 48.9 KB (added by gerald.zajac, 13 years ago)

File contains patch to overlay support to the ati video driver.

  • headers/private/graphics/ati/DriverInterface.h

     
    11/*
    2     Copyright 2007-2009 Haiku, Inc.  All rights reserved.
     2    Copyright 2007-2011 Haiku, Inc.  All rights reserved.
    33    Distributed under the terms of the MIT license.
    44
    55    Authors:
    6     Gerald Zajac 2007-2009
     6    Gerald Zajac
    77*/
    88
    99#ifndef DRIVERINTERFACE_H
     
    1414#include <GraphicsDefs.h>
    1515#include <Drivers.h>
    1616#include <edid.h>
     17#include <video_overlay.h>
    1718
    1819
    1920// This file contains info that is shared between the kernel driver and the
     
    163164};
    164165
    165166
     167struct OverlayBuffer : overlay_buffer {
     168    OverlayBuffer*  nextBuffer; // pointer to next buffer in chain, NULL = none
     169    uint32          size;       // size of overlay buffer
     170};
     171
     172
    166173struct SharedInfo {
    167174    // Device ID info.
    168175    uint16  vendorID;           // PCI vendor ID, from pci_info
     
    180187    area_id regsArea;           // area_id for the memory mapped registers. It will
    181188                                // be cloned into accelerant's address space.
    182189    area_id videoMemArea;       // video memory area_id.  The addresses are shared with all teams.
    183     void*   videoMemAddr;       // video memory addr as viewed from virtual memory
    184     void*   videoMemPCI;        // video memory addr as viewed from the PCI bus (for DMA)
     190    addr_t  videoMemAddr;       // video memory addr as viewed from virtual memory
     191    phys_addr_t videoMemPCI;    // video memory addr as viewed from the PCI bus (for DMA)
    185192    uint32  videoMemSize;       // video memory size in bytes.
    186193
    187194    uint32  cursorOffset;       // offset of cursor in video memory
     
    209216    bool        bHaveEDID;      // true = EDID info from device is in edidInfo
    210217
    211218    Benaphore   engineLock;     // for serializing access to the acceleration engine
     219    Benaphore   overlayLock;    // for overlay operations
    212220
     221    int32       overlayAllocated;   // non-zero if overlay is allocated
     222    uint32      overlayToken;
     223    OverlayBuffer* overlayBuffer;   // pointer to linked list of buffers; NULL = none
     224
    213225    MonitorType displayType;
    214226
    215227    uint16      panelX;         // laptop LCD width
     
    227239    R128_RAMSpec    r128MemSpec;    // Rage128 memory timing spec's
    228240    R128_PLLParams  r128PLLParams;  // Rage128 PLL parameters from video BIOS ROM
    229241
    230     uint32          r128_dpGuiMasterCntl;   // flags for accelerated drawing
     242    uint32      r128_dpGuiMasterCntl;   // flags for accelerated drawing
    231243};
    232244
    233245
  • src/add-ons/kernel/drivers/graphics/ati/driver.cpp

     
    11/*
    2     Copyright 2007-2009 Haiku, Inc.  All rights reserved.
     2    Copyright 2007-2011 Haiku, Inc.  All rights reserved.
    33    Distributed under the terms of the MIT license.
    44
    55    Authors:
    6     Gerald Zajac 2007-2009
     6    Gerald Zajac
    77*/
    88
    99#include <KernelExport.h>
     
    2020
    2121#undef TRACE
    2222
    23 //#define ENABLE_DEBUG_TRACE
    2423#ifdef ENABLE_DEBUG_TRACE
    2524#   define TRACE(x...) dprintf("ati: " x)
    2625#else
     
    4140#define M64_BIOS_SIZE       0x10000     // 64KB
    4241#define R128_BIOS_SIZE      0x10000     // 64KB
    4342
    44 int32 api_version = B_CUR_DRIVER_API_VERSION;   // revision of driver API we support
     43int32 api_version = B_CUR_DRIVER_API_VERSION;   // revision of driver API used
    4544
    4645#define VENDOR_ID 0x1002    // ATI vendor ID
    4746
     
    5453struct ChipInfo {
    5554    uint16      chipID;         // PCI device id of the chip
    5655    ChipType    chipType;       // assigned chip type identifier
    57     const char* chipName;       // user recognizable name for chip (must be < 32 chars)
     56    const char* chipName;       // user recognizable name for chip
     57                                //   (must be < 32 chars)
    5858};
    5959
    6060
     
    199199static inline uint32
    200200GetPCI(pci_info& info, uint8 offset, uint8 size)
    201201{
    202     return gPCI->read_pci_config(info.bus, info.device, info.function, offset, size);
     202    return gPCI->read_pci_config(info.bus, info.device, info.function, offset,
     203        size);
    203204}
    204205
    205206
    206207static inline void
    207208SetPCI(pci_info& info, uint8 offset, uint8 size, uint32 value)
    208209{
    209     gPCI->write_pci_config(info.bus, info.device, info.function, offset, size, value);
     210    gPCI->write_pci_config(info.bus, info.device, info.function, offset, size,
     211        value);
    210212}
    211213
    212214
     
    251253
    252254    status_t status = vm86_prepare(&vmState, 0x2000);
    253255    if (status != B_OK) {
    254         TRACE("GetEdidFromBIOS(); vm86_prepare() failed, status: 0x%lx\n", status);
     256        TRACE("GetEdidFromBIOS(); vm86_prepare() failed, status: 0x%lx\n",
     257            status);
    255258        return status;
    256259    }
    257260
     
    337340
    338341    status_t status = vm86_prepare(&vmState, 0x2000);
    339342    if (status != B_OK) {
    340         TRACE("SetVesaDisplayMode(); vm86_prepare() failed, status: 0x%lx\n", status);
     343        TRACE("SetVesaDisplayMode(); vm86_prepare() failed, status: 0x%lx\n",
     344            status);
    341345        return status;
    342346    }
    343347
     
    505509    pll.max_pll_freq = BIOS32(pllInfoBlock + 0x16);
    506510    pll.xclk = BIOS16(pllInfoBlock + 0x08);
    507511
    508     TRACE("PLL parameters: rf=%d rd=%d min=%ld max=%ld; xclk=%d\n", pll.reference_freq,
    509         pll.reference_div, pll.min_pll_freq, pll.max_pll_freq, pll.xclk);
     512    TRACE("PLL parameters: rf=%d rd=%d min=%ld max=%ld; xclk=%d\n",
     513        pll.reference_freq, pll.reference_div, pll.min_pll_freq,
     514        pll.max_pll_freq, pll.xclk);
    510515
    511516    // If Mobility chip, get the LCD panel width & height and a few other
    512517    // related parameters.
     
    537542                        si.panelY = BIOS16(fpStart + 27);
    538543                        si.panelPowerDelay = BIOS8(fpStart + 56);
    539544                        TRACE("LCD Panel size: %dx%d  Panel type: 0x%x   power delay: %d\n",
    540                             si.panelX, si.panelY, BIOS16(fpStart + 29), si.panelPowerDelay);
     545                            si.panelX, si.panelY, BIOS16(fpStart + 29),
     546                            si.panelPowerDelay);
    541547                        break;
    542548                    }
    543549                }
     
    566572
    567573    // Map the video memory.
    568574
    569     uint32 videoRamAddr = pciInfo.u.h0.base_registers[0];
     575    phys_addr_t videoRamAddr = pciInfo.u.h0.base_registers[0];
    570576    uint32 videoRamSize = pciInfo.u.h0.base_register_sizes[0];
    571     si.videoMemPCI = (void *)videoRamAddr;
     577    si.videoMemPCI = videoRamAddr;
    572578    char frameBufferAreaName[] = "ATI frame buffer";
    573579
    574580    si.videoMemArea = map_physical_memory(
     
    577583        videoRamSize,
    578584        B_ANY_KERNEL_BLOCK_ADDRESS | B_MTR_WC,
    579585        B_READ_AREA + B_WRITE_AREA,
    580         &(si.videoMemAddr));
     586        (void**)&(si.videoMemAddr));
    581587
    582588    if (si.videoMemArea < 0) {
    583589        // Try to map this time without write combining.
     
    587593            videoRamSize,
    588594            B_ANY_KERNEL_BLOCK_ADDRESS,
    589595            B_READ_AREA + B_WRITE_AREA,
    590             &(si.videoMemAddr));
     596            (void**)&(si.videoMemAddr));
    591597    }
    592598
    593599    if (si.videoMemArea < 0)
     
    595601
    596602    // Map the MMIO register area.
    597603
    598     uint32 regsBase = pciInfo.u.h0.base_registers[2];
     604    phys_addr_t regsBase = pciInfo.u.h0.base_registers[2];
    599605    uint32 regAreaSize = pciInfo.u.h0.base_register_sizes[2];
    600606
    601607    // If the register area address or size is not in the PCI info, it should
     
    619625
    620626        regsBase = videoRamAddr + regsOffset;
    621627        regAreaSize = 0x1000;
    622         TRACE("Register address is at end of frame buffer memory at 0x%lx\n", regsBase);
     628        TRACE("Register address is at end of frame buffer memory at 0x%lx\n",
     629            uint32(regsBase));
    623630    }
    624631
    625632    si.regsArea = map_physical_memory("ATI mmio registers",
     
    627634        regAreaSize,
    628635        B_ANY_KERNEL_ADDRESS,
    629636        0,      // neither read nor write, to hide it from user space apps
    630         (void**)(&(di.regs)));
     637        (void**)&di.regs);
    631638
    632639    // If there was an error, delete other areas.
    633640    if (si.regsArea < 0) {
     
    650657        delete_area(si.videoMemArea);
    651658
    652659    si.regsArea = si.videoMemArea = -1;
    653     si.videoMemAddr = NULL;
     660    si.videoMemAddr = (addr_t)NULL;
    654661    di.regs = NULL;
    655662}
    656663
     
    768775        si.vesaModeTableOffset = sharedSize;
    769776        si.vesaModeCount = vesaModeTableSize / sizeof(VesaMode);
    770777
    771         memcpy((uint8*)&si + si.vesaModeTableOffset, vesaModes, vesaModeTableSize);
     778        memcpy((uint8*)&si + si.vesaModeTableOffset, vesaModes,
     779            vesaModeTableSize);
    772780    }
    773781
    774782    pci_info& pciInfo = di.pciInfo;
     
    892900    pci_info pciInfo;
    893901    const ChipInfo* pDevice = GetNextSupportedDevice(pciIndex, pciInfo);
    894902
    895     TRACE("init_hardware() - %s\n", pDevice == NULL ? "no supported devices" : "device supported");
     903    TRACE("init_hardware() - %s\n",
     904        pDevice == NULL ? "no supported devices" : "device supported");
    896905
    897906    put_module(B_PCI_MODULE_NAME);      // put away the module manager
    898907
     
    900909}
    901910
    902911
    903 status_t  init_driver(void)
     912status_t
     913init_driver(void)
    904914{
    905915    // Get handle for the pci bus.
    906916
     
    10111021        *cookie = &di;      // send cookie to opener
    10121022    }
    10131023
    1014     TRACE("device_open() returning 0x%lx,  open count: %ld\n", status, di.openCount);
     1024    TRACE("device_open() returning 0x%lx,  open count: %ld\n", status,
     1025        di.openCount);
    10151026    return status;
    10161027}
    10171028
     
    10191030static status_t
    10201031device_read(void* dev, off_t pos, void* buf, size_t* len)
    10211032{
    1022     // Following 3 lines of code are here to eliminate "unused parameter" warnings.
     1033    // Following 3 lines of code are here to eliminate "unused parameter"
     1034    // warnings.
    10231035    (void)dev;
    10241036    (void)pos;
    10251037    (void)buf;
     
    10321044static status_t
    10331045device_write(void* dev, off_t pos, const void* buf, size_t* len)
    10341046{
    1035     // Following 3 lines of code are here to eliminate "unused parameter" warnings.
     1047    // Following 3 lines of code are here to eliminate "unused parameter"
     1048    // warnings.
    10361049    (void)dev;
    10371050    (void)pos;
    10381051    (void)buf;
     
    10681081        DisableVBI();       // disable & clear any pending interrupts
    10691082
    10701083        if (si.bInterruptAssigned) {
    1071             remove_io_interrupt_handler(pciInfo.u.h0.interrupt_line, InterruptHandler, &di);
     1084            remove_io_interrupt_handler(pciInfo.u.h0.interrupt_line,
     1085                InterruptHandler, &di);
    10721086        }
    10731087
    1074         // Delete the semaphores, ignoring any errors because the owning team may have died.
     1088        // Delete the semaphores, ignoring any errors because the owning team
     1089        // may have died.
    10751090        if (si.vertBlankSem >= 0)
    10761091            delete_sem(si.vertBlankSem);
    10771092        si.vertBlankSem = -1;
     
    10981113{
    10991114    DeviceInfo& di = *((DeviceInfo*)dev);
    11001115
    1101 //  TRACE("device_ioctl(); ioctl: %lu, buffer: 0x%08lx, bufLen: %lu\n", msg, (uint32)buffer, bufferLength);
     1116//  TRACE("device_ioctl(); ioctl: %lu, buffer: 0x%08lx, bufLen: %lu\n", msg,
     1117//      (uint32)buffer, bufferLength);
    11021118
    11031119    switch (msg) {
    11041120        case B_GET_ACCELERANT_SIGNATURE:
  • src/add-ons/accelerants/ati/accelerant.h

     
    11/*
    2     Copyright 2007-2009 Haiku, Inc.  All rights reserved.
     2    Copyright 2007-2011 Haiku, Inc.  All rights reserved.
    33    Distributed under the terms of the MIT license.
    44
    55    Authors:
    6     Gerald Zajac 2007-2009
     6    Gerald Zajac
    77*/
    88
    99#ifndef _ACCELERANT_H
     
    5252    status_t (*SetDPMSMode)(uint32 dpms_flags);
    5353
    5454    // Pointers to cursor functions.
    55     bool    (*LoadCursorImage)(int width, int height, uint8* and_mask, uint8* xor_mask);
     55    bool    (*LoadCursorImage)(int width, int height, uint8* and_mask,
     56                uint8* xor_mask);
    5657    void    (*SetCursorPosition)(int x, int y);
    5758    void    (*ShowCursor)(bool bShow);
    5859
    5960    // Pointers to 2D acceleration functions.
    60     void    (*FillRectangle)(engine_token*, uint32 color, fill_rect_params*, uint32 count);
    61     void    (*FillSpan)(engine_token*, uint32 color, uint16* list, uint32 count);
     61    void    (*FillRectangle)(engine_token*, uint32 color, fill_rect_params*,
     62                uint32 count);
     63    void    (*FillSpan)(engine_token*, uint32 color, uint16* list,
     64                uint32 count);
    6265    void    (*InvertRectangle)(engine_token*, fill_rect_params*, uint32 count);
    6366    void    (*ScreenToScreenBlit)(engine_token*, blit_params*, uint32 count);
    6467
    6568    // Pointers to other functions.
    6669    void     (*AdjustFrame)(const DisplayModeEx& mode);
    6770    status_t (*ChipInit)(void);
    68     bool     (*GetColorSpaceParams)(int colorSpace, uint8& bpp, uint32& maxPixelClk);
     71    bool     (*GetColorSpaceParams)(int colorSpace, uint8& bpp,
     72                uint32& maxPixelClk);
    6973    status_t (*SetDisplayMode)(const DisplayModeEx& mode);
    70     void     (*SetIndexedColors)(uint count, uint8 first, uint8* color_data, uint32 flags);
     74    void     (*SetIndexedColors)(uint count, uint8 first, uint8* color_data,
     75                uint32 flags);
    7176};
    7277
    7378extern AccelerantInfo gInfo;
     
    95100// Mode Configuration
    96101uint32   AccelerantModeCount(void);
    97102status_t GetModeList(display_mode* dm);
    98 status_t ProposeDisplayMode(display_mode* target, const display_mode* low, const display_mode* high);
     103status_t ProposeDisplayMode(display_mode* target, const display_mode* low,
     104                    const display_mode* high);
    99105status_t SetDisplayMode(display_mode* mode_to_set);
    100106status_t GetDisplayMode(display_mode* current_mode);
    101107status_t GetFrameBufferConfig(frame_buffer_config* a_frame_buffer);
    102108status_t GetPixelClockLimits(display_mode* dm, uint32* low, uint32* high);
    103109status_t MoveDisplay(uint16 h_display_start, uint16 v_display_start);
    104110status_t GetTimingConstraints(display_timing_constraints* dtc);
    105 void     Mach64_SetIndexedColors(uint count, uint8 first, uint8* color_data, uint32 flags);
    106 void     Rage128_SetIndexedColors(uint count, uint8 first, uint8* color_data, uint32 flags);
     111void     Mach64_SetIndexedColors(uint count, uint8 first, uint8* color_data,
     112                    uint32 flags);
     113void     Rage128_SetIndexedColors(uint count, uint8 first, uint8* color_data,
     114                    uint32 flags);
    107115status_t GetPreferredDisplayMode(display_mode* preferredMode);
    108116status_t GetEdidInfo(void* info, size_t size, uint32* _version);
    109117
     
    118126
    119127// Cursor
    120128status_t SetCursorShape(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y,
    121                         uint8* andMask, uint8* xorMask);
     129                    uint8* andMask, uint8* xorMask);
    122130void     MoveCursor(uint16 x, uint16 y);
    123131
    124132// Engine Management
    125133uint32   AccelerantEngineCount(void);
    126 status_t AcquireEngine(uint32 capabilities, uint32 max_wait, sync_token* st, engine_token** et);
     134status_t AcquireEngine(uint32 capabilities, uint32 max_wait, sync_token* st,
     135                    engine_token** et);
    127136status_t ReleaseEngine(engine_token* et, sync_token* st);
    128137void     WaitEngineIdle(void);
    129138status_t GetSyncToken(engine_token* et, sync_token* st);
    130139status_t SyncToToken(sync_token* st);
    131140
    132141// 2D acceleration
    133 void     Mach64_FillRectangle(engine_token* et, uint32 color, fill_rect_params* list, uint32 count);
    134 void     Mach64_FillSpan(engine_token* et, uint32 color, uint16* list, uint32 count);
    135 void     Mach64_InvertRectangle(engine_token* et, fill_rect_params* list, uint32 count);
    136 void     Mach64_ScreenToScreenBlit(engine_token* et, blit_params* list, uint32 count);
     142void     Mach64_FillRectangle(engine_token* et, uint32 color,
     143                    fill_rect_params* list, uint32 count);
     144void     Mach64_FillSpan(engine_token* et, uint32 color, uint16* list,
     145                    uint32 count);
     146void     Mach64_InvertRectangle(engine_token* et, fill_rect_params* list,
     147                    uint32 count);
     148void     Mach64_ScreenToScreenBlit(engine_token* et, blit_params* list,
     149                    uint32 count);
    137150
    138 void     Rage128_FillRectangle(engine_token* et, uint32 color, fill_rect_params* list, uint32 count);
    139 void     Rage128_FillSpan(engine_token* et, uint32 color, uint16* list, uint32 count);
    140 void     Rage128_InvertRectangle(engine_token* et, fill_rect_params* list, uint32 count);
    141 void     Rage128_ScreenToScreenBlit(engine_token* et, blit_params* list, uint32 count);
     151void     Rage128_FillRectangle(engine_token* et, uint32 color,
     152                    fill_rect_params* list, uint32 count);
     153void     Rage128_FillSpan(engine_token* et, uint32 color, uint16* list,
     154                    uint32 count);
     155void     Rage128_InvertRectangle(engine_token* et, fill_rect_params* list,
     156                    uint32 count);
     157void     Rage128_ScreenToScreenBlit(engine_token* et, blit_params* list,
     158                    uint32 count);
    142159
     160// Video_overlay
     161uint32      OverlayCount(const display_mode* dm);
     162const uint32* OverlaySupportedSpaces(const display_mode* dm);
     163uint32      OverlaySupportedFeatures(uint32 a_color_space);
     164const overlay_buffer* AllocateOverlayBuffer(color_space cs, uint16 width,
     165                    uint16 height);
     166status_t    ReleaseOverlayBuffer(const overlay_buffer* ob);
     167status_t    GetOverlayConstraints(const display_mode* dm,
     168                    const overlay_buffer* ob, overlay_constraints* oc);
     169overlay_token AllocateOverlay(void);
     170status_t    ReleaseOverlay(overlay_token ot);
     171status_t    ConfigureOverlay(overlay_token ot, const overlay_buffer* ob,
     172                    const overlay_window* ow, const overlay_view* ov);
     173
    143174#if defined(__cplusplus)
    144175}
    145176#endif
     
    156187
    157188// Mach64 functions.
    158189
     190bool     Mach64_DisplayOverlay(const overlay_window* window,
     191                const overlay_buffer* buffer);
     192void     Mach64_StopOverlay(void);
     193
    159194void     Mach64_EngineReset(void);
    160195void     Mach64_EngineInit(const DisplayModeEx& mode);
    161196
    162 bool     Mach64_LoadCursorImage(int width, int height, uint8* and_mask, uint8* xor_mask);
     197bool     Mach64_LoadCursorImage(int width, int height, uint8* and_mask,
     198                uint8* xor_mask);
    163199void     Mach64_SetCursorPosition(int x, int y);
    164200void     Mach64_ShowCursor(bool bShow);
    165201
     
    167203status_t Mach64_SetDisplayMode(const DisplayModeEx& mode);
    168204void     Mach64_SetFunctionPointers(void);
    169205
    170 int      Mach64_Divide(int numerator, int denom, int shift, const int roundingKind);
    171 void     Mach64_ReduceRatio(int *numerator, int *denominator);
     206int      Mach64_Divide(int numerator, int denom, int shift,
     207                const int roundingKind);
     208void     Mach64_ReduceRatio(int* numerator, int* denominator);
    172209
    173210
    174211// Rage128 functions.
    175212
     213bool     Rage128_DisplayOverlay(const overlay_window* window,
     214                const overlay_buffer* buffer);
     215void     Rage128_StopOverlay(void);
     216
    176217void     Rage128_EngineFlush(void);
    177218void     Rage128_EngineReset(void);
    178219void     Rage128_EngineInit(const DisplayModeEx& mode);
    179220
    180221bool     Rage128_GetEdidInfo(void);
    181222
    182 bool     Rage128_LoadCursorImage(int width, int height, uint8* and_mask, uint8* xor_mask);
     223bool     Rage128_LoadCursorImage(int width, int height, uint8* and_mask,
     224                uint8* xor_mask);
    183225void     Rage128_SetCursorPosition(int x, int y);
    184226void     Rage128_ShowCursor(bool bShow);
    185227
  • src/add-ons/accelerants/ati/rage128_overlay.cpp

     
     1/*
     2    Haiku ATI video driver adapted from the X.org ATI driver which has the
     3    following copyright:
     4
     5    Copyright 1999, 2000 ATI Technologies Inc., Markham, Ontario,
     6                         Precision Insight, Inc., Cedar Park, Texas, and
     7                         VA Linux Systems Inc., Fremont, California.
     8
     9    Copyright 2011 Haiku, Inc.  All rights reserved.
     10    Distributed under the terms of the MIT license.
     11
     12    Authors:
     13    Gerald Zajac
     14 */
     15
     16#include "accelerant.h"
     17#include "rage128.h"
     18
     19
     20static uint32 sCurrentKeyColor = 0;
     21static uint32 sCurrentKeyMask = 0;
     22
     23
     24
     25bool
     26Rage128_DisplayOverlay(const overlay_window* window,
     27                        const overlay_buffer* buffer)
     28{
     29    // Return true if setup is successful.
     30
     31    SharedInfo& si = *gInfo.sharedInfo;
     32
     33    if (window == NULL || buffer == NULL)
     34        return false;
     35
     36    if (buffer->space != B_YCbCr422)
     37        return false;   // color space not supported
     38
     39    uint32 keyColor = 0;
     40    uint32 keyMask = 0;
     41
     42    switch (si.displayMode.bitsPerPixel) {
     43        case 15:
     44            keyMask = 0x7fff;
     45            keyColor = (window->blue.value & window->blue.mask) << 0
     46                | (window->green.value & window->green.mask) << 5
     47                | (window->red.value & window->red.mask) << 10;
     48                // 15 bit color has no alpha bits
     49            break;
     50        case 16:
     51            keyMask = 0xffff;
     52            keyColor = (window->blue.value & window->blue.mask) << 0
     53                | (window->green.value & window->green.mask) << 5
     54                | (window->red.value & window->red.mask) << 11;
     55                // 16 bit color has no alpha bits
     56            break;
     57        default:
     58            keyMask = 0xffffffff;
     59            keyColor = (window->blue.value & window->blue.mask) << 0
     60                | (window->green.value & window->green.mask) << 8
     61                | (window->red.value & window->red.mask) << 16
     62                | (window->alpha.value & window->alpha.mask) << 24;
     63            break;
     64    }
     65
     66    // If the key color or key mask has changed since the overlay was
     67    // previously initialized, initialize it again.  This is to avoid
     68    // initializing the overlay video everytime the overlay buffer is
     69    // switched which causes artifacts in the overlay display.
     70
     71    if (keyColor != sCurrentKeyColor || keyMask != sCurrentKeyMask)
     72    {
     73        TRACE("Rage128_DisplayOverlay() initializing overlay video\n");
     74       
     75        // Initialize the overlay video by first resetting the video.
     76
     77        OUTREG(R128_OV0_SCALE_CNTL, 0);
     78        OUTREG(R128_OV0_EXCLUSIVE_HORZ, 0);
     79        OUTREG(R128_OV0_AUTO_FLIP_CNTL, 0);
     80        OUTREG(R128_OV0_FILTER_CNTL, 0x0000000f);
     81   
     82        const uint32 brightness = 0;
     83        const uint32 saturation = 16;
     84        OUTREG(R128_OV0_COLOUR_CNTL, brightness | saturation << 8
     85            | saturation << 16);
     86   
     87        OUTREG(R128_OV0_GRAPHICS_KEY_MSK, keyMask);
     88        OUTREG(R128_OV0_GRAPHICS_KEY_CLR, keyColor);
     89        OUTREG(R128_OV0_KEY_CNTL, R128_GRAPHIC_KEY_FN_NE);
     90        OUTREG(R128_OV0_TEST, 0);
     91
     92        sCurrentKeyColor = keyColor;
     93        sCurrentKeyMask = keyMask;
     94    }
     95
     96    uint32 ecpDiv;
     97    if (si.displayMode.timing.pixel_clock < 125000)
     98        ecpDiv = 0;
     99    else if (si.displayMode.timing.pixel_clock < 250000)
     100        ecpDiv = 1;
     101    else
     102        ecpDiv = 2;
     103
     104    SetPLLReg(R128_VCLK_ECP_CNTL, ecpDiv << 8, R128_ECP_DIV_MASK);
     105
     106    int32 vertInc = (buffer->height << 20) / window->height;
     107    int32 horzInc = (buffer->width << (12 + ecpDiv)) / window->width;
     108    int32 stepBy = 1;
     109
     110    while (horzInc >= (2 << 12)) {
     111        stepBy++;
     112        horzInc >>= 1;
     113    }
     114
     115    int32 x1 = window->h_start;
     116    int32 y1 = window->v_start;
     117
     118    int32 x2 = window->h_start + window->width;
     119    int32 y2 = window->v_start + window->height;
     120
     121    int32 left = x1;
     122    int32 tmp = (left & 0x0003ffff) + 0x00028000 + (horzInc << 3);
     123    int32 p1_h_accum_init = ((tmp << 4) & 0x000f8000) |
     124                      ((tmp << 12) & 0xf0000000);
     125
     126    tmp = ((left >> 1) & 0x0001ffff) + 0x00028000 + (horzInc << 2);
     127    int32 p23_h_accum_init = ((tmp << 4) & 0x000f8000) |
     128                        ((tmp << 12) & 0x70000000);
     129
     130    tmp = (y1 & 0x0000ffff) + 0x00018000;
     131    int32 p1_v_accum_init = ((tmp << 4) & 0x03ff8000) | 0x00000001;
     132
     133    // Compute offset of overlay buffer in the video memory.
     134    uint32 offset = uint32(buffer->buffer) - si.videoMemAddr;
     135
     136    OUTREG(R128_OV0_REG_LOAD_CNTL, 1);
     137    while (!(INREG(R128_OV0_REG_LOAD_CNTL) & (1 << 3)))
     138        ;
     139
     140    OUTREG(R128_OV0_H_INC, horzInc | ((horzInc >> 1) << 16));
     141    OUTREG(R128_OV0_STEP_BY, stepBy | (stepBy << 8));
     142    OUTREG(R128_OV0_Y_X_START, x1 | y1 << 16);
     143    OUTREG(R128_OV0_Y_X_END, x2 | y2 << 16);
     144    OUTREG(R128_OV0_V_INC, vertInc);
     145    OUTREG(R128_OV0_P1_BLANK_LINES_AT_TOP,
     146            0x00000fff | ((buffer->height - 1) << 16));
     147    OUTREG(R128_OV0_VID_BUF_PITCH0_VALUE, buffer->bytes_per_row);
     148
     149    int32 width = window->width;
     150    left = 0;
     151    OUTREG(R128_OV0_P1_X_START_END, (width - 1) | (left << 16));
     152    width >>= 1;
     153    OUTREG(R128_OV0_P2_X_START_END, (width - 1) | (left << 16));
     154    OUTREG(R128_OV0_P3_X_START_END, (width - 1) | (left << 16));
     155    OUTREG(R128_OV0_VID_BUF0_BASE_ADRS, offset);
     156    OUTREG(R128_OV0_P1_V_ACCUM_INIT, p1_v_accum_init);
     157    OUTREG(R128_OV0_P23_V_ACCUM_INIT, 0);
     158    OUTREG(R128_OV0_P1_H_ACCUM_INIT, p1_h_accum_init);
     159    OUTREG(R128_OV0_P23_H_ACCUM_INIT, p23_h_accum_init);
     160
     161    OUTREG(R128_OV0_SCALE_CNTL, 0x41FF8B03);
     162    OUTREG(R128_OV0_REG_LOAD_CNTL, 0);
     163
     164    return true;
     165}
     166
     167
     168void
     169Rage128_StopOverlay(void)
     170{
     171    OUTREG(R128_OV0_SCALE_CNTL, 0);     // reset the video
     172
     173    // Reset the key color and mask so that when the overlay is started again
     174    // it will be initialized.
     175   
     176    sCurrentKeyColor = 0;
     177    sCurrentKeyMask = 0;
     178}
  • src/add-ons/accelerants/ati/rage128.h

     
    11/*
    2     Haiku ATI video driver adapted from the X.org ATI driver.
     2    Haiku ATI video driver adapted from the X.org ATI driver which has the
     3    following copyright:
    34
    45    Copyright 1999, 2000 ATI Technologies Inc., Markham, Ontario,
    56                          Precision Insight, Inc., Cedar Park, Texas, and
    67                          VA Linux Systems Inc., Fremont, California.
    78
    8     Copyright 2009 Haiku, Inc.  All rights reserved.
     9    Copyright 2009, 2011 Haiku, Inc.  All rights reserved.
    910    Distributed under the terms of the MIT license.
    1011
    1112    Authors:
    12     Gerald Zajac 2009
     13    Gerald Zajac
    1314*/
    1415
    1516
     
    1718#define __RAGE128_H__
    1819
    1920
    20 #define CURSOR_BYTES    1024        // bytes used for cursor image in video memory
     21#define CURSOR_BYTES    1024    // bytes used for cursor image in video memory
    2122
    2223#define R128_TIMEOUT    2000000 // Fall out of wait loops after this count
    2324
     
    203204#define R128_OVR_CLR                      0x0230
    204205#define R128_OVR_WID_LEFT_RIGHT           0x0234
    205206#define R128_OVR_WID_TOP_BOTTOM           0x0238
    206 #define R128_OV0_SCALE_CNTL               0x0420
    207207
    208208#define R128_PALETTE_DATA                 0x00b4
    209209#define R128_PALETTE_INDEX                0x00b0
     
    231231
    232232#define R128_TMDS_CRC                     0x02a0
    233233
    234 #define R128_VCLK_ECP_CNTL                0x0008    // PLL
    235 #       define R128_VCLK_SRC_SEL_MASK     0x03
    236 #       define R128_VCLK_SRC_SEL_CPUCLK   0x00
    237 #       define R128_VCLK_SRC_SEL_PPLLCLK  0x03
     234#define R128_VCLK_ECP_CNTL               0x0008 // PLL
     235#       define R128_VCLK_SRC_SEL_MASK    0x03
     236#       define R128_VCLK_SRC_SEL_CPUCLK  0x00
     237#       define R128_VCLK_SRC_SEL_PPLLCLK 0x03
     238#       define R128_ECP_DIV_MASK         (3 << 8)
    238239#define R128_VIPH_CONTROL                 0x01D0    // ?
    239240
    240241
     242// Definitions used for overlays.
     243//===============================
    241244
     245#define R128_OV0_Y_X_START              0x0400
     246#define R128_OV0_Y_X_END                0x0404
     247#define R128_OV0_EXCLUSIVE_HORZ         0x0408
     248#define R128_OV0_REG_LOAD_CNTL          0x0410
     249#define R128_OV0_SCALE_CNTL             0x0420
     250#define R128_OV0_V_INC                  0x0424
     251#define R128_OV0_P1_V_ACCUM_INIT        0x0428
     252#define R128_OV0_P23_V_ACCUM_INIT       0x042C
     253#define R128_OV0_P1_BLANK_LINES_AT_TOP  0x0430
     254#define R128_OV0_VID_BUF0_BASE_ADRS     0x0440
     255#define R128_OV0_VID_BUF_PITCH0_VALUE   0x0460
     256#define R128_OV0_AUTO_FLIP_CNTL         0x0470
     257#define R128_OV0_H_INC                  0x0480
     258#define R128_OV0_STEP_BY                0x0484
     259#define R128_OV0_P1_H_ACCUM_INIT        0x0488
     260#define R128_OV0_P23_H_ACCUM_INIT       0x048C
     261#define R128_OV0_P1_X_START_END         0x0494
     262#define R128_OV0_P2_X_START_END         0x0498
     263#define R128_OV0_P3_X_START_END         0x049C
     264#define R128_OV0_FILTER_CNTL            0x04A0
     265#define R128_OV0_COLOUR_CNTL            0x04E0
     266#define R128_OV0_GRAPHICS_KEY_CLR       0x04EC
     267#define R128_OV0_GRAPHICS_KEY_MSK       0x04F0
     268#define R128_OV0_KEY_CNTL               0x04F4
     269#       define R128_GRAPHIC_KEY_FN_EQ   0x00000040L
     270#       define R128_GRAPHIC_KEY_FN_NE   0x00000050L
     271#define R128_OV0_TEST                   0x04F8
     272
     273
     274
    242275// Functions to get/set PLL registers.
    243276//=======================================
    244277
  • src/add-ons/accelerants/ati/overlay.cpp

     
     1/*
     2    Copyright 2011 Haiku, Inc.  All rights reserved.
     3    Distributed under the terms of the MIT license.
     4
     5    Authors:
     6        Gerald Zajac
     7 */
     8
     9#include "accelerant.h"
     10#include "rage128.h"
     11
     12#include <stdlib.h>
     13
     14
     15
     16uint32
     17OverlayCount(const display_mode* mode)
     18{
     19    (void)mode;     // avoid compiler warning for unused arg
     20
     21    return 1;
     22}
     23
     24
     25const uint32*
     26OverlaySupportedSpaces(const display_mode* mode)
     27{
     28    (void)mode;     // avoid compiler warning for unused arg
     29
     30    static const uint32 kSupportedSpaces[] = {B_YCbCr422, 0};
     31
     32    return kSupportedSpaces;
     33}
     34
     35
     36uint32
     37OverlaySupportedFeatures(uint32 colorSpace)
     38{
     39    (void)colorSpace;       // avoid compiler warning for unused arg
     40
     41    return B_OVERLAY_COLOR_KEY
     42        | B_OVERLAY_HORIZONTAL_FILTERING
     43        | B_OVERLAY_VERTICAL_FILTERING;
     44}
     45
     46
     47const overlay_buffer*
     48AllocateOverlayBuffer(color_space colorSpace, uint16 width, uint16 height)
     49{
     50    SharedInfo& si = *gInfo.sharedInfo;
     51
     52    TRACE("AllocateOverlayBuffer() width %u, height %u, colorSpace 0x%lx\n",
     53        width, height, colorSpace);
     54
     55    // If Mach 64 chip, check hardware limits.
     56
     57    if (MACH64_FAMILY(si.chipType)) {
     58        if (height > 2048 || width > 768
     59                || (width > 384 && si.chipType < MACH64_264VTB)
     60                || (width > 720 && (si.chipType < MACH64_264GTPRO
     61                || si.chipType > MACH64_264LTPRO)))
     62            return NULL;
     63    }
     64
     65    si.overlayLock.Acquire();
     66
     67    // Note:  When allocating buffers, buffer allocation starts at the end of
     68    // video memory, and works backward to the end of the video frame buffer.
     69    // The allocated buffers are recorded in a linked list of OverlayBuffer
     70    // objects which are ordered by the buffer address with the first object
     71    // in the list having the highest buffer address.
     72
     73    if (colorSpace != B_YCbCr422) {
     74        si.overlayLock.Release();
     75        TRACE("AllocateOverlayBuffer() unsupported color space 0x%x\n",
     76            colorSpace);
     77        return NULL;
     78    }
     79
     80    uint32 bytesPerPixel = 2;       // B_YCbCr422 uses 2 bytes per pixel
     81
     82    // Calculate required buffer size as a multiple of 1K.
     83    uint32 buffSize = (width * bytesPerPixel * height + 0x3ff) & ~0x3ff;
     84
     85    OverlayBuffer* ovBuff = si.overlayBuffer;
     86    OverlayBuffer* prevOvBuff = NULL;
     87
     88    // If no buffers have been allocated, prevBuffAddr calculated here will be
     89    // the address where the buffer area will start.  Leave a gap of about 4K
     90    // between where the overlay buffers will start and the cursor image;
     91    // thus, if the overlay buffer overflows it will be less apt to affect the
     92    // cursor.
     93
     94    uint32 prevBuffAddr = (si.videoMemAddr + si.cursorOffset - 0xfff) & ~0xfff;
     95
     96    while (ovBuff != NULL) {
     97        // Test if there is sufficient space between the end of the current
     98        // buffer and the start of the previous buffer to allocate the new
     99        // buffer.
     100
     101        uint32 currentBuffEndAddr = (addr_t)ovBuff->buffer + ovBuff->size;
     102        if ((prevBuffAddr - currentBuffEndAddr) >= buffSize)
     103            break;      // sufficient space for the new buffer
     104
     105        prevBuffAddr = (uint32)ovBuff->buffer;
     106        prevOvBuff = ovBuff;
     107        ovBuff = ovBuff->nextBuffer;
     108    }
     109
     110    OverlayBuffer* nextOvBuff = ovBuff;
     111
     112    if (ovBuff == NULL) {
     113        // No space between any current buffers of the required size was found;
     114        // thus space must be allocated between the last buffer and the end of
     115        // the video frame buffer.  Compute where current video frame buffer
     116        // ends so that it can be determined if there is sufficient space for
     117        // the new buffer to be created.
     118
     119        uint32 fbEndAddr = si.videoMemAddr + si.frameBufferOffset
     120            + (si.displayMode.virtual_width
     121            * ((si.displayMode.bitsPerPixel + 7) / 8)   // bytes per pixel
     122            * si.displayMode.virtual_height);
     123
     124        if (buffSize > prevBuffAddr - fbEndAddr) {
     125            si.overlayLock.Release();
     126            TRACE("AllocateOverlayBuffer() insuffcient space for %ld (0x%lx) "
     127                    "byte buffer\n", buffSize, buffSize);
     128            return NULL;    // insufficient space for buffer
     129        }
     130
     131        nextOvBuff = NULL;
     132    }
     133
     134    ovBuff = (OverlayBuffer*)malloc(sizeof(OverlayBuffer));
     135    if (ovBuff == NULL) {
     136        si.overlayLock.Release();
     137        return NULL;        // memory not available for OverlayBuffer struct
     138    }
     139
     140    ovBuff->nextBuffer = nextOvBuff;
     141    ovBuff->size = buffSize;
     142    ovBuff->space = colorSpace;
     143    ovBuff->width = width;
     144    ovBuff->height = height;
     145    ovBuff->bytes_per_row = width * bytesPerPixel;
     146    ovBuff->buffer = (void*)(prevBuffAddr - buffSize);
     147    ovBuff->buffer_dma = (void*)(si.videoMemPCI
     148        + ((addr_t)ovBuff->buffer - si.videoMemAddr));
     149
     150    if (prevOvBuff == NULL)
     151        si.overlayBuffer = ovBuff;
     152    else
     153        prevOvBuff->nextBuffer = ovBuff;
     154
     155    si.overlayLock.Release();
     156    TRACE("AllocateOverlayBuffer() allocated %ld (0x%lx) byte buffer at 0x%lx\n",
     157        buffSize, buffSize, ovBuff->buffer);
     158    return ovBuff;
     159}
     160
     161
     162status_t
     163ReleaseOverlayBuffer(const overlay_buffer* buffer)
     164{
     165    SharedInfo& si = *gInfo.sharedInfo;
     166
     167    if (buffer == NULL)
     168        return B_BAD_VALUE;
     169
     170    // Find the buffer to be released.
     171
     172    OverlayBuffer* ovBuff = si.overlayBuffer;
     173    OverlayBuffer* prevOvBuff = NULL;
     174
     175    while (ovBuff != NULL) {
     176        if (ovBuff->buffer == buffer->buffer) {
     177            // Buffer to be released has been found.  Remove the OverlayBuffer
     178            // object from the chain of overlay buffers.
     179
     180            if (prevOvBuff == NULL)
     181                si.overlayBuffer = ovBuff->nextBuffer;
     182            else
     183                prevOvBuff->nextBuffer = ovBuff->nextBuffer;
     184
     185            free(ovBuff);
     186            return B_OK;
     187        }
     188
     189        prevOvBuff = ovBuff;
     190        ovBuff = ovBuff->nextBuffer;
     191    }
     192
     193    TRACE("ReleaseOverlayBuffer() buffer to release at 0x%lx not found\n",
     194        buffer->buffer);
     195    return B_ERROR;     // buffer to be released not found in chain of buffers
     196}
     197
     198
     199status_t
     200GetOverlayConstraints(const display_mode* mode, const overlay_buffer* buffer,
     201                    overlay_constraints* constraints)
     202{
     203    if ((mode == NULL) || (buffer == NULL) || (constraints == NULL))
     204        return B_ERROR;
     205
     206    // Position (values are in pixels)
     207    constraints->view.h_alignment = 0;
     208    constraints->view.v_alignment = 0;
     209
     210    if (buffer->space == B_YCbCr422)
     211        constraints->view.width_alignment = 7;
     212    else {
     213        TRACE("GetOverlayConstraints() color space 0x%x out of range\n",
     214            buffer->space);
     215        return B_BAD_VALUE;
     216    }
     217
     218    constraints->view.height_alignment = 0;
     219
     220    //Size
     221    constraints->view.width.min = 4;
     222    constraints->view.height.min = 4;
     223    constraints->view.width.max = buffer->width;
     224    constraints->view.height.max = buffer->height;
     225
     226    // Scaler output restrictions
     227    constraints->window.h_alignment = 0;
     228    constraints->window.v_alignment = 0;
     229    constraints->window.width_alignment = 0;
     230    constraints->window.height_alignment = 0;
     231    constraints->window.width.min = 2;
     232    constraints->window.width.max = mode->virtual_width;
     233    constraints->window.height.min = 2;
     234    constraints->window.height.max = mode->virtual_height;
     235
     236    constraints->h_scale.min = 1.0;
     237    constraints->h_scale.max = 8.0;
     238    constraints->v_scale.min = 1.0;
     239    constraints->v_scale.max = 8.0;
     240
     241    return B_OK;
     242}
     243
     244
     245overlay_token
     246AllocateOverlay(void)
     247{
     248    SharedInfo& si = *gInfo.sharedInfo;
     249
     250    // There is only a single overlay channel;  thus, check if it is already
     251    // allocated.
     252
     253    if (atomic_or(&si.overlayAllocated, 1) != 0) {
     254        TRACE("AllocateOverlay() overlay channel already in use\n");
     255        return NULL;
     256    }
     257
     258    return (overlay_token)++si.overlayToken;
     259}
     260
     261
     262status_t
     263ReleaseOverlay(overlay_token overlayToken)
     264{
     265    SharedInfo& si = *gInfo.sharedInfo;
     266
     267    if (overlayToken != (overlay_token)si.overlayToken) {
     268        TRACE("ReleaseOverlay() error - no overlay previously allocated\n");
     269        return B_BAD_VALUE;
     270    }
     271
     272    if (MACH64_FAMILY(si.chipType))
     273        Mach64_StopOverlay();
     274    else
     275        Rage128_StopOverlay();
     276
     277    atomic_and(&si.overlayAllocated, 0);    // mark overlay as unallocated
     278    return B_OK;
     279}
     280
     281
     282status_t
     283ConfigureOverlay(overlay_token overlayToken, const overlay_buffer* buffer,
     284    const overlay_window* window, const overlay_view* view)
     285{
     286    SharedInfo& si = *gInfo.sharedInfo;
     287
     288    if (overlayToken != (overlay_token)si.overlayToken)
     289        return B_BAD_VALUE;
     290
     291    if (buffer == NULL)
     292        return B_BAD_VALUE;
     293
     294    if (window == NULL || view == NULL) {
     295        if (MACH64_FAMILY(si.chipType))
     296            Mach64_StopOverlay();
     297        else
     298            Rage128_StopOverlay();
     299
     300        return B_OK;
     301    }
     302
     303    // Program the overlay hardware.
     304    if (MACH64_FAMILY(si.chipType)) {
     305        if (!Mach64_DisplayOverlay(window, buffer)) {
     306            TRACE("ConfigureOverlay(), call to Mach64_DisplayOverlay() "
     307                "returned error\n");
     308            return B_ERROR;
     309        }
     310    } else {
     311        if (!Rage128_DisplayOverlay(window, buffer)) {
     312            TRACE("ConfigureOverlay(), call to Rage128_DisplayOverlay() "
     313                "returned error\n");
     314            return B_ERROR;
     315        }
     316    }
     317
     318    return B_OK;
     319}
  • src/add-ons/accelerants/ati/mach64_overlay.cpp

     
     1/*
     2    Haiku ATI video driver adapted from the X.org ATI driver which has the
     3    following copyright:
     4
     5    Copyright 2003 through 2004 by Marc Aurele La France, tsi@xfree86.org
     6
     7    Copyright 2011 Haiku, Inc.  All rights reserved.
     8    Distributed under the terms of the MIT license.
     9
     10    Authors:
     11    Gerald Zajac
     12*/
     13
     14#include "accelerant.h"
     15#include "mach64.h"
     16
     17
     18
     19bool
     20Mach64_DisplayOverlay(const overlay_window* window,
     21                        const overlay_buffer* buffer)
     22{
     23    // Return true if setup is successful.
     24
     25    SharedInfo& si = *gInfo.sharedInfo;
     26
     27    if (window == NULL || buffer == NULL)
     28        return false;
     29
     30    uint32 videoFormat;
     31
     32    if (buffer->space == B_YCbCr422)
     33        videoFormat = SCALE_IN_VYUY422;
     34    else
     35        return false;   // color space not supported
     36
     37    int32 x1 = (window->h_start < 0) ? 0 : window->h_start;
     38    int32 y1 = (window->v_start < 0) ? 0 : window->v_start;
     39
     40    int32 x2 = window->h_start + window->width - 1;
     41    int32 y2 = window->v_start + window->height - 1;
     42
     43    if (x2 > si.displayMode.timing.h_display)
     44        x2 = si.displayMode.timing.h_display;
     45
     46    if (y2 > si.displayMode.timing.v_display)
     47        y2 = si.displayMode.timing.v_display;
     48
     49    // If window is moved beyond edge of screen, do not allow width < 4 or
     50    // height < 4;  otherwise there is a possibilty of divide by zero when
     51    // computing the scale factors..
     52    if (x2 < x1 + 4)
     53        x2 = x1 + 4;
     54
     55    if (y2 < y1 + 4)
     56        y2 = y1 + 4;
     57
     58    // Calculate overlay scale factors.
     59    uint32 horzScale = (buffer->width << 12) / (x2 - x1 + 1);
     60    uint32 vertScale = (buffer->height << 12) / (y2 - y1 + 1);
     61   
     62    if (horzScale > 0xffff)     // only 16 bits are used for scale factors
     63        horzScale = 0xffff;
     64    if (vertScale > 0xffff)
     65        vertScale = 0xffff;
     66
     67    gInfo.WaitForFifo(2);
     68    OUTREG(BUS_CNTL, INREG(BUS_CNTL) | BUS_EXT_REG_EN); // enable reg block 1
     69    OUTREG(OVERLAY_SCALE_CNTL, SCALE_EN);   // reset the video
     70
     71    if (si.chipType >= MACH64_264GTPRO) {
     72        const uint32 brightness = 0;
     73        const uint32 saturation = 12;
     74
     75        gInfo.WaitForFifo(6);
     76        OUTREG(SCALER_COLOUR_CNTL, brightness | saturation << 8
     77            | saturation << 16);
     78        OUTREG(SCALER_H_COEFF0, 0x0002000);
     79        OUTREG(SCALER_H_COEFF1, 0xd06200d);
     80        OUTREG(SCALER_H_COEFF2, 0xd0a1c0d);
     81        OUTREG(SCALER_H_COEFF3, 0xc0e1a0c);
     82        OUTREG(SCALER_H_COEFF4, 0xc14140c);
     83    }
     84
     85    uint32 keyColor = 0;
     86    uint32 keyMask = 0;
     87
     88    switch (si.displayMode.bitsPerPixel) {
     89        case 15:
     90            keyMask = 0x7fff;
     91            keyColor = (window->blue.value & window->blue.mask) << 0
     92                | (window->green.value & window->green.mask) << 5
     93                | (window->red.value & window->red.mask) << 10;
     94                // 15 bit color has no alpha bits
     95            break;
     96        case 16:
     97            keyMask = 0xffff;
     98            keyColor = (window->blue.value & window->blue.mask) << 0
     99                | (window->green.value & window->green.mask) << 5
     100                | (window->red.value & window->red.mask) << 11;
     101                // 16 bit color has no alpha bits
     102            break;
     103        default:
     104            keyMask = 0xffffffff;
     105            keyColor = (window->blue.value & window->blue.mask) << 0
     106                | (window->green.value & window->green.mask) << 8
     107                | (window->red.value & window->red.mask) << 16
     108                | (window->alpha.value & window->alpha.mask) << 24;
     109            break;
     110    }
     111
     112    gInfo.WaitForFifo(3);
     113    OUTREG(OVERLAY_GRAPHICS_KEY_MSK, keyMask);
     114    OUTREG(OVERLAY_GRAPHICS_KEY_CLR, keyColor);
     115    OUTREG(OVERLAY_KEY_CNTL, OVERLAY_MIX_FALSE | OVERLAY_MIX_EQUAL);
     116
     117    gInfo.WaitForFifo(8);
     118    OUTREG(OVERLAY_Y_X_START, OVERLAY_LOCK_START | (x1 << 16) | y1);
     119    OUTREG(OVERLAY_Y_X_END, (x2 << 16) | y2);
     120    OUTREG(OVERLAY_SCALE_INC, (horzScale << 16) | vertScale);
     121    OUTREG(SCALER_HEIGHT_WIDTH, (buffer->width << 16) | buffer->height);
     122    OUTREG(VIDEO_FORMAT, videoFormat);
     123
     124    // Compute offset of overlay buffer in the video memory.
     125    uint32 offset = uint32(buffer->buffer) - si.videoMemAddr;
     126   
     127    if (si.chipType < MACH64_264VTB) {
     128        OUTREG(BUF0_OFFSET, offset);
     129        OUTREG(BUF0_PITCH, buffer->width);
     130    } else {
     131        OUTREG(SCALER_BUF0_OFFSET, offset);
     132        OUTREG(SCALER_BUF0_PITCH, buffer->width);
     133    }
     134
     135    OUTREG(OVERLAY_SCALE_CNTL, SCALE_PIX_EXPAND | OVERLAY_EN | SCALE_EN);
     136
     137    return true;
     138}
     139
     140
     141void
     142Mach64_StopOverlay(void)
     143{
     144    OUTREG(OVERLAY_SCALE_CNTL, SCALE_EN);   // reset the video
     145}
  • src/add-ons/accelerants/ati/hooks.cpp

     
    11/*
    2     Copyright 2008 Haiku, Inc.  All rights reserved.
     2    Copyright 2008, 2011 Haiku, Inc.  All rights reserved.
    33    Distributed under the terms of the MIT license.
    44
    55    Authors:
    6     Gerald Zajac 2008
     6    Gerald Zajac
    77*/
    88
    99#include "accelerant.h"
     
    1616
    1717    switch (feature) {
    1818        // General
    19         case B_INIT_ACCELERANT:             return (void*)InitAccelerant;
    20         case B_UNINIT_ACCELERANT:           return (void*)UninitAccelerant;
    21         case B_CLONE_ACCELERANT:            return (void*)CloneAccelerant;
    22         case B_ACCELERANT_CLONE_INFO_SIZE:  return (void*)AccelerantCloneInfoSize;
    23         case B_GET_ACCELERANT_CLONE_INFO:   return (void*)GetAccelerantCloneInfo;
    24         case B_GET_ACCELERANT_DEVICE_INFO:  return (void*)GetAccelerantDeviceInfo;
    25         case B_ACCELERANT_RETRACE_SEMAPHORE: return (void*)AccelerantRetraceSemaphore;
     19        case B_INIT_ACCELERANT:
     20            return (void*)InitAccelerant;
     21        case B_UNINIT_ACCELERANT:
     22            return (void*)UninitAccelerant;
     23        case B_CLONE_ACCELERANT:
     24            return (void*)CloneAccelerant;
     25        case B_ACCELERANT_CLONE_INFO_SIZE:
     26            return (void*)AccelerantCloneInfoSize;
     27        case B_GET_ACCELERANT_CLONE_INFO:
     28            return (void*)GetAccelerantCloneInfo;
     29        case B_GET_ACCELERANT_DEVICE_INFO:
     30            return (void*)GetAccelerantDeviceInfo;
     31        case B_ACCELERANT_RETRACE_SEMAPHORE:
     32            return (void*)AccelerantRetraceSemaphore;
    2633
    2734        // Mode Configuration
    28         case B_ACCELERANT_MODE_COUNT:   return (void*)AccelerantModeCount;
    29         case B_GET_MODE_LIST:           return (void*)GetModeList;
    30         case B_PROPOSE_DISPLAY_MODE:    return (void*)ProposeDisplayMode;
    31         case B_SET_DISPLAY_MODE:        return (void*)SetDisplayMode;
    32         case B_GET_DISPLAY_MODE:        return (void*)GetDisplayMode;
    33         case B_GET_PREFERRED_DISPLAY_MODE: return (void*)GetPreferredDisplayMode;
    34         case B_GET_EDID_INFO:           return (void*)GetEdidInfo;
    35         case B_GET_FRAME_BUFFER_CONFIG: return (void*)GetFrameBufferConfig;
    36         case B_GET_PIXEL_CLOCK_LIMITS:  return (void*)GetPixelClockLimits;
    37         case B_MOVE_DISPLAY:            return (void*)MoveDisplay;
    38         case B_SET_INDEXED_COLORS:      return (void*)(gInfo.SetIndexedColors);
    39         case B_GET_TIMING_CONSTRAINTS:  return (void*)GetTimingConstraints;
     35        case B_ACCELERANT_MODE_COUNT:
     36            return (void*)AccelerantModeCount;
     37        case B_GET_MODE_LIST:
     38            return (void*)GetModeList;
     39        case B_PROPOSE_DISPLAY_MODE:
     40            return (void*)ProposeDisplayMode;
     41        case B_SET_DISPLAY_MODE:
     42            return (void*)SetDisplayMode;
     43        case B_GET_DISPLAY_MODE:
     44            return (void*)GetDisplayMode;
     45        case B_GET_PREFERRED_DISPLAY_MODE:
     46            return (void*)GetPreferredDisplayMode;
     47        case B_GET_EDID_INFO:
     48            return (void*)GetEdidInfo;
     49        case B_GET_FRAME_BUFFER_CONFIG:
     50            return (void*)GetFrameBufferConfig;
     51        case B_GET_PIXEL_CLOCK_LIMITS:
     52            return (void*)GetPixelClockLimits;
     53        case B_MOVE_DISPLAY:
     54            return (void*)MoveDisplay;
     55        case B_SET_INDEXED_COLORS:
     56            return (void*)(gInfo.SetIndexedColors);
     57        case B_GET_TIMING_CONSTRAINTS:
     58            return (void*)GetTimingConstraints;
    4059
    4160        // DPMS
    42         case B_DPMS_CAPABILITIES:       return (void*)(gInfo.DPMSCapabilities);
    43         case B_DPMS_MODE:               return (void*)(gInfo.GetDPMSMode);
    44         case B_SET_DPMS_MODE:           return (void*)(gInfo.SetDPMSMode);
     61        case B_DPMS_CAPABILITIES:
     62            return (void*)(gInfo.DPMSCapabilities);
     63        case B_DPMS_MODE:
     64            return (void*)(gInfo.GetDPMSMode);
     65        case B_SET_DPMS_MODE:
     66            return (void*)(gInfo.SetDPMSMode);
    4567
    4668        // Cursor
    47         case B_SET_CURSOR_SHAPE:        return (void*)SetCursorShape;
    48         case B_MOVE_CURSOR:             return (void*)MoveCursor;
    49         case B_SHOW_CURSOR:             return (void*)(gInfo.ShowCursor);
     69        case B_SET_CURSOR_SHAPE:
     70            return (void*)SetCursorShape;
     71        case B_MOVE_CURSOR:
     72            return (void*)MoveCursor;
     73        case B_SHOW_CURSOR:
     74            return (void*)(gInfo.ShowCursor);
    5075
    5176        // Engine Management
    52         case B_ACCELERANT_ENGINE_COUNT: return (void*)AccelerantEngineCount;
    53         case B_ACQUIRE_ENGINE:          return (void*)AcquireEngine;
    54         case B_RELEASE_ENGINE:          return (void*)ReleaseEngine;
    55         case B_WAIT_ENGINE_IDLE:        return (void*)WaitEngineIdle;
    56         case B_GET_SYNC_TOKEN:          return (void*)GetSyncToken;
    57         case B_SYNC_TO_TOKEN:           return (void*)SyncToToken;
     77        case B_ACCELERANT_ENGINE_COUNT:
     78            return (void*)AccelerantEngineCount;
     79        case B_ACQUIRE_ENGINE:
     80            return (void*)AcquireEngine;
     81        case B_RELEASE_ENGINE:
     82            return (void*)ReleaseEngine;
     83        case B_WAIT_ENGINE_IDLE:
     84            return (void*)WaitEngineIdle;
     85        case B_GET_SYNC_TOKEN:
     86            return (void*)GetSyncToken;
     87        case B_SYNC_TO_TOKEN:
     88            return (void*)SyncToToken;
    5889
    5990        // 2D acceleration
    60         case B_SCREEN_TO_SCREEN_BLIT:   return (void*)(gInfo.ScreenToScreenBlit);
    61         case B_FILL_RECTANGLE:          return (void*)(gInfo.FillRectangle);
    62         case B_INVERT_RECTANGLE:        return (void*)(gInfo.InvertRectangle);
    63         case B_FILL_SPAN:               return (void*)(gInfo.FillSpan);
     91        case B_SCREEN_TO_SCREEN_BLIT:
     92            return (void*)(gInfo.ScreenToScreenBlit);
     93        case B_FILL_RECTANGLE:
     94            return (void*)(gInfo.FillRectangle);
     95        case B_INVERT_RECTANGLE:
     96            return (void*)(gInfo.InvertRectangle);
     97        case B_FILL_SPAN:
     98            return (void*)(gInfo.FillSpan);
     99
     100        // Overlay
     101        case B_OVERLAY_COUNT:
     102            return (void*)OverlayCount;
     103        case B_OVERLAY_SUPPORTED_SPACES:
     104            return (void*)OverlaySupportedSpaces;
     105        case B_OVERLAY_SUPPORTED_FEATURES:
     106            return (void*)OverlaySupportedFeatures;
     107        case B_ALLOCATE_OVERLAY_BUFFER:
     108            return (void*)AllocateOverlayBuffer;
     109        case B_RELEASE_OVERLAY_BUFFER:
     110            return (void*)ReleaseOverlayBuffer;
     111        case B_GET_OVERLAY_CONSTRAINTS:
     112            return (void*)GetOverlayConstraints;
     113        case B_ALLOCATE_OVERLAY:
     114            return (void*)AllocateOverlay;
     115        case B_RELEASE_OVERLAY:
     116            return (void*)ReleaseOverlay;
     117        case B_CONFIGURE_OVERLAY:
     118            return (void*)ConfigureOverlay;
    64119    }
    65120
    66121    return NULL;    // Return null pointer for any feature not handled above
  • src/add-ons/accelerants/ati/Jamfile

     
    1010    engine.cpp
    1111    hooks.cpp
    1212    mode.cpp
     13    overlay.cpp
    1314       
    1415    mach64_cursor.cpp
    1516    mach64_dpms.cpp
    1617    mach64_draw.cpp
    1718    mach64_init.cpp
    1819    mach64_mode.cpp
     20    mach64_overlay.cpp
    1921    mach64_util.cpp
    2022   
    2123    rage128_cursor.cpp
     
    2325    rage128_draw.cpp
    2426    rage128_init.cpp
    2527    rage128_mode.cpp
     28    rage128_overlay.cpp
    2629
    2730    : be libaccelerantscommon.a
    2831;
  • src/add-ons/accelerants/ati/mach64.h

     
    11/*
    2     Haiku ATI video driver adapted from the X.org ATI driver.
     2    Haiku ATI video driver adapted from the X.org ATI driver which has the
     3    following copyright:
    34
    45    Copyright 1992,1993,1994,1995,1996,1997 by Kevin E. Martin, Chapel Hill, North Carolina.
    56
    6     Copyright 2009 Haiku, Inc.  All rights reserved.
     7    Copyright 2009, 2011 Haiku, Inc.  All rights reserved.
    78    Distributed under the terms of the MIT license.
    89
    910    Authors:
    10     Gerald Zajac 2009
     11    Gerald Zajac
    1112*/
    1213
    1314#ifndef __MACH64_H__
     
    178179#define GUI_STAT                (0x0c00 + 0x0338)   // Dword offset CE
    179180
    180181
     182// Definitions used for overlays.
     183//===============================
     184
     185#define REG_BLOCK_1 0x0800      // offset of register block 1 in register area
     186
     187#define OVERLAY_Y_X_START       (REG_BLOCK_1 + 0x0000)  // Dword offset 00
     188#define OVERLAY_LOCK_START      0x80000000ul
     189#define OVERLAY_Y_X_END         (REG_BLOCK_1 + 0x0004)  // Dword offset 01
     190#define OVERLAY_GRAPHICS_KEY_CLR (REG_BLOCK_1 + 0x0010) // Dword offset 04
     191#define OVERLAY_GRAPHICS_KEY_MSK (REG_BLOCK_1 + 0x0014) // Dword offset 05
     192#define OVERLAY_KEY_CNTL        (REG_BLOCK_1 + 0x0018)  // Dword offset 06
     193#define OVERLAY_MIX_FALSE       0x00
     194#define OVERLAY_MIX_EQUAL       0x50
     195#define OVERLAY_SCALE_INC       (REG_BLOCK_1 + 0x0020)  // Dword offset 08
     196#define OVERLAY_SCALE_CNTL      (REG_BLOCK_1 + 0x0024)  // Dword offset 09
     197#define SCALE_PIX_EXPAND        0x00000001
     198#define OVERLAY_EN              0x40000000
     199#define SCALE_EN                0x80000000
     200#define SCALER_HEIGHT_WIDTH     (REG_BLOCK_1 + 0x0028)  // Dword offset 0a
     201#define SCALER_BUF0_OFFSET      (REG_BLOCK_1 + 0x0034)  // Dword offset 0d
     202#define SCALER_BUF0_PITCH       (REG_BLOCK_1 + 0x003c)  // Dword offset 0f
     203#define VIDEO_FORMAT            (REG_BLOCK_1 + 0x0048)  // Dword offset 12
     204#define SCALE_IN_VYUY422        0x000b0000
     205#define BUF0_OFFSET             (REG_BLOCK_1 + 0x0080)  // Dword offset 20
     206#define BUF0_PITCH              (REG_BLOCK_1 + 0x008c)  // Dword offset 23
     207#define SCALER_COLOUR_CNTL      (REG_BLOCK_1 + 0x0150)  // Dword offset 54
     208#define SCALER_H_COEFF0         (REG_BLOCK_1 + 0x0154)  // Dword offset 55
     209#define SCALER_H_COEFF1         (REG_BLOCK_1 + 0x0158)  // Dword offset 56
     210#define SCALER_H_COEFF2         (REG_BLOCK_1 + 0x015c)  // Dword offset 57
     211#define SCALER_H_COEFF3         (REG_BLOCK_1 + 0x0160)  // Dword offset 58
     212#define SCALER_H_COEFF4         (REG_BLOCK_1 + 0x0164)  // Dword offset 59
     213
     214
    181215// CRTC control values.
    182216
    183217#define CRTC_H_SYNC_NEG         0x00200000
     
    225259#define CRTC_PITCH              0xffc00000
    226260
    227261// DAC control values.
    228 
    229262#define DAC_8BIT_EN             0x00000100
    230263
     264
    231265// Mix control values.
    232 
    233266#define MIX_NOT_DST             0x0000
    234267#define MIX_0                   0x0001
    235268#define MIX_1                   0x0002
     
    250283// BUS_CNTL register constants.
    251284#define BUS_FIFO_ERR_ACK        0x00200000
    252285#define BUS_HOST_ERR_ACK        0x00800000
    253 #define BUS_APER_REG_DIS        0x00000010
     286#define BUS_EXT_REG_EN          0x08000000
    254287
    255288// GEN_TEST_CNTL register constants.
    256289#define GEN_OVR_OUTPUT_EN       0x20
     
    361394#define BYTE_ORDER_LSB_TO_MSB 0x1000000
    362395
    363396// DP_SRC register constants.
    364 #define BKGD_SRC_BKGD_CLR       0
    365 #define FRGD_SRC_FRGD_CLR       0x100
    366 #define FRGD_SRC_BLIT           0x300
    367 #define MONO_SRC_ONE                0
     397#define BKGD_SRC_BKGD_CLR   0
     398#define FRGD_SRC_FRGD_CLR   0x100
     399#define FRGD_SRC_BLIT       0x300
     400#define MONO_SRC_ONE        0
    368401
    369402// GUI_STAT register constants.
    370 #define ENGINE_BUSY                 1
     403#define ENGINE_BUSY         1
    371404
    372405// LCD Index register constants.
    373406#define LCD_REG_INDEX       0x0000003F