1/*
2 *
3 * Copyright (C) 2000 Keith Packard
4 *               2004 Eric Anholt
5 *               2005 Zack Rusin
6 *
7 * Copyright 2011 VMWare, Inc. All rights reserved.
8 *
9 * Permission to use, copy, modify, distribute, and sell this software and its
10 * documentation for any purpose is hereby granted without fee, provided that
11 * the above copyright notice appear in all copies and that both that
12 * copyright notice and this permission notice appear in supporting
13 * documentation, and that the name of copyright holders not be used in
14 * advertising or publicity pertaining to distribution of the software without
15 * specific, written prior permission. Copyright holders make no
16 * representations about the suitability of this software for any purpose.  It
17 * is provided "as is" without express or implied warranty.
18 *
19 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
20 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
24 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
25 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26 * SOFTWARE.
27 *
28 * Author: Based on "exa.h"
29 * Author: Thomas Hellstrom <thellstrom@vmware.com>
30 */
31
32#ifndef _SAA_H_
33#define _SAA_H_
34
35#ifdef HAVE_CONFIG_H
36#include <config.h>
37#endif
38#ifdef HAVE_DIX_CONFIG_H
39#include <dix-config.h>
40#else
41#include <xorg-server.h>
42#endif
43#include <xf86.h>
44#include <damage.h>
45#include <picturestr.h>
46
47#include "../src/compat-api.h"
48
49#define SAA_VERSION_MAJOR 0
50#define SAA_VERSION_MINOR 1
51
52#define SAA_ACCESS_R (1 << 0)
53#define SAA_ACCESS_W (1 << 1)
54#define SAA_ACCESS_RW (SAA_ACCESS_R | SAA_ACCESS_W)
55
56#define SAA_PIXMAP_HINT_CREATE_HW (1 << 25)
57#define SAA_PIXMAP_PREFER_SHADOW  (1 << 0)
58
59typedef unsigned int saa_access_t;
60
61enum saa_pixmap_loc {
62    saa_loc_driver,
63    saa_loc_override,
64};
65
66struct saa_pixmap {
67    PixmapPtr pixmap;
68    int read_access;
69    int write_access;
70    unsigned int mapped_access;
71    Bool fallback_created;
72    RegionRec dirty_shadow;
73    RegionRec dirty_hw;
74    RegionRec shadow_damage;
75    DamagePtr damage;
76    void *addr;
77    void *override;
78    enum saa_pixmap_loc auth_loc;
79    PictFormatShort src_format;
80    PictFormatShort dst_format;
81    uint32_t pad[16];
82};
83
84struct saa_driver {
85    unsigned int saa_major;
86    unsigned int saa_minor;
87    size_t pixmap_size;
88     Bool(*damage) (struct saa_driver * driver, PixmapPtr pixmap,
89		    Bool hw, RegionPtr damage);
90    void (*operation_complete) (struct saa_driver * driver, PixmapPtr pixmap);
91     Bool(*download_from_hw) (struct saa_driver * driver, PixmapPtr pixmap,
92			      RegionPtr readback);
93    void (*release_from_cpu) (struct saa_driver * driver, PixmapPtr pixmap,
94			      saa_access_t access);
95    void *(*sync_for_cpu) (struct saa_driver * driver, PixmapPtr pixmap,
96			   saa_access_t access);
97    void *(*map) (struct saa_driver * driver, PixmapPtr pixmap,
98		  saa_access_t access);
99    void (*unmap) (struct saa_driver * driver, PixmapPtr pixmap,
100		   saa_access_t access);
101     Bool(*create_pixmap) (struct saa_driver * driver, struct saa_pixmap * spix,
102			   int w, int h, int depth, unsigned int usage_hint,
103			   int bpp, int *new_pitch);
104    void (*destroy_pixmap) (struct saa_driver * driver, PixmapPtr pixmap);
105    Bool (*modify_pixmap_header) (PixmapPtr pixmap, int w, int h, int depth,
106				  int bpp, int devkind, void *pPixData);
107
108    Bool (*copy_prepare) (struct saa_driver * driver, PixmapPtr src_pixmap,
109			 PixmapPtr dst_pixmap, int dx, int dy, int alu,
110			 RegionPtr scr_reg, uint32_t plane_mask);
111    void (*copy) (struct saa_driver * driver, int src_x, int src_y, int dst_x,
112		  int dst_y, int w, int h);
113    void (*copy_done) (struct saa_driver * driver);
114    Bool (*composite_prepare) (struct saa_driver *driver, CARD8 op,
115			       PicturePtr src_pict, PicturePtr mask_pict,
116			       PicturePtr dst_pict,
117			       PixmapPtr src_pix, PixmapPtr mask_pix,
118			       PixmapPtr dst_pix,
119			       RegionPtr src_region,
120			       RegionPtr mask_region,
121			       RegionPtr dst_region);
122    void (*composite) (struct saa_driver *driver,
123		       int src_x, int src_y, int mask_x, int mask_y,
124		       int dst_x, int dst_y,
125		       int width, int height);
126    void (*composite_done) (struct saa_driver *driver);
127
128    void (*takedown) (struct saa_driver * driver);
129    uint32_t pad[16];
130};
131
132extern _X_EXPORT PixmapPtr
133saa_get_drawable_pixmap(DrawablePtr pDrawable);
134
135extern _X_EXPORT void
136saa_get_drawable_deltas(DrawablePtr pDrawable, PixmapPtr pPixmap,
137			int *xp, int *yp);
138
139extern _X_EXPORT PixmapPtr
140saa_get_pixmap(DrawablePtr drawable, int *xp, int *yp);
141
142extern _X_EXPORT Bool
143saa_prepare_access_pixmap(PixmapPtr pix, saa_access_t access,
144			  RegionPtr read_reg);
145
146extern _X_EXPORT Bool
147saa_pad_read(DrawablePtr draw);
148
149Bool
150saa_pad_read_box(DrawablePtr draw, int x, int y, int w, int h);
151
152extern _X_EXPORT Bool
153saa_pad_write(DrawablePtr draw, GCPtr pGC, Bool check_read,
154	      saa_access_t * access);
155
156extern _X_EXPORT void
157saa_finish_access_pixmap(PixmapPtr pix, saa_access_t access);
158
159extern _X_EXPORT void
160saa_fad_read(DrawablePtr draw);
161
162extern _X_EXPORT void
163saa_fad_write(DrawablePtr draw, saa_access_t access);
164
165extern _X_EXPORT Bool
166saa_resources_init(ScreenPtr screen);
167
168extern _X_EXPORT void
169saa_driver_fini(ScreenPtr pScreen);
170
171extern _X_EXPORT int
172saa_create_gc(GCPtr pGC);
173
174extern _X_EXPORT RegionPtr
175saa_bitmap_to_region(PixmapPtr pPix);
176
177extern _X_EXPORT Bool
178saa_close_screen(CLOSE_SCREEN_ARGS_DECL);
179
180extern _X_EXPORT Bool
181saa_gc_reads_destination(DrawablePtr pDrawable, GCPtr pGC);
182
183extern _X_EXPORT Bool
184saa_op_reads_destination(CARD8 op);
185
186extern _X_EXPORT void
187saa_set_fallback_debug(ScreenPtr screen, Bool enable);
188
189extern _X_EXPORT
190struct saa_pixmap *saa_get_saa_pixmap(PixmapPtr pPixmap);
191
192extern _X_EXPORT Bool
193saa_add_damage(PixmapPtr pixmap);
194
195extern _X_EXPORT struct saa_driver *
196saa_get_driver(ScreenPtr pScreen);
197
198extern _X_EXPORT Bool
199saa_driver_init(ScreenPtr screen, struct saa_driver *saa_driver);
200
201extern _X_EXPORT void
202saa_pixmap_dirty(PixmapPtr pixmap, Bool hw, RegionPtr reg);
203
204extern _X_EXPORT void
205saa_drawable_dirty(DrawablePtr draw, Bool hw, RegionPtr reg);
206
207#define SAA_PM_IS_SOLID(_pDrawable, _pm) \
208  (((_pm) & FbFullMask((_pDrawable)->depth)) == \
209   FbFullMask((_pDrawable)->depth))
210
211#endif
212