16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved.
56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions:
136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the
156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software.
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#ifndef INTEL_REGIONS_H
296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_REGIONS_H
306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
31f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie/** @file intel_regions.h
32f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie *
3334474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt * Structure definitions and prototypes for intel_region handling,
3434474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt * which is the basic structure for rectangular collections of pixels
3534474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt * stored in a drm_intel_bo.
36f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie */
37f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
382e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke#include <stdbool.h>
393628185f566e178a12b493fb89abf52b4b281f99Eric Anholt#include <xf86drm.h>
403628185f566e178a12b493fb89abf52b4b281f99Eric Anholt
41ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/mtypes.h"
423628185f566e178a12b493fb89abf52b4b281f99Eric Anholt#include "intel_bufmgr.h"
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
44434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#ifdef __cplusplus
45434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berryextern "C" {
46434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#endif
47434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_context;
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_buffer_object;
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * A layer on top of the bufmgr buffers that adds a few useful things:
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - Refcounting for local buffer references.
556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - Refcounting for buffer maps
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - Buffer dimensions - pitch and height.
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - Blitter commands for copying 2D regions between buffers. (really???)
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_region
606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
618004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt   drm_intel_bo *bo;  /**< buffer manager's buffer */
626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint refcount; /**< Reference count for region */
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint cpp;      /**< bytes per pixel */
648db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt   GLuint width;    /**< in pixels */
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint height;   /**< in pixels */
668db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt   GLuint pitch;    /**< in pixels */
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLubyte *map;    /**< only non-NULL when region is actually mapped */
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint map_refcount;  /**< Reference count for mapping */
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
70f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   uint32_t tiling; /**< Which tiling mode the region is in */
712d99588b3556928a0879b4160210ac771dbf1f0bKristian Høgsberg
722d99588b3556928a0879b4160210ac771dbf1f0bKristian Høgsberg   uint32_t name; /**< Global name for the bo */
732d99588b3556928a0879b4160210ac771dbf1f0bKristian Høgsberg   struct intel_screen *screen;
746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell};
756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Allocate a refcounted region.  Pointers to regions should only be
786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copied by calling intel_reference_region().
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
809087ba128089ed0dc00e6eb38f37126fb7557d3bKristian Høgsbergstruct intel_region *intel_region_alloc(struct intel_screen *screen,
811ba96651e12b3c74fb9c8f5a61b183ef36a27b1eEric Anholt                                        uint32_t tiling,
821ba96651e12b3c74fb9c8f5a61b183ef36a27b1eEric Anholt					GLuint cpp, GLuint width,
83da011faf48155a5c02ebc1fe1fa20a4f54b8c657Eric Anholt                                        GLuint height,
842e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke					bool expect_accelerated_upload);
856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
86c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsbergstruct intel_region *
879087ba128089ed0dc00e6eb38f37126fb7557d3bKristian Høgsbergintel_region_alloc_for_handle(struct intel_screen *screen,
888db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt			      GLuint cpp,
898db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt			      GLuint width, GLuint height, GLuint pitch,
90f56b569e9af356c11869ee49a4669bb01b75397eKristian Høgsberg			      unsigned int handle, const char *name);
91c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
922e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkebool
93f301932dba4cc75e810e0c051e39247128a899fcKristian Høgsbergintel_region_flink(struct intel_region *region, uint32_t *name);
94f301932dba4cc75e810e0c051e39247128a899fcKristian Høgsberg
956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_region_reference(struct intel_region **dst,
966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                            struct intel_region *src);
976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_region_release(struct intel_region **ib);
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1007c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholtvoid intel_recreate_static_regions(struct intel_context *intel);
1017c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholt
102f8377b411dfe3c879eaab11bb86f509178796bd1Chad Versace/**
103f8377b411dfe3c879eaab11bb86f509178796bd1Chad Versace * Map/unmap regions.  This is refcounted also:
104f8377b411dfe3c879eaab11bb86f509178796bd1Chad Versace *
105f8377b411dfe3c879eaab11bb86f509178796bd1Chad Versace * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1074cb1d6a25e4749ec5e0389ca3da468adbbe5299eEric Anholtvoid *intel_region_map(struct intel_context *intel,
1084cb1d6a25e4749ec5e0389ca3da468adbbe5299eEric Anholt		       struct intel_region *ib,
1094cb1d6a25e4749ec5e0389ca3da468adbbe5299eEric Anholt		       GLbitfield mode);
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1117c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholtvoid intel_region_unmap(struct intel_context *intel, struct intel_region *ib);
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Copy rectangular sub-regions
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1152e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkebool
1168f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholtintel_region_copy(struct intel_context *intel,
1178f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt		  struct intel_region *dest,
1188f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt		  GLuint dest_offset,
1198f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt		  GLuint destx, GLuint desty,
1208f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt		  struct intel_region *src,
1218f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt		  GLuint src_offset,
1228f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt		  GLuint srcx, GLuint srcy, GLuint width, GLuint height,
1232e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke		  bool flip,
1248f81a6468fdbc7320800ea497791e3e1b8f782caEric Anholt		  GLenum logicop);
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
126a9a483b43ec090408148d069bc184c0a21323654Zou Nan haivoid _mesa_copy_rect(GLubyte * dst,
127a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                GLuint cpp,
128a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                GLuint dst_pitch,
129a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                GLuint dst_x,
130a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                GLuint dst_y,
131a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                GLuint width,
132a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                GLuint height,
133a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                const GLubyte * src,
134a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai                GLuint src_pitch, GLuint src_x, GLuint src_y);
135a9a483b43ec090408148d069bc184c0a21323654Zou Nan hai
1363ec0e55b63db3c1067f3bbf4563beb3b98a19288Paul Berryvoid
1373ec0e55b63db3c1067f3bbf4563beb3b98a19288Paul Berryintel_region_get_tile_masks(struct intel_region *region,
13896fd94ba9421c7c3072988f999ee869534f2bc2aPaul Berry                            uint32_t *mask_x, uint32_t *mask_y,
13996fd94ba9421c7c3072988f999ee869534f2bc2aPaul Berry                            bool map_stencil_as_y_tiled);
1403ec0e55b63db3c1067f3bbf4563beb3b98a19288Paul Berry
1413ec0e55b63db3c1067f3bbf4563beb3b98a19288Paul Berryuint32_t
1423ec0e55b63db3c1067f3bbf4563beb3b98a19288Paul Berryintel_region_get_aligned_offset(struct intel_region *region, uint32_t x,
14368da5dfc2c2e9c0aca47431076be0cd43406d4aaPaul Berry                                uint32_t y, bool map_stencil_as_y_tiled);
1443ec0e55b63db3c1067f3bbf4563beb3b98a19288Paul Berry
14500978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz/**
14600978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz * Used with images created with image_from_names
14700978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz * to help support planar images.
14800978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz */
14900978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantzstruct intel_image_format {
15000978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   int fourcc;
15100978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   int components;
15200978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   int nplanes;
15300978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   struct {
15400978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz      int buffer_index;
15500978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz      int width_shift;
15600978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz      int height_shift;
15700978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz      uint32_t dri_format;
15800978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz      int cpp;
15900978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   } planes[3];
16000978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz};
16100978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz
162c26247100bfd453a7ec013f630abe366c12fbd8bKristian Høgsbergstruct __DRIimageRec {
163c26247100bfd453a7ec013f630abe366c12fbd8bKristian Høgsberg   struct intel_region *region;
164c26247100bfd453a7ec013f630abe366c12fbd8bKristian Høgsberg   GLenum internal_format;
1658de5c355fa2bf0f30df2c7cf39aee01e793284bfJesse Barnes   uint32_t dri_format;
166c26247100bfd453a7ec013f630abe366c12fbd8bKristian Høgsberg   GLuint format;
16795bc0527e9f81c62cbfe02dace94e73d9950d04dKristian Høgsberg   uint32_t offset;
16800978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz
16900978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   /*
17000978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz    * Need to save these here between calls to
17100978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz    * image_from_names and calls to image_from_planar.
17200978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz    */
17300978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   uint32_t strides[3];
17400978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   uint32_t offsets[3];
17500978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz   struct intel_image_format *planar_format;
17600978098794f723230a33cab1c1152686f1c4fa5Jakob Bornecrantz
177c26247100bfd453a7ec013f630abe366c12fbd8bKristian Høgsberg   void *data;
178c26247100bfd453a7ec013f630abe366c12fbd8bKristian Høgsberg};
179c26247100bfd453a7ec013f630abe366c12fbd8bKristian Høgsberg
180434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#ifdef __cplusplus
181434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry}
182434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#endif
183434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry
1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
185