i965: Use helper function for modifier -> tiling

Use a helper function and struct to convert between a modifier and
tiling mode, so we can use it later for a tiling -> modifier lookup.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
This commit is contained in:
Daniel Stone
2017-05-03 18:05:10 +01:00
parent 485ece83ac
commit 467332a0ab

View File

@@ -290,6 +290,29 @@ static struct intel_image_format intel_image_formats[] = {
{ 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } } { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }
}; };
static const struct {
uint32_t tiling;
uint64_t modifier;
} tiling_modifier_map[] = {
{ .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR },
{ .tiling = I915_TILING_X, .modifier = I915_FORMAT_MOD_X_TILED },
{ .tiling = I915_TILING_Y, .modifier = I915_FORMAT_MOD_Y_TILED },
};
static uint32_t
modifier_to_tiling(uint64_t modifier)
{
int i;
for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
if (tiling_modifier_map[i].modifier == modifier)
return tiling_modifier_map[i].tiling;
}
assert(0 && "modifier_to_tiling should only receive known modifiers");
unreachable();
}
static void static void
intel_image_warn_if_unaligned(__DRIimage *image, const char *func) intel_image_warn_if_unaligned(__DRIimage *image, const char *func)
{ {
@@ -568,10 +591,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
{ {
__DRIimage *image; __DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate; struct intel_screen *screen = dri_screen->driverPrivate;
/* Historically, X-tiled was the default, and so lack of modifier means uint32_t tiling;
* X-tiled.
*/
uint32_t tiling = I915_TILING_X;
int cpp; int cpp;
/* Callers of this may specify a modifier, or a dri usage, but not both. The /* Callers of this may specify a modifier, or a dri usage, but not both. The
@@ -581,21 +601,18 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count)); assert(!(use && count));
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, count); uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, count);
switch (modifier) { if (modifier == DRM_FORMAT_MOD_INVALID) {
case I915_FORMAT_MOD_X_TILED: /* User requested specific modifiers, none of which work */
assert(tiling == I915_TILING_X);
break;
case DRM_FORMAT_MOD_LINEAR:
tiling = I915_TILING_NONE;
break;
case I915_FORMAT_MOD_Y_TILED:
tiling = I915_TILING_Y;
break;
case DRM_FORMAT_MOD_INVALID:
if (modifiers) if (modifiers)
return NULL; return NULL;
default:
break; /* Historically, X-tiled was the default, and so lack of modifier means
* X-tiled.
*/
tiling = I915_TILING_X;
} else {
/* select_best_modifier has found a modifier we support */
tiling = modifier_to_tiling(modifier);
} }
if (use & __DRI_IMAGE_USE_CURSOR) { if (use & __DRI_IMAGE_USE_CURSOR) {