summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-04-24 13:32:48 +0200
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-05-18 17:53:30 +0200
commite660b454a80c91083bc740b14bdfcfeea1ed743c (patch)
treead6f82b67af674e4b7a28ef2362493189ae54adf
parent244467e0ed921b68939964cf43b16ca57ffb5e63 (diff)
intel: introduce new intel_region_alloc_for_handle2().
This is an extended version of the original intel_region_alloc_for_handle() function but with extra attributes for future usage. e.g. picture structure, offset to bo base, etc.
-rw-r--r--src/mesa/drivers/dri/intel/intel_regions.c42
-rw-r--r--src/mesa/drivers/dri/intel/intel_regions.h28
2 files changed, 53 insertions, 17 deletions
diff --git a/src/mesa/drivers/dri/intel/intel_regions.c b/src/mesa/drivers/dri/intel/intel_regions.c
index 1ef1ac663c..24a7be4418 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.c
+++ b/src/mesa/drivers/dri/intel/intel_regions.c
@@ -160,8 +160,7 @@ intel_region_unmap(struct intel_context *intel, struct intel_region *region)
static struct intel_region *
intel_region_alloc_internal(struct intel_screen *screen,
- GLuint cpp,
- GLuint width, GLuint height, GLuint pitch,
+ const struct intel_region_attributes *attrs,
uint32_t tiling, drm_intel_bo *buffer)
{
struct intel_region *region;
@@ -170,10 +169,10 @@ intel_region_alloc_internal(struct intel_screen *screen,
if (region == NULL)
return region;
- region->cpp = cpp;
- region->width = width;
- region->height = height;
- region->pitch = pitch;
+ region->cpp = attrs->cpp;
+ region->width = attrs->width;
+ region->height = attrs->height;
+ region->pitch = attrs->pitch;
region->refcount = 1;
region->bo = buffer;
region->tiling = tiling;
@@ -193,6 +192,7 @@ intel_region_alloc(struct intel_screen *screen,
unsigned long flags = 0;
unsigned long aligned_pitch;
struct intel_region *region;
+ struct intel_region_attributes attrs;
if (expect_accelerated_upload)
flags |= BO_ALLOC_FOR_RENDER;
@@ -203,8 +203,11 @@ intel_region_alloc(struct intel_screen *screen,
if (buffer == NULL)
return NULL;
- region = intel_region_alloc_internal(screen, cpp, width, height,
- aligned_pitch / cpp, tiling, buffer);
+ attrs.cpp = cpp;
+ attrs.width = width;
+ attrs.height = height;
+ attrs.pitch = aligned_pitch / cpp;
+ region = intel_region_alloc_internal(screen, &attrs, tiling, buffer);
if (region == NULL) {
drm_intel_bo_unreference(buffer);
return NULL;
@@ -229,11 +232,20 @@ intel_region_flink(struct intel_region *region, uint32_t *name)
return true;
}
+static inline bool
+intel_region_validate_attributes(const struct intel_region *region,
+ const struct intel_region_attributes *attrs)
+{
+ return (region->cpp == attrs->cpp &&
+ region->width == attrs->width &&
+ region->height == attrs->height &&
+ region->pitch == attrs->pitch);
+}
+
struct intel_region *
-intel_region_alloc_for_handle(struct intel_screen *screen,
- GLuint cpp,
- GLuint width, GLuint height, GLuint pitch,
- GLuint handle, const char *name)
+intel_region_alloc_for_handle2(struct intel_screen *screen,
+ unsigned int handle, const char *name,
+ const struct intel_region_attributes *attrs)
{
struct intel_region *region, *dummy;
drm_intel_bo *buffer;
@@ -243,8 +255,7 @@ intel_region_alloc_for_handle(struct intel_screen *screen,
region = _mesa_HashLookup(screen->named_regions, handle);
if (region != NULL) {
dummy = NULL;
- if (region->width != width || region->height != height ||
- region->cpp != cpp || region->pitch != pitch) {
+ if (!intel_region_validate_attributes(region, attrs)) {
fprintf(stderr,
"Region for name %d already exists but is not compatible\n",
handle);
@@ -265,8 +276,7 @@ intel_region_alloc_for_handle(struct intel_screen *screen,
return NULL;
}
- region = intel_region_alloc_internal(screen, cpp,
- width, height, pitch, tiling, buffer);
+ region = intel_region_alloc_internal(screen, attrs, tiling, buffer);
if (region == NULL) {
drm_intel_bo_unreference(buffer);
return NULL;
diff --git a/src/mesa/drivers/dri/intel/intel_regions.h b/src/mesa/drivers/dri/intel/intel_regions.h
index 2fb30eb48f..ab3e2bdf69 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.h
+++ b/src/mesa/drivers/dri/intel/intel_regions.h
@@ -73,6 +73,17 @@ struct intel_region
struct intel_screen *screen;
};
+/**
+ * A helper structure that defines attributes useful for importing buffers.
+ * See. intel_region_alloc_for_handle().
+ */
+struct intel_region_attributes {
+ GLuint cpp; /**< bytes per pixel */
+ GLuint width; /**< in pixels */
+ GLuint height; /**< in pixels */
+ GLuint pitch; /**< in pixels */
+};
+
/* Allocate a refcounted region. Pointers to regions should only be
* copied by calling intel_reference_region().
@@ -83,11 +94,26 @@ struct intel_region *intel_region_alloc(struct intel_screen *screen,
GLuint height,
bool expect_accelerated_upload);
+/* Extended version of intel_region_alloc_for_handle() with attributes */
struct intel_region *
+intel_region_alloc_for_handle2(struct intel_screen *screen,
+ unsigned int handle, const char *name,
+ const struct intel_region_attributes *attrs);
+
+static inline struct intel_region *
intel_region_alloc_for_handle(struct intel_screen *screen,
GLuint cpp,
GLuint width, GLuint height, GLuint pitch,
- unsigned int handle, const char *name);
+ unsigned int handle, const char *name)
+{
+ struct intel_region_attributes attrs;
+
+ attrs.cpp = cpp;
+ attrs.width = width;
+ attrs.height = height;
+ attrs.pitch = pitch;
+ return intel_region_alloc_for_handle2(screen, handle, name, &attrs);
+}
bool
intel_region_flink(struct intel_region *region, uint32_t *name);