chip.c revision 1117
290N/A
290N/A/*
290N/A * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
290N/A *
761N/A * Permission is hereby granted, free of charge, to any person obtaining a
761N/A * copy of this software and associated documentation files (the "Software"),
290N/A * to deal in the Software without restriction, including without limitation
290N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
290N/A * and/or sell copies of the Software, and to permit persons to whom the
290N/A * Software is furnished to do so, subject to the following conditions:
290N/A *
290N/A * The above copyright notice and this permission notice (including the next
290N/A * paragraph) shall be included in all copies or substantial portions of the
290N/A * Software.
290N/A *
290N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
290N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
290N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
290N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
290N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
290N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
290N/A * DEALINGS IN THE SOFTWARE.
290N/A */
290N/A
290N/A#include <sys/types.h>
290N/A#include <errno.h>
290N/A#include <signal.h> /* signal() */
290N/A#include <stdio.h>
290N/A#include <stropts.h> /* ioctl() */
290N/A#include <unistd.h> /* ioctl(), sleep() */
290N/A#include <sys/mman.h>
290N/A
761N/A#include "gfx_common.h" /* VTS Graphics Test common routines */
290N/A#include "graphicstest.h"
290N/A#include "gfx_vts.h" /* VTS Graphics Test common routines */
290N/A#include "ast.h"
493N/A
290N/Avoid
290N/Abox(struct ast_info *pAST, int x1, int y1, int x2, int y2, unsigned int color)
761N/A{
290N/A int tmp;
290N/A int width;
290N/A int height;
290N/A
293N/A if (x2 < x1) {
290N/A tmp = x2;
290N/A x2 = x1;
493N/A x1 = tmp;
493N/A }
290N/A if (y2 < y1) {
290N/A tmp = y2;
y2 = y1;
y1 = tmp;
}
width = x2 - x1;
height = y2 - y1;
ASTSetupForSolidFill(pAST, color, 0xf0);
ASTSolidFillRect(pAST, x1, y1, width, height);
} /* box() */
void
line(struct ast_info *pAST,
int x1,
int y1,
int x2,
int y2,
unsigned int color
)
{
ASTSetupForSolidLine(pAST, color, 0xf0);
ASTSolidLine(pAST, x1, y1, x2, y2);
} /* line() */
void
draw_cascaded_box(struct ast_info *pAST, int width, int height)
{
unsigned int x1;
unsigned int y1;
unsigned int x2;
unsigned int y2;
unsigned int w;
unsigned int h;
int i;
unsigned int k = 0;
for (i = 0; i < 256; i++) {
x1 = (unsigned int)((width * i) / 512);
x2 = width - x1;
w = x2 - x1;
y1 = (unsigned int)((height * i) / 512);
y2 = height - y1;
k = (i<<24 | i<<16 | i<<8 | i);
box(pAST, x1, y1, x2, y2, k);
}
} /* draw_cascaded_box() */
void
draw_lines(struct ast_info *pAST, int width, int height)
{
unsigned int x1;
unsigned int y1;
unsigned int x2;
unsigned int y2;
int k;
int i;
int nlines = 128;
k = 0;
for (i = 0; i < nlines; i++) {
k = 0x00af0000 | (i << 8) | i;
x1 = (unsigned int)((width * i) / nlines);
x2 = x1;
y1 = 0;
y2 = height;
line(pAST, x1, y1, x2, y2, k);
}
for (i = 0; i < nlines; i++) {
k = 0x00af0000 | (i << 8) | i;
x1 = 0;
x2 = width;
y1 = (unsigned int)((height * i) / nlines);
y2 = y1;
line(pAST, x1, y1, x2, y2, k);
}
}
void
chip_test(return_packet *rp, int fd)
{
struct ast_info ast_info;
struct ast_info *pAST;
unsigned int red;
unsigned char *fbaddr;
int i;
int bytepp;
int fb_offset, fb_pitch, fb_height, fb_width;
pAST = &ast_info;
pAST->fd = fd;
/*
* map the registers & frame buffers memory
*/
if (ast_map_mem(pAST, rp, GRAPHICS_ERR_CHIP) == -1) {
return;
}
/*
* initialize ast info
*/
if (ast_init_info(pAST) == -1) {
return;
}
/*
* only support 32 bits depth for now
*/
if (pAST->bytesPerPixel == 1) {
goto done;
}
/*
* enable 2D, initialize command queue
*/
ASTEnable2D(pAST);
if (ASTInitCMDQ(pAST) == -1) {
pAST->MMIO2D = 1;
} else {;
ASTEnableCMDQ(pAST);
}
ASTSaveState(pAST);
/*
* set clipping rectangle
*/
ASTSetClippingRectangle(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight);
/*
* Clear screen
*/
box(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight, 0);
ASTWaitEngIdle(pAST);
/*
* line test
*/
draw_lines(pAST, pAST->screenWidth, pAST->screenHeight);
ASTWaitEngIdle(pAST);
sleep(2);
/*
* fill test
*/
draw_cascaded_box(pAST, pAST->screenWidth, pAST->screenHeight);
ASTWaitEngIdle(pAST);
sleep(2);
/*
* Clear screen
*/
box(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight, 0xff);
ASTWaitEngIdle(pAST);
sleep(2);
ASTResetState(pAST);
done:
/*
* Unmap the registers & frame buffers memory
*/
if (ast_unmap_mem(pAST, rp, GRAPHICS_ERR_CHIP) == -1) {
return;
}
if (close(fd) == -1) {
gfx_vts_set_message(rp, 1, GRAPHICS_ERR_CHIP, "error closing device\n");
return;
}
} /* chip_test() */
/* End of chip.c */