hwc.c revision 2acde915b4868129963ef7dc7afe1f3b35ffeeac
1c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/* 2c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Copyright (C) Texas Instruments - http://www.ti.com/ 3c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 4c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Licensed under the Apache License, Version 2.0 (the "License"); 5c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * you may not use this file except in compliance with the License. 6c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * You may obtain a copy of the License at 7c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 8c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * http://www.apache.org/licenses/LICENSE-2.0 9c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 10c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Unless required by applicable law or agreed to in writing, software 11c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * distributed under the License is distributed on an "AS IS" BASIS, 12c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * See the License for the specific language governing permissions and 14c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * limitations under the License. 15c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 16c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 17c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <errno.h> 18c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <malloc.h> 19c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <stdlib.h> 20c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <stdarg.h> 212125fa148686edfa389121f946377aedaa3d9483Lajos Molnar#include <fcntl.h> 2202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian#include <poll.h> 23751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen#include <sys/eventfd.h> 242125fa148686edfa389121f946377aedaa3d9483Lajos Molnar#include <sys/ioctl.h> 252125fa148686edfa389121f946377aedaa3d9483Lajos Molnar#include <linux/fb.h> 26e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian#include <linux/omapfb.h> 270aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar#include <sys/mman.h> 28e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian#include <sys/resource.h> 29c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 30c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <cutils/properties.h> 31c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <cutils/log.h> 32c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <cutils/native_handle.h> 33876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#define HWC_REMOVE_DEPRECATED_VERSIONS 0 34c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <hardware/hardware.h> 35c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <hardware/hwcomposer.h> 36c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <EGL/egl.h> 372125fa148686edfa389121f946377aedaa3d9483Lajos Molnar#include <hardware_legacy/uevent.h> 380aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar#include <png.h> 391fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse#include <utils/Timers.h> 40c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 41e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian#include <system/graphics.h> 42876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#include <linux/bltsville.h> 43876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 44876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#define MAX_HWC_LAYERS 32 45ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 46e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian#define ASPECT_RATIO_TOLERANCE 0.02f 47a02dce1ac438e0538fbcef1c663092035c5f4348Lajos Molnar 4878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar#define min(a, b) ( { typeof(a) __a = (a), __b = (b); __a < __b ? __a : __b; } ) 4978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar#define max(a, b) ( { typeof(a) __a = (a), __b = (b); __a > __b ? __a : __b; } ) 50d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar#define swap(a, b) do { typeof(a) __a = (a); (a) = (b); (b) = __a; } while (0) 5178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 522704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar#define WIDTH(rect) ((rect).right - (rect).left) 532704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar#define HEIGHT(rect) ((rect).bottom - (rect).top) 542704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar 5516b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar#define DIV_ROUND_UP(a, b) (((a) + (b) - 1) / (b)) 5616b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar 57c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <video/dsscomp.h> 58876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#include <video/omap_hwc.h> 59c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 60c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include "hal_public.h" 61876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#include "rgz_2d.h" 62c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 6383f80658d865b741a024515c523e373df50c091eSunita Nadampalli#include <linux/ion.h> 6483f80658d865b741a024515c523e373df50c091eSunita Nadampalli#include <linux/omap_ion.h> 6583f80658d865b741a024515c523e373df50c091eSunita Nadampalli#include <ion/ion.h> 6683f80658d865b741a024515c523e373df50c091eSunita Nadampalli 67c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define MAX_HW_OVERLAYS 4 6878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar#define NUM_NONSCALING_OVERLAYS 1 6983f80658d865b741a024515c523e373df50c091eSunita Nadampalli#define NUM_EXT_DISPLAY_BACK_BUFFERS 2 70c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 71ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnarstruct ext_transform_t { 72ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u8 rotation : 3; /* 90-degree clockwise rotations */ 73ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u8 hflip : 1; /* flip l-r (after rotation) */ 74ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u8 enabled : 1; /* cloning enabled */ 75ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u8 docking : 1; /* docking vs. mirroring - used for state */ 76ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar}; 77ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 78ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar/* cloning support and state */ 79ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnarstruct omap4_hwc_ext { 80ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar /* support */ 81ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar struct ext_transform_t mirror; /* mirroring settings */ 82ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar struct ext_transform_t dock; /* docking settings */ 833797fa989f5fee97caea2bbadf433a5a9ac03d8dLajos Molnar float lcd_xpy; /* pixel ratio for UI */ 844e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar __u8 avoid_mode_change; /* use HDMI mode used for mirroring if possible */ 852b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar __u8 force_dock; /* must dock */ 862b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar __u8 hdmi_state; /* whether HDMI is connected */ 87ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 88ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar /* state */ 89ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u8 on_tv; /* using a tv */ 90ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar struct ext_transform_t current; /* current settings */ 91ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar struct ext_transform_t last; /* last-used settings */ 92ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 93ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar /* configuration */ 941b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar __u32 last_xres_used; /* resolution and pixel ratio used for mode selection */ 95ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u32 last_yres_used; 964cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar __u32 last_mode; /* 2-s complement of last HDMI mode set, 0 if none */ 974e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar __u32 mirror_mode; /* 2-s complement of mode used when mirroring */ 981b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float last_xpy; 99ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u16 width; /* external screen dimensions */ 100ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u16 height; 101ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u32 xres; /* external screen resolution */ 102ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar __u32 yres; 103ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar float m[2][3]; /* external transformation matrix */ 1048d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_rect_t mirror_region; /* region of screen to mirror */ 105ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar}; 106ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnartypedef struct omap4_hwc_ext omap4_hwc_ext_t; 107ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 108ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar/* used by property settings */ 10978fce72baff38f488a0117591d4241d278a48b1bLajos Molnarenum { 11078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar EXT_ROTATION = 3, /* rotation while mirroring */ 11178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar EXT_HFLIP = (1 << 2), /* flip l-r on output (after rotation) */ 11278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar}; 11378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 114876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenenum bltpolicy { 115876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen BLTPOLICY_DISABLED = 0, 116876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen BLTPOLICY_DEFAULT = 1, /* Default blit policy */ 117876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen BLTPOLICY_ALL, /* Test mode to attempt to blit all */ 118876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen}; 119876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 120876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenenum bltmode { 121876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen BLTMODE_PAINT = 0, /* Attempt to blit layer by layer */ 122876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen BLTMODE_REGION = 1, /* Attempt to blit layers via regions */ 123876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen}; 124876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1250aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar/* ARGB image */ 1260aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarstruct omap4_hwc_img { 1270aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar int width; 1280aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar int height; 1290aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar int rowbytes; 1300aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar int size; 1310aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar unsigned char *ptr; 1320aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar} dock_image = { .rowbytes = 0 }; 1330aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 134c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstruct omap4_hwc_module { 135c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_module_t base; 136c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 137c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_framebuffer_device_public_t *fb_dev; 138c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}; 139c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct omap4_hwc_module omap4_hwc_module_t; 140c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 14158aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthousestruct counts { 14258aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int possible_overlay_layers; 14358aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int composited_layers; 14458aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int scaled_layers; 14558aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int RGB; 14658aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int BGR; 14758aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int NV12; 14858aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int dockable; 14958aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int protected; 15058aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse 15158aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int max_hw_overlays; 15258aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int max_scaling_overlays; 15358aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int mem; 15458aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse unsigned int s3d; 15558aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse}; 15658aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse 157c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstruct omap4_hwc_device { 15800d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar /* static data */ 1596ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_composer_device_1_t base; 1602125fa148686edfa389121f946377aedaa3d9483Lajos Molnar hwc_procs_t *procs; 1612125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_t hdmi_thread; 1622125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_t lock; 163c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 164c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_framebuffer_device_public_t *fb_dev; 165d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar struct dsscomp_display_info fb_dis; 16600d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int fb_fd; /* file descriptor for /dev/fb0 */ 16700d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int dsscomp_fd; /* file descriptor for /dev/dsscomp */ 16800d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int hdmi_fb_fd; /* file descriptor for /dev/fb1 */ 169751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int wakeup_evt; /* eventfd used to wakeup event thread */ 17000d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar 1710aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar int img_mem_size; /* size of fb for hdmi */ 1720aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar void *img_mem_ptr; /* start of fb for hdmi */ 1730aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 17400d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int flags_rgb_order; 17500d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int flags_nv12_only; 176f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar float upscaled_nv12_limit; 177c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 178876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int on_tv; /* using a tv */ 17900d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int force_sgx; 18000d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar omap4_hwc_ext_t ext; /* external mirroring data */ 18100d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int idle; 182ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 183876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen float primary_m[2][3]; /* internal transformation matrix */ 184876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int primary_transform; 185876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int primary_rotation; 186876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_rect_t primary_region; 1875db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 188c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev buffer_handle_t *buffers; 189c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int use_sgx; 19078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar int swap_rb; 191876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int post2_layers; /* Buffers used with DSS pipes*/ 192876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int post2_blit_buffers; /* Buffers used with blit */ 19300d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int ext_ovls; /* # of overlays on external display for current composition */ 19400d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int ext_ovls_wanted; /* # of overlays that should be on external display for current composition */ 19500d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int last_ext_ovls; /* # of overlays on external/internal display for last composition */ 19678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar int last_int_ovls; 197876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 198876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen enum bltmode blt_mode; 199876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen enum bltpolicy blt_policy; 200876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 201876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int blit_flags; 202876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int blit_num; 203876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct omap_hwc_data comp_data; /* This is a kernel data structure */ 204876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct rgz_blt_entry blit_ops[RGZ_MAX_BLITS]; 20558aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse struct counts stats; 20683f80658d865b741a024515c523e373df50c091eSunita Nadampalli int ion_fd; 20783f80658d865b741a024515c523e373df50c091eSunita Nadampalli struct ion_handle *ion_handles[2]; 208751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 209751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* fake vsync event state */ 210751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_t vsync_lock; 211751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int vsync_enabled; 212751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t last_vsync_time; 213751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int last_vsync_time_valid; 214751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t fake_vsync_period; 215c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}; 216c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct omap4_hwc_device omap4_hwc_device_t; 217c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 218734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar#define HAL_FMT(f) ((f) == HAL_PIXEL_FORMAT_TI_NV12 ? "NV12" : \ 219dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse (f) == HAL_PIXEL_FORMAT_TI_NV12_1D ? "NV12" : \ 220734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_YV12 ? "YV12" : \ 221734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_BGRX_8888 ? "xRGB32" : \ 222734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_RGBX_8888 ? "xBGR32" : \ 223734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_BGRA_8888 ? "ARGB32" : \ 224734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_RGBA_8888 ? "ABGR32" : \ 225734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_RGB_565 ? "RGB565" : "??") 226734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 227734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar#define DSS_FMT(f) ((f) == OMAP_DSS_COLOR_NV12 ? "NV12" : \ 228734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == OMAP_DSS_COLOR_RGB24U ? "xRGB32" : \ 229734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == OMAP_DSS_COLOR_ARGB32 ? "ARGB32" : \ 230734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == OMAP_DSS_COLOR_RGB16 ? "RGB565" : "??") 231734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 232c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int debug = 0; 233876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic int debugpost2 = 0; 234876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic int debugblt = 0; 235876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic rgz_t grgz; 236876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic struct bvsurfgeom gscrngeom; 237c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2381fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthousestatic void showfps(void) 2391fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse{ 2401fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static int framecount = 0; 2411fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static int lastframecount = 0; 2421fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static nsecs_t lastfpstime = 0; 2431fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static float fps = 0; 2441fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse char value[PROPERTY_VALUE_MAX]; 2451fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2461fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse property_get("debug.hwc.showfps", value, "0"); 2471fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse if (!atoi(value)) { 2481fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse return; 2491fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse } 2501fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2511fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse framecount++; 2521fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse if (!(framecount & 0x7)) { 2531fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); 2541fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse nsecs_t diff = now - lastfpstime; 2551fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse fps = ((framecount - lastframecount) * (float)(s2ns(1))) / diff; 2561fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse lastfpstime = now; 2571fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse lastframecount = framecount; 2581fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse ALOGI("%d Frames, %f FPS", framecount, fps); 2591fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse } 2601fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse} 2611fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2626ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void dump_layer(hwc_layer_1_t const* l) 263c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2643a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}, {%d,%d,%d,%d}", 265b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->compositionType, l->flags, l->handle, l->transform, l->blending, 266b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.left, 267b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.top, 268b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.right, 269b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.bottom, 270b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.left, 271b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.top, 272b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.right, 273b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.bottom); 274c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 275c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 276c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic void dump_dsscomp(struct dsscomp_setup_dispc_data *d) 277c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 27878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar unsigned i; 279c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2803a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("[%08x] set: %c%c%c %d ovls\n", 281c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev d->sync_id, 282c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev (d->mode & DSSCOMP_SETUP_MODE_APPLY) ? 'A' : '-', 283c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev (d->mode & DSSCOMP_SETUP_MODE_DISPLAY) ? 'D' : '-', 284c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev (d->mode & DSSCOMP_SETUP_MODE_CAPTURE) ? 'C' : '-', 285c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev d->num_ovls); 286c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 28778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar for (i = 0; i < d->num_mgrs; i++) { 28800d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar struct dss2_mgr_info *mi = &d->mgrs[i]; 2893a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD(" (dis%d alpha=%d col=%08x ilace=%d)\n", 290b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar mi->ix, 291b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar mi->alpha_blending, mi->default_color, 292b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar mi->interlaced); 29378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 29478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 295c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev for (i = 0; i < d->num_ovls; i++) { 29600d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar struct dss2_ovl_info *oi = &d->ovls[i]; 297b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar struct dss2_ovl_cfg *c = &oi->cfg; 298b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar if (c->zonly) 2993a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("ovl%d(%s z%d)\n", 300b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->ix, c->enabled ? "ON" : "off", c->zorder); 301b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar else 3023a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("ovl%d(%s z%d %s%s *%d%% %d*%d:%d,%d+%d,%d rot%d%s => %d,%d+%d,%d %p/%p|%d)\n", 303b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->ix, c->enabled ? "ON" : "off", c->zorder, DSS_FMT(c->color_mode), 304b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->pre_mult_alpha ? " premult" : "", 305b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar (c->global_alpha * 100 + 128) / 255, 306b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->width, c->height, c->crop.x, c->crop.y, 307b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->crop.w, c->crop.h, 308b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->rotation, c->mirror ? "+mir" : "", 309b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->win.x, c->win.y, c->win.w, c->win.h, 310b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar (void *) oi->ba, (void *) oi->uv, c->stride); 311c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 312c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 313c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 314734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnarstruct dump_buf { 315734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar char *buf; 316734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar int buf_len; 317734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar int len; 318734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar}; 319734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 320734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnarstatic void dump_printf(struct dump_buf *buf, const char *fmt, ...) 321734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar{ 322734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar va_list ap; 323734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 324734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar va_start(ap, fmt); 325734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar buf->len += vsnprintf(buf->buf + buf->len, buf->buf_len - buf->len, fmt, ap); 326734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar va_end(ap); 327734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar} 328734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 3296ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void dump_set_info(omap4_hwc_device_t *hwc_dev, hwc_display_contents_1_t* list) 330734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar{ 331876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 332734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar char logbuf[1024]; 333734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar struct dump_buf log = { 334734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf = logbuf, 335734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf_len = sizeof(logbuf), 336734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar }; 337734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar unsigned int i; 338734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 339734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "set H{"); 340734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar for (i = 0; list && i < list->numHwLayers; i++) { 341734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (i) 342734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " "); 3436ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer = &list->hwLayers[i]; 344734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 345876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_blit_buffers) { 346876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if ((i + 1) < hwc_dev->post2_layers) 347876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p:%s,", handle, "DSS"); 348876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen else 349876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p:%s,", handle, "BV2D"); 350876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 351876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen else 352876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p:%s,", handle, layer->compositionType == HWC_OVERLAY ? "DSS" : "SGX"); 353734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if ((layer->flags & HWC_SKIP_LAYER) || !handle) { 354734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "SKIP"); 355734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar continue; 356734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 357734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (layer->flags & HWC_HINT_CLEAR_FB) 358734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "CLR,"); 359734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%d*%d(%s)", handle->iWidth, handle->iHeight, HAL_FMT(handle->iFormat)); 360734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (layer->transform) 361734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "~%d", layer->transform); 362734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 363734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "} D{"); 364734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar for (i = 0; i < dsscomp->num_ovls; i++) { 365734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (i) 366734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " "); 367734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%d=", dsscomp->ovls[i].cfg.ix); 368734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (dsscomp->ovls[i].cfg.enabled) 369734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%08x:%d*%d,%s", 370734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dsscomp->ovls[i].ba, 371734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dsscomp->ovls[i].cfg.width, 372734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dsscomp->ovls[i].cfg.height, 373734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar DSS_FMT(dsscomp->ovls[i].cfg.color_mode)); 374734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar else 375734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "-"); 376734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 377734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "} L{"); 378734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar for (i = 0; i < hwc_dev->post2_layers; i++) { 379734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (i) 380734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " "); 381734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%p", hwc_dev->buffers[i]); 382734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 383876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_blit_buffers) { 384876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "} B{"); 385876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = hwc_dev->post2_layers; 386876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen i < hwc_dev->post2_blit_buffers + hwc_dev->post2_layers; i++) { 387876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p ", hwc_dev->buffers[i]); 388876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 389876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 390734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "}%s\n", hwc_dev->use_sgx ? " swap" : ""); 391734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 3923a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("%s", log.buf); 393734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar} 394734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 3955706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int sync_id = 0; 3965706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 397c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_is_valid_format(int format) 398c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 399c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev switch(format) { 400c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGB_565: 401c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGBX_8888: 402c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGBA_8888: 403c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRA_8888: 404c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRX_8888: 405c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_TI_NV12: 406dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse case HAL_PIXEL_FORMAT_TI_NV12_1D: 407c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 1; 408c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 409c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev default: 410c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 411c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 412c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 413c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 414876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic int scaled(hwc_layer_1_t *layer) 415c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 4162704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int w = WIDTH(layer->sourceCrop); 4172704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int h = HEIGHT(layer->sourceCrop); 418d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 419d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar if (layer->transform & HWC_TRANSFORM_ROT_90) 420d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar swap(w, h); 421d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 422876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return WIDTH(layer->displayFrame) != w || HEIGHT(layer->displayFrame) != h; 423c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 424c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 4256ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int is_protected(hwc_layer_1_t *layer) 4264ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli{ 4274ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 4284ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli 4294ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli return (handle->usage & GRALLOC_USAGE_PROTECTED); 4304ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli} 4314ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli 4325706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar#define is_BLENDED(layer) ((layer)->blending != HWC_BLENDING_NONE) 4335706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 434fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrechtstatic int is_RGB32(IMG_native_handle_t *handle) 435fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht{ 436fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht switch(handle->iFormat) 437fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht { 438fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht case HAL_PIXEL_FORMAT_BGRA_8888: 439fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht case HAL_PIXEL_FORMAT_BGRX_8888: 440fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht return 1; 441fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht default: 442fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht return 0; 443fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht } 444fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht} 445fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht 4465706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_RGB(IMG_native_handle_t *handle) 4475706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4485706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar switch(handle->iFormat) 4495706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar { 4505706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_BGRA_8888: 4515706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_BGRX_8888: 4525706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGB_565: 4535706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 1; 4545706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar default: 4555706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 0; 4565706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar } 4575706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 458c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 4595706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_BGR_format(int format) 4605706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4615706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar switch (format) { 4625706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGBX_8888: 4635706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGBA_8888: 4645706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 1; 4655706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar default: 4665706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 0; 4675706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar } 4685706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 469a3a76c576a0a1706c102570697b4fc0017eb46fbMathias Agopian 4705706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_BGR(IMG_native_handle_t *handle) 4715706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4725706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return is_BGR_format(handle->iFormat); 4735706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 4745706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 4755706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_NV12(IMG_native_handle_t *handle) 4765706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4775706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar switch(handle->iFormat) 4785706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar { 4795706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_TI_NV12: 480dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse case HAL_PIXEL_FORMAT_TI_NV12_1D: 4815706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 1; 4825706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar default: 4835706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 0; 4845706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar } 4855706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 486c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 487f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnarstatic int is_upscaled_NV12(omap4_hwc_device_t *hwc_dev, hwc_layer_t *layer) 488f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar{ 489f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (!layer) 490f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar return 0; 491f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 492f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 493f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (!is_NV12(handle)) 494f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar return 0; 495f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 496f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar int w = WIDTH(layer->sourceCrop); 497f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar int h = HEIGHT(layer->sourceCrop); 498f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 499f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (layer->transform & HWC_TRANSFORM_ROT_90) 500f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar swap(w, h); 501f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 502f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar return (WIDTH(layer->displayFrame) >= w * hwc_dev->upscaled_nv12_limit || 503f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar HEIGHT(layer->displayFrame) >= h * hwc_dev->upscaled_nv12_limit); 504f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar} 505f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 506f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnarstatic int dockable(hwc_layer_t *layer) 507834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar{ 508834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 509834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 510834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar return (handle->usage & GRALLOC_USAGE_EXTERNAL_DISP); 511834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar} 512834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 513751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chenstatic uint64_t vsync_clock_now() 514751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen{ 515751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t now = 0; 516751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen struct timespec ts; 517751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 518751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!clock_gettime(CLOCK_MONOTONIC, &ts)) 519751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen now = ((uint64_t)ts.tv_sec) * 1000000000ull + ts.tv_nsec; 520751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 521751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen return now; 522751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen} 523751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 524751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chenstatic void wakeup_hdmi_thread(omap4_hwc_device_t *hwc_dev) 525751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen{ 526751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t tmp = 1; 527751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen write(hwc_dev->wakeup_evt, &tmp, sizeof(tmp)); 528751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen} 529751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 530751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chenstatic void fire_vsync_event(omap4_hwc_device_t *hwc_dev, uint64_t timestamp) 531751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen{ 532751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 533751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 534751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time_valid = 1; 535751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time = timestamp; 536751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 537751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 538751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 539876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->procs && hwc_dev->procs->vsync) 540751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->procs->vsync(hwc_dev->procs, 0, timestamp); 541751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen} 542751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 54338934f125a600817dded7aeba9639c6a75afe358Lajos Molnarstatic unsigned int mem1d(IMG_native_handle_t *handle) 54438934f125a600817dded7aeba9639c6a75afe358Lajos Molnar{ 5455706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar if (handle == NULL || is_NV12(handle)) 546b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar return 0; 54738934f125a600817dded7aeba9639c6a75afe358Lajos Molnar 5485706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar int bpp = handle->iFormat == HAL_PIXEL_FORMAT_RGB_565 ? 2 : 4; 54938934f125a600817dded7aeba9639c6a75afe358Lajos Molnar int stride = ALIGN(handle->iWidth, HW_ALIGN) * bpp; 55038934f125a600817dded7aeba9639c6a75afe358Lajos Molnar return stride * handle->iHeight; 55138934f125a600817dded7aeba9639c6a75afe358Lajos Molnar} 55238934f125a600817dded7aeba9639c6a75afe358Lajos Molnar 553c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic void 5545706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnaromap4_hwc_setup_layer_base(struct dss2_ovl_cfg *oc, int index, int format, int blended, int width, int height) 555c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 556c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev unsigned int bits_per_pixel; 557c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 558c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* YUV2RGB conversion */ 559c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev const struct omap_dss_cconv_coefs ctbl_bt601_5 = { 560c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 298, 409, 0, 298, -208, -100, 298, 0, 517, 0, 561c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev }; 562c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 563c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* convert color format */ 564c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev switch (format) { 565c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGBA_8888: 566c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRA_8888: 567c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_ARGB32; 568c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 32; 5695706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar if (blended) 5705706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar break; 571c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 5725706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGBX_8888: 573c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRX_8888: 574c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_RGB24U; 575c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 32; 576c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev break; 577c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 578c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGB_565: 579c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_RGB16; 580c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 16; 581c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev break; 582c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 583c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_TI_NV12: 584dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse case HAL_PIXEL_FORMAT_TI_NV12_1D: 585c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_NV12; 586c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 8; 587c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->cconv = ctbl_bt601_5; 588c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev break; 589c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 590c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev default: 591c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Should have been filtered out */ 592ac837f2654f5a7a7fbecf05e4b085b87a7701714Steve Block ALOGV("Unsupported pixel format"); 593c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return; 594c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 595c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 596c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->width = width; 597c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->height = height; 598c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->stride = ALIGN(width, HW_ALIGN) * bits_per_pixel / 8; 599c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 600c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->enabled = 1; 601c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->global_alpha = 255; 602c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->zorder = index; 603c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->ix = 0; 604c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 605c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* defaults for SGX framebuffer renders */ 606c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.w = oc->win.w = width; 607c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.h = oc->win.h = height; 608c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 609c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* for now interlacing and vc1 info is not supplied */ 610c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->ilace = OMAP_DSS_ILACE_NONE; 611c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->vc1.enable = 0; 612c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 613c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 614c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic void 615c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevomap4_hwc_setup_layer(omap4_hwc_device_t *hwc_dev, struct dss2_ovl_info *ovl, 6166ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer, int index, 617c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int format, int width, int height) 618c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 619c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev struct dss2_ovl_cfg *oc = &ovl->cfg; 620c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 621c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev //dump_layer(layer); 622c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 6235706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar omap4_hwc_setup_layer_base(oc, index, format, is_BLENDED(layer), width, height); 624c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 625c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* convert transformation - assuming 0-set config */ 626c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform & HWC_TRANSFORM_FLIP_H) 627c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->mirror = 1; 628c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform & HWC_TRANSFORM_FLIP_V) { 629c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->rotation = 2; 63078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar oc->mirror = !oc->mirror; 631c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 632c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform & HWC_TRANSFORM_ROT_90) { 633c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->rotation += oc->mirror ? -1 : 1; 634c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->rotation &= 3; 635c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 636c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 637c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->pre_mult_alpha = layer->blending == HWC_BLENDING_PREMULT; 638c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 639c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* display position */ 640c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->win.x = layer->displayFrame.left; 641c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->win.y = layer->displayFrame.top; 6422704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->win.w = WIDTH(layer->displayFrame); 6432704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->win.h = HEIGHT(layer->displayFrame); 644c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 645c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* crop */ 646c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.x = layer->sourceCrop.left; 647c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.y = layer->sourceCrop.top; 6482704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->crop.w = WIDTH(layer->sourceCrop); 6492704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->crop.h = HEIGHT(layer->sourceCrop); 650c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 651c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 6522952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarconst float m_unit[2][3] = { { 1., 0., 0. }, { 0., 1., 0. } }; 6532952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6542952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline void m_translate(float m[2][3], int dx, int dy) 6552952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6562952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[0][2] += dx; 6572952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[1][2] += dy; 6582952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6592952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6602952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline void m_scale1(float m[3], int from, int to) 6612952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6622952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[0] = m[0] * to / from; 6632952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[1] = m[1] * to / from; 6642952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[2] = m[2] * to / from; 6652952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6662952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6672952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline void m_scale(float m[2][3], int x_from, int x_to, int y_from, int y_to) 6682952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6692952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m_scale1(m[0], x_from, x_to); 6702952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m_scale1(m[1], y_from, y_to); 6712952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6722952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6732952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic void m_rotate(float m[2][3], int quarter_turns) 6742952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6752952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar if (quarter_turns & 2) 6762952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m_scale(m, 1, -1, 1, -1); 6772952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar if (quarter_turns & 1) { 6782952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar int q; 6792952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar q = m[0][0]; m[0][0] = -m[1][0]; m[1][0] = q; 6802952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar q = m[0][1]; m[0][1] = -m[1][1]; m[1][1] = q; 6812952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar q = m[0][2]; m[0][2] = -m[1][2]; m[1][2] = q; 6822952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar } 6832952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6842952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6852952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline int m_round(float x) 6862952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6872952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* int truncates towards 0 */ 6882952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar return (int) (x < 0 ? x - 0.5 : x + 0.5); 6892952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6902952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 691ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar/* 6921b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar * assuming xpy (xratio:yratio) original pixel ratio, calculate the adjusted width 693ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar * and height for a screen of xres/yres and physical size of width/height. 694ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar * The adjusted size is the largest that fits into the screen. 695ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar */ 696ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnarstatic void get_max_dimensions(__u32 orig_xres, __u32 orig_yres, 6971b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float xpy, 698ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 scr_xres, __u32 scr_yres, 699ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 scr_width, __u32 scr_height, 700ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 *adj_xres, __u32 *adj_yres) 701ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar{ 702ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* assume full screen (largest size)*/ 703ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_xres = scr_xres; 704ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_yres = scr_yres; 705ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 706ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* assume 1:1 pixel ratios if none supplied */ 707ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar if (!scr_width || !scr_height) { 708ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar scr_width = scr_xres; 709ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar scr_height = scr_yres; 710ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar } 711ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 712ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* trim to keep aspect ratio */ 7131b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float x_factor = orig_xres * xpy * scr_height; 7141b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float y_factor = orig_yres * scr_width; 715ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 716ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* allow for tolerance so we avoid scaling if framebuffer is standard size */ 717ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar if (x_factor < y_factor * (1.f - ASPECT_RATIO_TOLERANCE)) 718ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_xres = (__u32) (x_factor * *adj_xres / y_factor + 0.5); 719ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar else if (x_factor * (1.f - ASPECT_RATIO_TOLERANCE) > y_factor) 720ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_yres = (__u32) (y_factor * *adj_yres / x_factor + 0.5); 721ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar} 722ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 7238d546610cba3698c62af537d97e38a7368362f1aLajos Molnarstatic void set_ext_matrix(omap4_hwc_ext_t *ext, struct hwc_rect region) 7242952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 7258d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int orig_w = WIDTH(region); 7268d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int orig_h = HEIGHT(region); 7273797fa989f5fee97caea2bbadf433a5a9ac03d8dLajos Molnar float xpy = ext->lcd_xpy; 7282952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 7292952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* reorientation matrix is: 7302952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m = (center-from-target-center) * (scale-to-target) * (mirror) * (rotate) * (center-to-original-center) */ 7312952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 732ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar memcpy(ext->m, m_unit, sizeof(m_unit)); 7338d546610cba3698c62af537d97e38a7368362f1aLajos Molnar m_translate(ext->m, -(orig_w >> 1) - region.left, -(orig_h >> 1) - region.top); 734ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_rotate(ext->m, ext->current.rotation); 735ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar if (ext->current.hflip) 736ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_scale(ext->m, 1, -1, 1, 1); 7372952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 738ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar if (ext->current.rotation & 1) { 739d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar swap(orig_w, orig_h); 7401b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar xpy = 1. / xpy; 7412952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar } 7422952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 743ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* get target size */ 744ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 adj_xres, adj_yres; 7451b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar get_max_dimensions(orig_w, orig_h, xpy, 746ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->xres, ext->yres, ext->width, ext->height, 747ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar &adj_xres, &adj_yres); 7482952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 749ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_scale(ext->m, orig_w, adj_xres, orig_h, adj_yres); 750ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_translate(ext->m, ext->xres >> 1, ext->yres >> 1); 7512952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 7522952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 7538d546610cba3698c62af537d97e38a7368362f1aLajos Molnarstatic int 7548d546610cba3698c62af537d97e38a7368362f1aLajos Molnarcrop_to_rect(struct dss2_ovl_cfg *cfg, struct hwc_rect vis_rect) 7558d546610cba3698c62af537d97e38a7368362f1aLajos Molnar{ 7568d546610cba3698c62af537d97e38a7368362f1aLajos Molnar struct { 7578d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int xy[2]; 7588d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int wh[2]; 7598d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } crop, win; 7608d546610cba3698c62af537d97e38a7368362f1aLajos Molnar struct { 7618d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int lt[2]; 7628d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int rb[2]; 7638d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } vis; 7648d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[0] = cfg->win.x; win.xy[1] = cfg->win.y; 7658d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.wh[0] = cfg->win.w; win.wh[1] = cfg->win.h; 7668d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[0] = cfg->crop.x; crop.xy[1] = cfg->crop.y; 7678d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.wh[0] = cfg->crop.w; crop.wh[1] = cfg->crop.h; 7688d546610cba3698c62af537d97e38a7368362f1aLajos Molnar vis.lt[0] = vis_rect.left; vis.lt[1] = vis_rect.top; 7698d546610cba3698c62af537d97e38a7368362f1aLajos Molnar vis.rb[0] = vis_rect.right; vis.rb[1] = vis_rect.bottom; 7708d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 7718d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int c, swap = cfg->rotation & 1; 7728d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 7738d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* align crop window with display coordinates */ 7748d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (swap) 7758d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[1] -= (crop.wh[1] = -crop.wh[1]); 7768d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (cfg->rotation & 2) 7778d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[!swap] -= (crop.wh[!swap] = -crop.wh[!swap]); 7788d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if ((!cfg->mirror) ^ !(cfg->rotation & 2)) 7798d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[swap] -= (crop.wh[swap] = -crop.wh[swap]); 7808d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 7818d546610cba3698c62af537d97e38a7368362f1aLajos Molnar for (c = 0; c < 2; c++) { 7828d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* see if complete buffer is outside the vis or it is 7838d546610cba3698c62af537d97e38a7368362f1aLajos Molnar fully cropped or scaled to 0 */ 7848d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (win.wh[c] <= 0 || vis.rb[c] <= vis.lt[c] || 7858d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[c] + win.wh[c] <= vis.lt[c] || 7868d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[c] >= vis.rb[c] || 7878d546610cba3698c62af537d97e38a7368362f1aLajos Molnar !crop.wh[c ^ swap]) 7888d546610cba3698c62af537d97e38a7368362f1aLajos Molnar return -ENOENT; 7898d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 7908d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* crop left/top */ 7918d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (win.xy[c] < vis.lt[c]) { 7928d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* correction term */ 7938d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int a = (vis.lt[c] - win.xy[c]) * crop.wh[c ^ swap] / win.wh[c]; 7948d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[c ^ swap] += a; 7958d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.wh[c ^ swap] -= a; 7968d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.wh[c] -= vis.lt[c] - win.xy[c]; 7978d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[c] = vis.lt[c]; 7988d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 7998d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* crop right/bottom */ 8008d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (win.xy[c] + win.wh[c] > vis.rb[c]) { 8018d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.wh[c ^ swap] = crop.wh[c ^ swap] * (vis.rb[c] - win.xy[c]) / win.wh[c]; 8028d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.wh[c] = vis.rb[c] - win.xy[c]; 8038d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 8048d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8058d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (!crop.wh[c ^ swap] || !win.wh[c]) 8068d546610cba3698c62af537d97e38a7368362f1aLajos Molnar return -ENOENT; 8078d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 8088d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8098d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* realign crop window to buffer coordinates */ 8108d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (cfg->rotation & 2) 8118d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[!swap] -= (crop.wh[!swap] = -crop.wh[!swap]); 8128d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if ((!cfg->mirror) ^ !(cfg->rotation & 2)) 8138d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[swap] -= (crop.wh[swap] = -crop.wh[swap]); 8148d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (swap) 8158d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[1] -= (crop.wh[1] = -crop.wh[1]); 8168d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8178d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->win.x = win.xy[0]; cfg->win.y = win.xy[1]; 8188d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->win.w = win.wh[0]; cfg->win.h = win.wh[1]; 8198d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->crop.x = crop.xy[0]; cfg->crop.y = crop.xy[1]; 8208d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->crop.w = crop.wh[0]; cfg->crop.h = crop.wh[1]; 8218d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8228d546610cba3698c62af537d97e38a7368362f1aLajos Molnar return 0; 8238d546610cba3698c62af537d97e38a7368362f1aLajos Molnar} 8248d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8252952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic void 826876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenomap4_hwc_apply_transform(float transform[2][3],struct dss2_ovl_cfg *oc) 8272952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 8282952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar float x, y, w, h; 8292952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 8302952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* display position */ 831876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen x = transform[0][0] * oc->win.x + transform[0][1] * oc->win.y + transform[0][2]; 832876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen y = transform[1][0] * oc->win.x + transform[1][1] * oc->win.y + transform[1][2]; 833876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen w = transform[0][0] * oc->win.w + transform[0][1] * oc->win.h; 834876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen h = transform[1][0] * oc->win.w + transform[1][1] * oc->win.h; 8352952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.x = m_round(w > 0 ? x : x + w); 8362952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.y = m_round(h > 0 ? y : y + h); 8372952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.w = m_round(w > 0 ? w : -w); 8382952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.h = m_round(h > 0 ? h : -h); 8392952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 8402952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 8415db21d521ed41e2e2cc110b698981e841e027287Dandawate Saketstatic void 842876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenomap4_hwc_adjust_ext_layer(omap4_hwc_ext_t *ext, struct dss2_ovl_info *ovl) 8435db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket{ 8445db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket struct dss2_ovl_cfg *oc = &ovl->cfg; 8455db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 846876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* crop to clone region if mirroring */ 847876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!ext->current.docking && 848876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen crop_to_rect(&ovl->cfg, ext->mirror_region) != 0) { 8495db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ovl->cfg.enabled = 0; 8505db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket return; 8515db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 8525db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 853876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen omap4_hwc_apply_transform(ext->m, oc); 8545db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 8555db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket /* combining transformations: F^a*R^b*F^i*R^j = F^(a+b)*R^(j+b*(-1)^i), because F*R = R^(-1)*F */ 856876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->rotation += (oc->mirror ? -1 : 1) * ext->current.rotation; 8575db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket oc->rotation &= 3; 858876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (ext->current.hflip) 859876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->mirror = !oc->mirror; 8605db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket} 861876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 862876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic struct dsscomp_platform_info limits; 863876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 8645db21d521ed41e2e2cc110b698981e841e027287Dandawate Saketstatic void 865876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenomap4_hwc_adjust_primary_display_layer(omap4_hwc_device_t *hwc_dev, struct dss2_ovl_info *ovl) 8665db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket{ 8675db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket struct dss2_ovl_cfg *oc = &ovl->cfg; 8685db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 869876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (crop_to_rect(&ovl->cfg, hwc_dev->primary_region) != 0) { 8705db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ovl->cfg.enabled = 0; 8715db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket return; 8725db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 8735db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 874876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen omap4_hwc_apply_transform(hwc_dev->primary_m, oc); 8755db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 876876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* combining transformations: F^a*R^b*F^i*R^j = F^(a+b)*R^(j+b*(-1)^i), because F*R = R^(-1)*F */ 877876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->rotation += (oc->mirror ? -1 : 1) * hwc_dev->primary_rotation; 878876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->rotation &= 3; 8795db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket} 8805db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 881e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnarstatic int omap4_hwc_can_scale(__u32 src_w, __u32 src_h, __u32 dst_w, __u32 dst_h, int is_2d, 882876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_display_info *dis, struct dsscomp_platform_info *limits, 8834ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar __u32 pclk) 884d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar{ 885d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar __u32 fclk = limits->fclk / 1000; 88616b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar __u32 min_src_w = DIV_ROUND_UP(src_w, is_2d ? limits->max_xdecim_2d : limits->max_xdecim_1d); 88716b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar __u32 min_src_h = DIV_ROUND_UP(src_h, is_2d ? limits->max_ydecim_2d : limits->max_ydecim_1d); 888d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 889d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* ERRATAs */ 890d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* cannot render 1-width layers on DSI video mode panels - we just disallow all 1-width LCD layers */ 891d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (dis->channel != OMAP_DSS_CHANNEL_DIGIT && dst_w < limits->min_width) 892d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 893d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 894d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* NOTE: no support for checking YUV422 layers that are tricky to scale */ 895d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 8961a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian /* FIXME: limit vertical downscale well below theoretical limit as we saw display artifacts */ 8971a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian if (dst_h < src_h / 4) 8981a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian return 0; 8991a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian 900d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* max downscale */ 90116b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar if (dst_h * limits->max_downscale < min_src_h) 902d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 903d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 9044ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar /* for manual panels pclk is 0, and there are no pclk based scaling limits */ 9054ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar if (!pclk) 906b319783cc9e00318eb67b554029bef5932d5436dSunita Nadampalli return !(dst_w < src_w / limits->max_downscale / (is_2d ? limits->max_xdecim_2d : limits->max_xdecim_1d)); 9074ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar 908d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* :HACK: limit horizontal downscale well below theoretical limit as we saw display artifacts */ 90916b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar if (dst_w * 4 < src_w) 910d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 911d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 912d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* max horizontal downscale is 4, or the fclk/pixclk */ 913d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (fclk > pclk * limits->max_downscale) 914d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar fclk = pclk * limits->max_downscale; 915d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* for small parts, we need to use integer fclk/pixclk */ 916d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (src_w < limits->integer_scale_ratio_limit) 917d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar fclk = fclk / pclk * pclk; 91816b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar if ((__u32) dst_w * fclk < min_src_w * pclk) 919d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 920d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 921d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 1; 922d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar} 923d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 9246ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_can_scale_layer(omap4_hwc_device_t *hwc_dev, hwc_layer_1_t *layer, IMG_native_handle_t *handle) 925d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar{ 9262704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int src_w = WIDTH(layer->sourceCrop); 9272704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int src_h = HEIGHT(layer->sourceCrop); 9282704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int dst_w = WIDTH(layer->displayFrame); 9292704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int dst_h = HEIGHT(layer->displayFrame); 930d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 931d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* account for 90-degree rotation */ 932d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar if (layer->transform & HWC_TRANSFORM_ROT_90) 933d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar swap(src_w, src_h); 934d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 9354ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar /* NOTE: layers should be able to be scaled externally since 9364ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar framebuffer is able to be scaled on selected external resolution */ 9375706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return omap4_hwc_can_scale(src_w, src_h, dst_w, dst_h, is_NV12(handle), &hwc_dev->fb_dis, &limits, 9384ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar hwc_dev->fb_dis.timings.pixel_clock); 939d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar} 940d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 941d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnarstatic int omap4_hwc_is_valid_layer(omap4_hwc_device_t *hwc_dev, 9426ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer, 943c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_native_handle_t *handle) 944c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 945c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Skip layers are handled by SF */ 946c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if ((layer->flags & HWC_SKIP_LAYER) || !handle) 947c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 948c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 949c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!omap4_hwc_is_valid_format(handle->iFormat)) 950c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 951c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 952c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* 1D buffers: no transform, must fit in TILER slot */ 9535706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar if (!is_NV12(handle)) { 954c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform) 955c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 956876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (mem1d(handle) > limits.tiler1d_slot_size) 957c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 958c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 959d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 960d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return omap4_hwc_can_scale_layer(hwc_dev, layer, handle); 961c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 962c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 963e14d52936107e390e2464df1e6653efde5409096Lajos Molnarstatic __u32 add_scaling_score(__u32 score, 964e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 xres, __u32 yres, __u32 refresh, 965e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 ext_xres, __u32 ext_yres, 966e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_xres, __u32 mode_yres, __u32 mode_refresh) 967e14d52936107e390e2464df1e6653efde5409096Lajos Molnar{ 968e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 area = xres * yres; 969e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 ext_area = ext_xres * ext_yres; 970e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_area = mode_xres * mode_yres; 971e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 972e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* prefer to upscale (1% tolerance) [0..1] (insert after 1st bit) */ 973e14d52936107e390e2464df1e6653efde5409096Lajos Molnar int upscale = (ext_xres >= xres * 99 / 100 && ext_yres >= yres * 99 / 100); 974e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (((score & ~1) | upscale) << 1) | (score & 1); 975e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 976e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* pick minimum scaling [0..16] */ 977e14d52936107e390e2464df1e6653efde5409096Lajos Molnar if (ext_area > area) 978e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 5) | (16 * area / ext_area); 979e14d52936107e390e2464df1e6653efde5409096Lajos Molnar else 980e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 5) | (16 * ext_area / area); 981e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 982e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* pick smallest leftover area [0..16] */ 983e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 5) | ((16 * ext_area + (mode_area >> 1)) / mode_area); 984e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 985e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* adjust mode refresh rate */ 986e14d52936107e390e2464df1e6653efde5409096Lajos Molnar mode_refresh += mode_refresh % 6 == 5; 987e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 988e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* prefer same or higher frame rate */ 989e14d52936107e390e2464df1e6653efde5409096Lajos Molnar upscale = (mode_refresh >= refresh); 990e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 1) | upscale; 991e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 992e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* pick closest frame rate */ 993e14d52936107e390e2464df1e6653efde5409096Lajos Molnar if (mode_refresh > refresh) 994e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 8) | (240 * refresh / mode_refresh); 995e14d52936107e390e2464df1e6653efde5409096Lajos Molnar else 996e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 8) | (240 * mode_refresh / refresh); 997e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 998e14d52936107e390e2464df1e6653efde5409096Lajos Molnar return score; 999e14d52936107e390e2464df1e6653efde5409096Lajos Molnar} 1000e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 100104c7041e0dc1e9c7d2c4e1be1e78a092de993c27Lajos Molnarstatic int omap4_hwc_set_best_hdmi_mode(omap4_hwc_device_t *hwc_dev, __u32 xres, __u32 yres, 10021b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float xpy) 1003bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar{ 10045db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket int dis_ix = hwc_dev->on_tv ? 0 : 1; 1005ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen int forced_preferred_mode = 0; 10065db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 1007bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar struct _qdis { 1008bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar struct dsscomp_display_info dis; 100904512dd8a3fd2830139e3f352a295841c7eed190Travis Geiselbrecht struct dsscomp_videomode modedb[32]; 10105db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } d = { .dis = { .ix = dis_ix } }; 1011ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 1012bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1013bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar d.dis.modedb_len = sizeof(d.modedb) / sizeof(*d.modedb); 1014cb64c2be21ad9550b1f5d2b4a8361e997b9be757Lajos Molnar int ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_DISPLAY, &d); 1015bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (ret) 1016bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar return ret; 1017bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 10186c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar if (d.dis.timings.x_res * d.dis.timings.y_res == 0 || 10196c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar xres * yres == 0) 10206c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar return -EINVAL; 10216c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar 1022bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 i, best = ~0, best_score = 0; 1023ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->width = d.dis.width_in_mm; 1024ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->height = d.dis.height_in_mm; 1025ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->xres = d.dis.timings.x_res; 1026ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->yres = d.dis.timings.y_res; 10273837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 10283837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* use VGA external resolution as default */ 10293837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (!ext->xres || !ext->yres) { 10303837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->xres = 640; 10313837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->yres = 480; 10323837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 10333837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 1034ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* 1035ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht * copy the xres/yres from the preferred mode 1036ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht */ 1037ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht __u32 preferred_mode_xres = 0; 1038ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht __u32 preferred_mode_yres = 0; 1039ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen 1040ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen char value[PROPERTY_VALUE_MAX]; 1041ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (property_get("persist.hwc.preferred_mode", value, "") <= 0 || 1042ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen sscanf(value, "%dx%d", &preferred_mode_xres, 1043ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen &preferred_mode_yres) != 2) { 1044ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen for (i = 0; i < d.dis.modedb_len; i++) { 1045ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (d.modedb[i].flag & FB_FLAG_PREFERRED) { 1046ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen preferred_mode_xres = d.modedb[i].xres; 1047ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen preferred_mode_yres = d.modedb[i].yres; 1048ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen ALOGD("preferred mode %d: xres %u yres %u\n", 1049ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen i, d.modedb[i].xres, d.modedb[i].yres); 1050ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen break; 1051ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen } 1052ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht } 1053ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen } else { 1054ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen ALOGD("forced preferred mode xres %u yres %u\n", 1055ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen preferred_mode_xres, preferred_mode_yres); 1056ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen forced_preferred_mode = 1; 1057ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht } 1058ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1059bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_fb_xres, ext_fb_yres; 1060bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar for (i = 0; i < d.dis.modedb_len; i++) { 1061bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 score = 0; 1062e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_xres = d.modedb[i].xres; 1063e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_yres = d.modedb[i].yres; 1064bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_width = d.dis.width_in_mm; 1065bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_height = d.dis.height_in_mm; 1066bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1067ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* reject it because the hw says it can't actually use this mode */ 1068ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht if ((d.modedb[i].flag & FB_FLAG_HW_CAPABLE) == 0) 1069ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht continue; 1070ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1071620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli if (d.modedb[i].vmode & FB_VMODE_INTERLACED) 1072620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli mode_yres /= 2; 1073620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli 1074bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (d.modedb[i].flag & FB_FLAG_RATIO_4_3) { 1075bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width = 4; 1076bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_height = 3; 1077bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } else if (d.modedb[i].flag & FB_FLAG_RATIO_16_9) { 1078bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width = 16; 1079bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_height = 9; 1080bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1081bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1082e14d52936107e390e2464df1e6653efde5409096Lajos Molnar if (!mode_xres || !mode_yres) 10836c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar continue; 10846c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar 1085e14d52936107e390e2464df1e6653efde5409096Lajos Molnar get_max_dimensions(xres, yres, xpy, mode_xres, mode_yres, 1086bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width, ext_height, &ext_fb_xres, &ext_fb_yres); 1087bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1088f4524c063d4cc4afeb19b08966f51b42257d3acdLajos Molnar /* we need to ensure that even TILER2D buffers can be scaled */ 10894ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar if (!d.modedb[i].pixclock || 1090620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli (d.modedb[i].vmode & ~FB_VMODE_INTERLACED) || 10914ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar !omap4_hwc_can_scale(xres, yres, ext_fb_xres, ext_fb_yres, 1092ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 1, &d.dis, &limits, 10934ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar 1000000000 / d.modedb[i].pixclock)) 1094bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar continue; 1095bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1096bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar /* prefer CEA modes */ 1097bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (d.modedb[i].flag & (FB_FLAG_RATIO_4_3 | FB_FLAG_RATIO_16_9)) 1098ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht score += 1; 1099ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1100ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* prefer modes that match the preferred mode's resolution */ 1101ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht if (d.modedb[i].xres == preferred_mode_xres && 1102ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht d.modedb[i].yres == preferred_mode_yres) { 1103ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (forced_preferred_mode) 1104ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen score += 10; 1105ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen else 1106ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen score += 1; 1107ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht } 1108ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1109ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* prefer modes the kernel has hinted is the correct mode */ 1110ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (!forced_preferred_mode && (d.modedb[i].flag & FB_FLAG_PREFERRED)) 1111ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht score += 1; 1112bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 11134e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar /* prefer the same mode as we use for mirroring to avoid mode change */ 1114ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen score = (score << 1) | (i == ~ext->mirror_mode && ext->avoid_mode_change); 1115bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1116e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = add_scaling_score(score, xres, yres, 60, ext_fb_xres, ext_fb_yres, 1117e14d52936107e390e2464df1e6653efde5409096Lajos Molnar mode_xres, mode_yres, d.modedb[i].refresh ? : 1); 1118bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1119876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGD("#%d: %dx%d %dHz flag 0x%x vmode 0x%x, score 0x%x", 1120876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen i, mode_xres, mode_yres, 1121876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen d.modedb[i].refresh, d.modedb[i].flag, d.modedb[i].vmode, 1122876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen score); 1123876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1124bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (debug) 11253a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD(" score=0x%x adj.res=%dx%d", score, ext_fb_xres, ext_fb_yres); 1126bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (best_score < score) { 1127ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->width = ext_width; 1128ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->height = ext_height; 1129e14d52936107e390e2464df1e6653efde5409096Lajos Molnar ext->xres = mode_xres; 1130e14d52936107e390e2464df1e6653efde5409096Lajos Molnar ext->yres = mode_yres; 1131bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar best = i; 1132bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar best_score = score; 1133bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1134bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1135bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (~best) { 11365db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket struct dsscomp_setup_display_data sdis = { .ix = dis_ix, }; 1137bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar sdis.mode = d.dis.modedb[best]; 11383a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("picking #%d", best); 11394cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar /* only reconfigure on change */ 11405142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen if (ext->last_mode != ~best) { 11415142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen /* set a property that apps that care (e.g. YouTube) can use 11425142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * to determine whether or not to stream lower resolution 11435142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * videos when the hdmi mode is < 1080p. 11445142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * otherwise, they'd give us 1080p and we'd just scale it 11455142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * down to the hdmi mode res. UI apps are always going 11465142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * to draw at 1080p and we'll scale down because the 11475142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * system can't support dynamic dpi changes. 11485142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen */ 11495142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen char display[PROPERTY_VALUE_MAX]; 11505142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen snprintf(display, sizeof(display), "%dx%d", 11515142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen d.modedb[best].xres, d.modedb[best].yres); 11525142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen ALOGD("setting property sys.display-size to %s", display); 11535142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen property_set("sys.display-size", display); 11545142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen 1155cb64c2be21ad9550b1f5d2b4a8361e997b9be757Lajos Molnar ioctl(hwc_dev->dsscomp_fd, DSSCIOC_SETUP_DISPLAY, &sdis); 11565142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen } 11574cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar ext->last_mode = ~best; 1158bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } else { 1159bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_width = d.dis.width_in_mm; 1160bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_height = d.dis.height_in_mm; 1161bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_fb_xres, ext_fb_yres; 1162bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 11631b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar get_max_dimensions(xres, yres, xpy, d.dis.timings.x_res, d.dis.timings.y_res, 1164bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width, ext_height, &ext_fb_xres, &ext_fb_yres); 11654ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar if (!d.dis.timings.pixel_clock || 11664ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar !omap4_hwc_can_scale(xres, yres, ext_fb_xres, ext_fb_yres, 1167ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 1, &d.dis, &limits, 11684ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar d.dis.timings.pixel_clock)) { 1169a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("DSS scaler cannot support HDMI cloning"); 1170bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar return -1; 1171bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1172bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1173ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->last_xres_used = xres; 1174ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->last_yres_used = yres; 11751b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->last_xpy = xpy; 1176bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (d.dis.channel == OMAP_DSS_CHANNEL_DIGIT) 1177ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->on_tv = 1; 1178bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar return 0; 1179bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar} 1180bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 11816ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void gather_layer_statistics(omap4_hwc_device_t *hwc_dev, struct counts *num, hwc_display_contents_1_t *list) 118244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar{ 118344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar unsigned int i; 118444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 118544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar /* Figure out how many layers we can support via DSS */ 118644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar for (i = 0; list && i < list->numHwLayers; i++) { 11876ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer = &list->hwLayers[i]; 118844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 118944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 119044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar layer->compositionType = HWC_FRAMEBUFFER; 119144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 119244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (omap4_hwc_is_valid_layer(hwc_dev, layer, handle)) { 119344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->possible_overlay_layers++; 119444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 119544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar /* NV12 layers can only be rendered on scaling overlays */ 1196876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (scaled(layer) || is_NV12(handle) || hwc_dev->primary_transform) 119744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->scaled_layers++; 119844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 119944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (is_BGR(handle)) 120044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->BGR++; 120144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar else if (is_RGB(handle)) 120244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->RGB++; 120344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar else if (is_NV12(handle)) 120444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->NV12++; 120544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 120644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (dockable(layer)) 120744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->dockable++; 120844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 120944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (is_protected(layer)) 121044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->protected++; 121144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 121244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->mem += mem1d(handle); 121344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 121444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 121558aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse hwc_dev->stats = *num; 121644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar} 121744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 121844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnarstatic void decide_supported_cloning(omap4_hwc_device_t *hwc_dev, struct counts *num) 121978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar{ 1220ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 122178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar int nonscaling_ovls = NUM_NONSCALING_OVERLAYS; 122278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays = MAX_HW_OVERLAYS; 122378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 122478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* 122578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * We cannot atomically switch overlays from one display to another. First, they 122678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * have to be disabled, and the disabling has to take effect on the current display. 122778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * We keep track of the available number of overlays here. 122878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar */ 12290aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (ext->dock.enabled && !(ext->mirror.enabled && !(num->dockable || ext->force_dock))) { 123078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* some overlays may already be used by the external display, so we account for this */ 123178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 123278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* reserve just a video pipeline for HDMI if docking */ 12330aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar hwc_dev->ext_ovls = (num->dockable || ext->force_dock) ? 1 : 0; 123478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays -= max(hwc_dev->ext_ovls, hwc_dev->last_ext_ovls); 12351b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar 12361b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar /* use mirroring transform if we are auto-switching to docking mode while mirroring*/ 12371b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar if (ext->mirror.enabled) { 12381b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->current = ext->mirror; 12391b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->current.docking = 1; 12401b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar } else { 12411b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->current = ext->dock; 12421b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar } 1243ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar } else if (ext->mirror.enabled) { 124478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* 124578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * otherwise, manage just from half the pipelines. NOTE: there is 124678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * no danger of having used too many overlays for external display here. 124778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar */ 12486d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket 124978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays >>= 1; 125078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar nonscaling_ovls >>= 1; 125178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = MAX_HW_OVERLAYS - num->max_hw_overlays; 1252ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->current = ext->mirror; 125378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } else { 125478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays -= hwc_dev->last_ext_ovls; 125578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = 0; 1256ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->current.enabled = 0; 125778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 125878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 125978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* 126078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * :TRICKY: We may not have enough overlays on the external display. We "reserve" them 126178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * here to figure out if mirroring is supported, but may not do mirroring for the first 126278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * frame while the overlays required for it are cleared. 126378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar */ 1264bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar hwc_dev->ext_ovls_wanted = hwc_dev->ext_ovls; 126578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = min(MAX_HW_OVERLAYS - hwc_dev->last_int_ovls, hwc_dev->ext_ovls); 126678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1267ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar /* if mirroring, we are limited by both internal and external overlays. However, 1268ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext_ovls is always <= MAX_HW_OVERLAYS / 2 <= max_hw_overlays */ 126958aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse if (!num->protected && hwc_dev->ext_ovls && ext->current.enabled && !ext->current.docking) 1270b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar num->max_hw_overlays = hwc_dev->ext_ovls; 127178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 12726d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket /* If FB is not same resolution as LCD don't use GFX pipe line*/ 1273876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->primary_transform) { 1274876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen num->max_hw_overlays -= NUM_NONSCALING_OVERLAYS; 12756d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket num->max_scaling_overlays = num->max_hw_overlays; 1276876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else 12775db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket num->max_scaling_overlays = num->max_hw_overlays - nonscaling_ovls; 127844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar} 127978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 128044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnarstatic int can_dss_render_all(omap4_hwc_device_t *hwc_dev, struct counts *num) 128144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar{ 128244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 12835db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket int on_tv = hwc_dev->on_tv || (ext->on_tv && ext->current.enabled); 128444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar int tform = ext->current.enabled && (ext->current.rotation || ext->current.hflip); 1285ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 12864b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar return !hwc_dev->force_sgx && 12874b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar /* must have at least one layer if using composition bypass to get sync object */ 128878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->possible_overlay_layers && 128978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->possible_overlay_layers <= num->max_hw_overlays && 129078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->possible_overlay_layers == num->composited_layers && 129178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->scaled_layers <= num->max_scaling_overlays && 12924af5978e0677b13118611721f265e2dbaba849ffLajos Molnar num->NV12 <= num->max_scaling_overlays && 129338934f125a600817dded7aeba9639c6a75afe358Lajos Molnar /* fits into TILER slot */ 1294876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen num->mem <= limits.tiler1d_slot_size && 129578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* we cannot clone non-NV12 transformed layers */ 12965a87355f6a7ed393d5d8f71bf7aac5f65b87c640Muralidhar Dixit (!tform || (num->NV12 == num->possible_overlay_layers) || 12975a87355f6a7ed393d5d8f71bf7aac5f65b87c640Muralidhar Dixit (num->NV12 && ext->current.docking)) && 129878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* HDMI cannot display BGR */ 1299ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar (num->BGR == 0 || (num->RGB == 0 && !on_tv) || !hwc_dev->flags_rgb_order); 130078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar} 130178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 130278fce72baff38f488a0117591d4241d278a48b1bLajos Molnarstatic inline int can_dss_render_layer(omap4_hwc_device_t *hwc_dev, 13036ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer) 130478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar{ 130578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 130678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 130744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 1308876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int cloning = ext->current.enabled && (!ext->current.docking || (handle!=NULL ? dockable(layer) : 0)); 1309876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int on_tv = hwc_dev->on_tv || (ext->on_tv && cloning); 1310876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int tform = cloning && (ext->current.rotation || ext->current.hflip); 131178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1312d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return omap4_hwc_is_valid_layer(hwc_dev, layer, handle) && 13132952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* cannot rotate non-NV12 layers on external display */ 13145706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar (!tform || is_NV12(handle)) && 131578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* skip non-NV12 layers if also using SGX (if nv12_only flag is set) */ 13165706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar (!hwc_dev->flags_nv12_only || (!hwc_dev->use_sgx || is_NV12(handle))) && 131778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* make sure RGB ordering is consistent (if rgb_order flag is set) */ 13185706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar (!(hwc_dev->swap_rb ? is_RGB(handle) : is_BGR(handle)) || 131978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar !hwc_dev->flags_rgb_order) && 132078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* TV can only render RGB */ 13215706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar !(on_tv && is_BGR(handle)); 132278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar} 132378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1324834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnarstatic inline int display_area(struct dss2_ovl_info *o) 1325834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar{ 1326834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar return o->cfg.win.w * o->cfg.win.h; 1327834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar} 1328834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 13293837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnarstatic int clone_layer(omap4_hwc_device_t *hwc_dev, int ix) { 1330876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 13313837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 13323837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar int ext_ovl_ix = dsscomp->num_ovls - hwc_dev->post2_layers; 13333837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar struct dss2_ovl_info *o = &dsscomp->ovls[dsscomp->num_ovls]; 13343837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13353837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (dsscomp->num_ovls >= MAX_HW_OVERLAYS) { 133646de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** cannot clone layer #%d. using all %d overlays.", ix, dsscomp->num_ovls); 13373837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return -EBUSY; 13383837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 13393837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13403837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar memcpy(o, dsscomp->ovls + ix, sizeof(*o)); 13413837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13423837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* reserve overlays at end for other display */ 13433837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar o->cfg.ix = MAX_HW_OVERLAYS - 1 - ext_ovl_ix; 13443837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar o->cfg.mgr_ix = 1; 134583f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* 134683f80658d865b741a024515c523e373df50c091eSunita Nadampalli * Here the assumption is that overlay0 is the one attached to FB. 134783f80658d865b741a024515c523e373df50c091eSunita Nadampalli * Hence this clone_layer call is for FB cloning (provided use_sgx is true). 134883f80658d865b741a024515c523e373df50c091eSunita Nadampalli */ 134983f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* For the external displays whose transform is the same as 135083f80658d865b741a024515c523e373df50c091eSunita Nadampalli * that of primary display, ion_handles would be NULL hence 135183f80658d865b741a024515c523e373df50c091eSunita Nadampalli * the below logic doesn't execute. 135283f80658d865b741a024515c523e373df50c091eSunita Nadampalli */ 135383f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ix == 0 && hwc_dev->ion_handles[sync_id%2] && hwc_dev->use_sgx) { 135483f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->addressing = OMAP_DSS_BUFADDR_ION; 135583f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->ba = (int)hwc_dev->ion_handles[sync_id%2]; 135683f80658d865b741a024515c523e373df50c091eSunita Nadampalli } else { 135783f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->addressing = OMAP_DSS_BUFADDR_OVL_IX; 135883f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->ba = ix; 135983f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 13603837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13613837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* use distinct z values (to simplify z-order checking) */ 13623837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar o->cfg.zorder += hwc_dev->post2_layers; 13633837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13643837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_adjust_ext_layer(&hwc_dev->ext, o); 13653837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar dsscomp->num_ovls++; 13663837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return 0; 13673837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar} 13683837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13693837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnarstatic int clone_external_layer(omap4_hwc_device_t *hwc_dev, int ix) { 1370876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 13713837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 13723837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13733837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* mirror only 1 external layer */ 13743837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar struct dss2_ovl_info *o = &dsscomp->ovls[ix]; 13753837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13763837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* full screen video after transformation */ 13773837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar __u32 xres = o->cfg.crop.w, yres = o->cfg.crop.h; 13783837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if ((ext->current.rotation + o->cfg.rotation) & 1) 13793837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar swap(xres, yres); 13803837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar float xpy = ext->lcd_xpy * o->cfg.win.w / o->cfg.win.h; 13813837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (o->cfg.rotation & 1) 13823837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy = o->cfg.crop.h / xpy / o->cfg.crop.w; 13833837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar else 13843837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy = o->cfg.crop.h * xpy / o->cfg.crop.w; 13853837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.rotation & 1) 13863837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy = 1. / xpy; 13873837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13883837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* adjust hdmi mode based on resolution */ 13893837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (xres != ext->last_xres_used || 13903837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar yres != ext->last_yres_used || 13913837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy < ext->last_xpy * (1.f - ASPECT_RATIO_TOLERANCE) || 13923837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy * (1.f - ASPECT_RATIO_TOLERANCE) > ext->last_xpy) { 13933a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("set up HDMI for %d*%d\n", xres, yres); 13943837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (omap4_hwc_set_best_hdmi_mode(hwc_dev, xres, yres, xpy)) { 13953837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->current.enabled = 0; 13963837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return -ENODEV; 13973837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 13983837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 13993837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14003837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar struct hwc_rect region = { 14013837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar .left = o->cfg.win.x, .top = o->cfg.win.y, 14023837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar .right = o->cfg.win.x + o->cfg.win.w, 14033837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar .bottom = o->cfg.win.y + o->cfg.win.h 14043837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar }; 14053837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar set_ext_matrix(&hwc_dev->ext, region); 14063837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14073837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return clone_layer(hwc_dev, ix); 14083837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar} 14093837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14103837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnarstatic int setup_mirroring(omap4_hwc_device_t *hwc_dev) 14113837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar{ 14123837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 14133837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14143837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar __u32 xres = WIDTH(ext->mirror_region); 14153837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar __u32 yres = HEIGHT(ext->mirror_region); 14163837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.rotation & 1) 14173837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar swap(xres, yres); 14183837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (omap4_hwc_set_best_hdmi_mode(hwc_dev, xres, yres, ext->lcd_xpy)) 14193837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return -ENODEV; 14203837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar set_ext_matrix(ext, ext->mirror_region); 14213837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return 0; 14223837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar} 14233837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14246ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden/* 14256ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden * We're using "implicit" synchronization, so make sure we aren't passing any 14266ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden * sync object descriptors around. 14276ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden */ 14286ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void check_sync_fds(size_t numDisplays, hwc_display_contents_1_t** displays) 14296ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden{ 14306ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden //ALOGD("checking sync FDs"); 14316ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden unsigned int i, j; 14326ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden for (i = 0; i < numDisplays; i++) { 14336ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t* list = displays[i]; 14343d6b69f0a0fb325443ef8c2987c16af1f8618d3eJesse Hall if (list->retireFenceFd >= 0) { 14353d6b69f0a0fb325443ef8c2987c16af1f8618d3eJesse Hall ALOGW("retireFenceFd[%u] was %d", i, list->retireFenceFd); 14363d6b69f0a0fb325443ef8c2987c16af1f8618d3eJesse Hall list->retireFenceFd = -1; 14376ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14386ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 14396ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden for (j = 0; j < list->numHwLayers; j++) { 14406ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t* layer = &list->hwLayers[j]; 14416ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (layer->acquireFenceFd >= 0) { 14426ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden ALOGW("acquireFenceFd[%u][%u] was %d, closing", i, j, layer->acquireFenceFd); 14436ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden close(layer->acquireFenceFd); 14446ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden layer->acquireFenceFd = -1; 14456ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14466ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (layer->releaseFenceFd >= 0) { 14476ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden ALOGW("releaseFenceFd[%u][%u] was %d", i, j, layer->releaseFenceFd); 14486ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden layer->releaseFenceFd = -1; 14496ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14506ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14516ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14526ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden} 14536ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 1454fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht/* test if layer appears to be RGB32 (4 Bpp) and > 1280x720 */ 1455fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrechtstatic int is_large_rgb32_layer(const hwc_layer_1_t *layer) 1456fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht{ 1457fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 1458fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht 1459fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht return is_RGB32(handle) && 1460fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht (((layer->sourceCrop.right - layer->sourceCrop.left) > 1280) || 1461fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht ((layer->sourceCrop.bottom - layer->sourceCrop.top) > 720)); 1462fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht} 1463fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht 1464876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic void blit_reset(omap4_hwc_device_t *hwc_dev, int flags) 1465876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 1466876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_flags = 0; 1467876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_num = 0; 1468876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->post2_blit_buffers = 0; 1469876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->comp_data.blit_data.rgz_items = 0; 1470876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1471876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* We want to maintain the rgz dirty region data if there are no geometry changes */ 1472876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (flags & HWC_GEOMETRY_CHANGED) 1473876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_release(&grgz); 1474876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen} 1475876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1476876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic int blit_layers(omap4_hwc_device_t *hwc_dev, hwc_layer_list_t *list, int bufoff) 1477876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 1478876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Do not blit if this frame will be composed entirely by the GPU */ 1479876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!list || hwc_dev->force_sgx) 1480876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1481876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1482876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int rgz_in_op; 1483876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int rgz_out_op; 1484876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1485876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen switch (hwc_dev->blt_mode) { 1486876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen case BLTMODE_PAINT: 1487876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_in_op = RGZ_IN_HWCCHK; 1488876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_out_op = RGZ_OUT_BVCMD_PAINT; 1489876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen break; 1490876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen case BLTMODE_REGION: 1491876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen default: 1492876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_in_op = RGZ_IN_HWC; 1493876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_out_op = RGZ_OUT_BVCMD_REGION; 1494876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen break; 1495876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1496876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1497876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_in_params_t in = { 1498876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .op = rgz_in_op, 1499876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .data = { 1500876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .hwc = { 1501876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .dstgeom = &gscrngeom, 1502876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .layers = list->hwLayers, 1503876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .layerno = list->numHwLayers 1504876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1505876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1506876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen }; 1507876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1508876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* 1509876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * This means if all the layers marked for the FRAMEBUFFER cannot be 1510876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * blitted, do not blit, for e.g. SKIP layers 1511876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1512876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_in(&in, &grgz) != RGZ_ALL) 1513876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1514876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1515876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int i, count = 0; 1516876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < list->numHwLayers; i++) { 1517876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (list->hwLayers[i].compositionType != HWC_OVERLAY) { 1518876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen count++; 1519876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1520876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1521876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1522876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_out_params_t out = { 1523876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .op = rgz_out_op, 1524876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .data = { 1525876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .bvc = { 1526876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .dstgeom = &gscrngeom, 1527876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .noblend = 0, 1528876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1529876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1530876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen }; 1531876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1532876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_out(&grgz, &out) != 0) { 1533876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("Failed generating blits"); 1534876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1535876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1536876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1537876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* This is a special situation where the regionizer decided no blits are 1538876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * needed for this frame but there are blit buffers to synchronize with. Can 1539876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * happen only if the regionizer is enabled otherwise it's likely a bug 1540876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1541876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_out_op != RGZ_OUT_BVCMD_REGION && out.data.bvc.out_blits == 0 && out.data.bvc.out_nhndls > 0) { 1542876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("Regionizer invalid output blit_num %d, post2_blit_buffers %d", out.data.bvc.out_blits, out.data.bvc.out_nhndls); 1543876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1544876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1545876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1546876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_flags |= HWC_BLT_FLAG_USE_FB; 1547876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_num = out.data.bvc.out_blits; 1548876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->post2_blit_buffers = out.data.bvc.out_nhndls; 1549876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < hwc_dev->post2_blit_buffers; i++) { 1550876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen //ALOGI("blit buffers[%d] = %p", bufoff, out.data.bvc.out_hndls[i]); 1551876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers[bufoff++] = out.data.bvc.out_hndls[i]; 1552876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1553876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1554876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct rgz_blt_entry *res_blit_ops = (struct rgz_blt_entry *) out.data.bvc.cmdp; 1555876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen memcpy(hwc_dev->comp_data.blit_data.rgz_blts, res_blit_ops, sizeof(*res_blit_ops) * out.data.bvc.cmdlen); 1556876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI_IF(debugblt, "blt struct sz %d", sizeof(*res_blit_ops) * out.data.bvc.cmdlen); 1557876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE_IF(hwc_dev->blit_num != out.data.bvc.cmdlen,"blit_num != out.data.bvc.cmdlen, %d != %d", hwc_dev->blit_num, out.data.bvc.cmdlen); 1558876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1559876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* all layers will be rendered without SGX help either via DSS or blitter */ 1560876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < list->numHwLayers; i++) { 1561876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (list->hwLayers[i].compositionType != HWC_OVERLAY) { 1562876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen list->hwLayers[i].compositionType = HWC_OVERLAY; 1563876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen //ALOGI("blitting layer %d", i); 1564a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse list->hwLayers[i].hints &= ~HWC_HINT_TRIPLE_BUFFER; 1565876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1566876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen list->hwLayers[i].hints &= ~HWC_HINT_CLEAR_FB; 1567876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1568876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return 1; 1569876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1570876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenerr_out: 1571876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_release(&grgz); 1572876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return 0; 1573876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen} 1574876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1575876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenvoid debug_post2(omap4_hwc_device_t *hwc_dev, int nbufs) 1576876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 1577876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!debugpost2) 1578876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return; 1579876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 1580876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int i; 1581876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i=0; i<nbufs; i++) { 1582876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("buf[%d] hndl %p", i, hwc_dev->buffers[i]); 1583876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1584876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i=0; i < dsscomp->num_ovls; i++) { 1585876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("ovl[%d] ba %d", i, dsscomp->ovls[i].ba); 1586876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1587876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen} 1588876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 158983f80658d865b741a024515c523e373df50c091eSunita Nadampallistatic int free_tiler2d_buffers(omap4_hwc_device_t *hwc_dev) 159083f80658d865b741a024515c523e373df50c091eSunita Nadampalli{ 159183f80658d865b741a024515c523e373df50c091eSunita Nadampalli int i; 159283f80658d865b741a024515c523e373df50c091eSunita Nadampalli 159383f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0 ; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 159483f80658d865b741a024515c523e373df50c091eSunita Nadampalli ion_free(hwc_dev->ion_fd, hwc_dev->ion_handles[i]); 159583f80658d865b741a024515c523e373df50c091eSunita Nadampalli hwc_dev->ion_handles[i] = NULL; 159683f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 159783f80658d865b741a024515c523e373df50c091eSunita Nadampalli return 0; 159883f80658d865b741a024515c523e373df50c091eSunita Nadampalli} 159983f80658d865b741a024515c523e373df50c091eSunita Nadampalli 160083f80658d865b741a024515c523e373df50c091eSunita Nadampallistatic int allocate_tiler2d_buffers(omap4_hwc_device_t *hwc_dev) 160183f80658d865b741a024515c523e373df50c091eSunita Nadampalli{ 160283f80658d865b741a024515c523e373df50c091eSunita Nadampalli int ret, i; 160383f80658d865b741a024515c523e373df50c091eSunita Nadampalli size_t stride; 160483f80658d865b741a024515c523e373df50c091eSunita Nadampalli 160583f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_fd < 0) { 160683f80658d865b741a024515c523e373df50c091eSunita Nadampalli ALOGE("No ion fd, hence can't allocate tiler2d buffers"); 160783f80658d865b741a024515c523e373df50c091eSunita Nadampalli return -1; 160883f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 160983f80658d865b741a024515c523e373df50c091eSunita Nadampalli 161083f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 161183f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_handles[i]) 161283f80658d865b741a024515c523e373df50c091eSunita Nadampalli return 0; 161383f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 161483f80658d865b741a024515c523e373df50c091eSunita Nadampalli 161583f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0 ; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 161683f80658d865b741a024515c523e373df50c091eSunita Nadampalli ret = ion_alloc_tiler(hwc_dev->ion_fd, hwc_dev->fb_dev->base.width, hwc_dev->fb_dev->base.height, 161783f80658d865b741a024515c523e373df50c091eSunita Nadampalli TILER_PIXEL_FMT_32BIT, 0, &hwc_dev->ion_handles[i], &stride); 161883f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ret) 161983f80658d865b741a024515c523e373df50c091eSunita Nadampalli goto handle_error; 162083f80658d865b741a024515c523e373df50c091eSunita Nadampalli 162183f80658d865b741a024515c523e373df50c091eSunita Nadampalli ALOGI("ion handle[%d][%p]", i, hwc_dev->ion_handles[i]); 162283f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 162383f80658d865b741a024515c523e373df50c091eSunita Nadampalli return 0; 162483f80658d865b741a024515c523e373df50c091eSunita Nadampalli 162583f80658d865b741a024515c523e373df50c091eSunita Nadampallihandle_error: 162683f80658d865b741a024515c523e373df50c091eSunita Nadampalli free_tiler2d_buffers(hwc_dev); 162783f80658d865b741a024515c523e373df50c091eSunita Nadampalli return -1; 162883f80658d865b741a024515c523e373df50c091eSunita Nadampalli} 162983f80658d865b741a024515c523e373df50c091eSunita Nadampalli 16306ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_prepare(struct hwc_composer_device_1 *dev, size_t numDisplays, 16316ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t** displays) 1632c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 16336ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (!numDisplays || displays == NULL) { 16346ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden return 0; 16356ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 16366ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 16376ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t* list = displays[0]; // ignore displays beyond the first 1638c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *)dev; 1639876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 16400b62b7ca3c6430caaebb2d3815642b2ff80f527aLajos Molnar struct counts num = { .composited_layers = list ? list->numHwLayers : 0 }; 16413837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar unsigned int i, ix; 1642c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 16432125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_lock(&hwc_dev->lock); 1644c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev memset(dsscomp, 0x0, sizeof(*dsscomp)); 1645c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev dsscomp->sync_id = sync_id++; 1646c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 164744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar gather_layer_statistics(hwc_dev, &num, list); 1648834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 164944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar decide_supported_cloning(hwc_dev, &num); 1650c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 16514b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar /* Disable the forced SGX rendering if there is only one layer */ 16524b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar if (hwc_dev->force_sgx && num.composited_layers <= 1) 16534b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar hwc_dev->force_sgx = 0; 16544b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar 165578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* phase 3 logic */ 16564b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar if (can_dss_render_all(hwc_dev, &num)) { 1657c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* All layers can be handled by the DSS -- don't use SGX for composition */ 1658c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->use_sgx = 0; 165978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->swap_rb = num.BGR != 0; 1660c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } else { 1661c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Use SGX for composition plus first 3 layers that are DSS renderable */ 1662c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->use_sgx = 1; 16635706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar hwc_dev->swap_rb = is_BGR_format(hwc_dev->fb_dev->base.format); 1664c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1665c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1666c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* setup pipes */ 1667c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int z = 0; 1668a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar int fb_z = -1; 1669c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int scaled_gfx = 0; 1670834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar int ix_docking = -1; 1671fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht int big_layers = 0; 1672c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1673876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int blit_all = 0; 16742acde915b4868129963ef7dc7afe1f3b35ffeeacJon Pry blit_reset(hwc_dev, list ? list->flags : 0); 1675876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1676876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* If the SGX is used or we are going to blit something we need a framebuffer 1677876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * and a DSS pipe 1678876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1679876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int needs_fb = hwc_dev->use_sgx; 1680876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1681876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->blt_policy == BLTPOLICY_ALL) { 1682876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Check if we can blit everything */ 1683876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen blit_all = blit_layers(hwc_dev, list, 0); 1684876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (blit_all) { 1685876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen needs_fb = 1; 1686876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->use_sgx = 0; 1687876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1688876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1689876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1690876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* If a framebuffer is needed, begin using VID1 for DSS overlay layers, 1691876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * we need GFX for FB 1692876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1693876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->num_ovls = needs_fb ? 1 /*VID1*/ : 0 /*GFX*/; 1694876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1695c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* set up if DSS layers */ 169638934f125a600817dded7aeba9639c6a75afe358Lajos Molnar unsigned int mem_used = 0; 1697876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; list && i < list->numHwLayers && !blit_all; i++) { 16986ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer = &list->hwLayers[i]; 1699c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 1700c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 17014b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar if (dsscomp->num_ovls < num.max_hw_overlays && 1702a1be32cc5c3978f9bac62c3b40a257bba2315861Lajos Molnar can_dss_render_layer(hwc_dev, layer) && 17034b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar (!hwc_dev->force_sgx || 17044b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar /* render protected and dockable layers via DSS */ 17055706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar is_protected(layer) || 1706f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar is_upscaled_NV12(hwc_dev, layer) || 17074b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar (hwc_dev->ext.current.docking && hwc_dev->ext.current.enabled && dockable(layer))) && 1708876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen mem_used + mem1d(handle) < limits.tiler1d_slot_size && 1709c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* can't have a transparent overlay in the middle of the framebuffer stack */ 1710fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht !(is_BLENDED(layer) && fb_z >= 0) && 1711fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht /* current hardware is unable to keep up with more than 1 'large' RGB32 layer */ 1712fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht !(is_large_rgb32_layer(layer) && big_layers > 0)) { 17135706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 1714c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* render via DSS overlay */ 171538934f125a600817dded7aeba9639c6a75afe358Lajos Molnar mem_used += mem1d(handle); 1716c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev layer->compositionType = HWC_OVERLAY; 1717a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse /* 1718a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse * This hint will not be used in vanilla ICS, but maybe in 1719a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse * JellyBean, it is useful to distinguish between blts and true 1720a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse * overlays 1721a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse */ 1722a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse layer->hints |= HWC_HINT_TRIPLE_BUFFER; 1723b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar 1724b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar /* clear FB above all opaque layers if rendering via SGX */ 1725b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar if (hwc_dev->use_sgx && !is_BLENDED(layer)) 1726b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar layer->hints |= HWC_HINT_CLEAR_FB; 1727b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar 1728e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar hwc_dev->buffers[dsscomp->num_ovls] = layer->handle; 1729c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1730c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_setup_layer(hwc_dev, 1731c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev &dsscomp->ovls[dsscomp->num_ovls], 1732f1e357b2cf26fa5a50789061e068e4f0bd4ea772Mathias Agopian layer, 1733c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev z, 1734c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev handle->iFormat, 1735c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev handle->iWidth, 1736c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev handle->iHeight); 1737d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 1738876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[dsscomp->num_ovls].cfg.ix = dsscomp->num_ovls + hwc_dev->primary_transform; 173912c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[dsscomp->num_ovls].addressing = OMAP_DSS_BUFADDR_LAYER_IX; 174012c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[dsscomp->num_ovls].ba = dsscomp->num_ovls; 1741c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1742c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* ensure GFX layer is never scaled */ 1743876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if ((dsscomp->num_ovls == 0) && (!hwc_dev->primary_transform)) { 1744876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen scaled_gfx = scaled(layer) || is_NV12(handle); 1745876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else if (scaled_gfx && !scaled(layer) && !is_NV12(handle)) { 1746c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* swap GFX layer with this one */ 1747c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev dsscomp->ovls[dsscomp->num_ovls].cfg.ix = 0; 1748876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[0].cfg.ix = dsscomp->num_ovls; 1749c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev scaled_gfx = 0; 1750c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1751c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1752834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar /* remember largest dockable layer */ 1753834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar if (dockable(layer) && 1754834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar (ix_docking < 0 || 175500d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar display_area(&dsscomp->ovls[dsscomp->num_ovls]) > display_area(&dsscomp->ovls[ix_docking]))) 1756834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar ix_docking = dsscomp->num_ovls; 175778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1758c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev dsscomp->num_ovls++; 1759c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev z++; 1760fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht 1761fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht /* record whether or not this was a 'big' RGB32 layer */ 1762fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht if (is_large_rgb32_layer(layer)) { 1763fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht big_layers++; 1764fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht } 1765c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } else if (hwc_dev->use_sgx) { 1766c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (fb_z < 0) { 1767c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* NOTE: we are not handling transparent cutout for now */ 1768a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar fb_z = z; 1769c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev z++; 1770c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } else { 1771c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* move fb z-order up (by lowering dss layers) */ 1772a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar while (fb_z < z - 1) 1773a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar dsscomp->ovls[1 + fb_z++].cfg.zorder--; 1774c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1775c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1776c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1777c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1778c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* if scaling GFX (e.g. only 1 scaled surface) use a VID pipe */ 1779c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (scaled_gfx) 1780876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[0].cfg.ix = dsscomp->num_ovls; 1781876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1782876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->blt_policy == BLTPOLICY_DEFAULT) { 1783876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->use_sgx) { 1784876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (blit_layers(hwc_dev, list, dsscomp->num_ovls == 1 ? 0 : dsscomp->num_ovls)) { 1785876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->use_sgx = 0; 1786876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1787876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1788876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1789c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1790876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* If the SGX is not used and there is blit data we need a framebuffer and 1791876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * a DSS pipe well configured for it 1792876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1793876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (needs_fb) { 1794b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar /* assign a z-layer for fb */ 1795449e98a958753e6ae8f16b923596af0c6783ff8aLajos Molnar if (fb_z < 0) { 1796876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!hwc_dev->blt_policy != BLTPOLICY_DISABLED && num.composited_layers) 17976d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket ALOGE("**** should have assigned z-layer for fb"); 1798449e98a958753e6ae8f16b923596af0c6783ff8aLajos Molnar fb_z = z++; 1799449e98a958753e6ae8f16b923596af0c6783ff8aLajos Molnar } 1800876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* 1801876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * This is needed because if we blit all we would lose the handle of 1802876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * the first layer 1803876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1804876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->blit_num == 0) { 1805876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers[0] = NULL; 1806876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1807c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_setup_layer_base(&dsscomp->ovls[0].cfg, fb_z, 1808c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev->base.format, 18095706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 1, /* FB is always premultiplied */ 1810c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev->base.width, 1811c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev->base.height); 1812c35f8ef2dc4bf1606f2b27f750057b12e51cb99aErik Gilling dsscomp->ovls[0].cfg.pre_mult_alpha = 1; 181312c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[0].addressing = OMAP_DSS_BUFADDR_LAYER_IX; 181412c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[0].ba = 0; 1815876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[0].cfg.ix = hwc_dev->primary_transform; 1816c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1817c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 181878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* mirror layers */ 181978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->post2_layers = dsscomp->num_ovls; 18203837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 18213837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 18223837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.enabled && hwc_dev->ext_ovls) { 18233837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.docking && ix_docking >= 0) { 1824876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (clone_external_layer(hwc_dev, ix_docking) == 0) 182512c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[dsscomp->num_ovls - 1].cfg.zorder = z++; 18260aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } else if (ext->current.docking && ix_docking < 0 && ext->force_dock) { 18270aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar ix_docking = dsscomp->num_ovls; 18280aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar struct dss2_ovl_info *oi = &dsscomp->ovls[ix_docking]; 18290aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar omap4_hwc_setup_layer_base(&oi->cfg, 0, HAL_PIXEL_FORMAT_BGRA_8888, 1, 18300aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar dock_image.width, dock_image.height); 18310aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar oi->cfg.stride = dock_image.rowbytes; 18320aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (clone_external_layer(hwc_dev, ix_docking) == 0) { 18330aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar oi->addressing = OMAP_DSS_BUFADDR_FB; 18340aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar oi->ba = 0; 18350aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar z++; 18360aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 18373837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } else if (!ext->current.docking) { 18383837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar int res = 0; 1839834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 1840834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar /* reset mode if we are coming from docking */ 18413837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->last.docking) 18423837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar res = setup_mirroring(hwc_dev); 1843c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 18443837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* mirror all layers */ 18453837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar for (ix = 0; res == 0 && ix < hwc_dev->post2_layers; ix++) { 18463837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (clone_layer(hwc_dev, ix)) 18473837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar break; 18483837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar z++; 18492952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar } 185078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 185178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 1852876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1853876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Apply transform for primary display */ 1854876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->primary_transform) 1855876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < dsscomp->num_ovls; i++) { 1856876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if(dsscomp->ovls[i].cfg.mgr_ix == 0) 1857876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen omap4_hwc_adjust_primary_display_layer(hwc_dev, &dsscomp->ovls[i]); 1858876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1859876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 18603837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->last = ext->current; 186178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 186278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar if (z != dsscomp->num_ovls || dsscomp->num_ovls > MAX_HW_OVERLAYS) 186346de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** used %d z-layers for %d overlays\n", z, dsscomp->num_ovls); 186478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 186544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar /* verify all z-orders and overlay indices are distinct */ 186644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar for (i = z = ix = 0; i < dsscomp->num_ovls; i++) { 186744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar struct dss2_ovl_cfg *c = &dsscomp->ovls[i].cfg; 186844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 186944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (z & (1 << c->zorder)) 187046de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** used z-order #%d multiple times", c->zorder); 187144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (ix & (1 << c->ix)) 187246de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** used ovl index #%d multiple times", c->ix); 187344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar z |= 1 << c->zorder; 187444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ix |= 1 << c->ix; 187544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 187678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mode = DSSCOMP_SETUP_DISPLAY; 187778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[0].ix = 0; 187878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[0].alpha_blending = 1; 187978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[0].swap_rb = hwc_dev->swap_rb; 188078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->num_mgrs = 1; 188178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 18823837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.enabled || hwc_dev->last_ext_ovls) { 188378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[1] = dsscomp->mgrs[0]; 188478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[1].ix = 1; 188578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->num_mgrs++; 188678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = dsscomp->num_ovls - hwc_dev->post2_layers; 188778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 188844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 188944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (debug) { 18903a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("prepare (%d) - %s (comp=%d, poss=%d/%d scaled, RGB=%d,BGR=%d,NV12=%d) (ext=%s%s%ddeg%s %dex/%dmx (last %dex,%din)\n", 189144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar dsscomp->sync_id, 189244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar hwc_dev->use_sgx ? "SGX+OVL" : "all-OVL", 189344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num.composited_layers, 189444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num.possible_overlay_layers, num.scaled_layers, 189544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num.RGB, num.BGR, num.NV12, 189644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->on_tv ? "tv+" : "", 189744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->current.enabled ? ext->current.docking ? "dock+" : "mirror+" : "OFF+", 189844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->current.rotation * 90, 189944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->current.hflip ? "+hflip" : "", 190044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar hwc_dev->ext_ovls, num.max_hw_overlays, hwc_dev->last_ext_ovls, hwc_dev->last_int_ovls); 190144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 190244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 19032125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_unlock(&hwc_dev->lock); 1904c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 1905c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 1906c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 190724a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnarstatic void omap4_hwc_reset_screen(omap4_hwc_device_t *hwc_dev) 190824a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar{ 190924a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar static int first_set = 1; 191024a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar int ret; 191124a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 191224a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (first_set) { 191324a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar first_set = 0; 191424a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar struct dsscomp_setup_dispc_data d = { 1915b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar .num_mgrs = 1, 191624a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar }; 191724a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar /* remove bootloader image from the screen as blank/unblank does not change the composition */ 1918cb64c2be21ad9550b1f5d2b4a8361e997b9be757Lajos Molnar ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_SETUP_DISPC, &d); 191924a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (ret) 1920a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("failed to remove bootloader image"); 192124a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 192224a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar /* blank and unblank fd to make sure display is properly programmed on boot. 192324a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar * This is needed because the bootloader can not be trusted. 192424a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar */ 192524a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar ret = ioctl(hwc_dev->fb_fd, FBIOBLANK, FB_BLANK_POWERDOWN); 192624a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (ret) 1927a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("failed to blank display"); 192824a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 192924a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar ret = ioctl(hwc_dev->fb_fd, FBIOBLANK, FB_BLANK_UNBLANK); 193024a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (ret) 1931a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("failed to blank display"); 193224a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar } 193324a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar} 193424a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 19356ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_set(struct hwc_composer_device_1 *dev, 19366ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden size_t numDisplays, hwc_display_contents_1_t** displays) 1937c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 19386ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (!numDisplays || displays == NULL) { 19396ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden ALOGD("set: empty display list"); 19406ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden return 0; 19416ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 19426ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_t dpy = NULL; 19436ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_surface_t sur = NULL; 19446ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t* list = displays[0]; // ignore displays beyond the first 19456ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (list != NULL) { 19466ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden dpy = list->dpy; 19476ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden sur = list->sur; 19486ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 1949c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *)dev; 1950876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 1951ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar int err = 0; 1952bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar int invalidate; 1953c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 19542125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_lock(&hwc_dev->lock); 195524a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 195627843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht /* disable resetting the screen on the first boot for devices 195727843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht * with hdmi as primary input. 195827843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht */ 195927843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht if (!hwc_dev->on_tv) 196027843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht omap4_hwc_reset_screen(hwc_dev); 196124a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 196258aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse invalidate = hwc_dev->ext_ovls_wanted && (hwc_dev->ext_ovls < hwc_dev->ext_ovls_wanted) && 196358aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse (hwc_dev->stats.protected || !hwc_dev->ext_ovls); 1964bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar 1965734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (debug) 1966734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_set_info(hwc_dev, list); 1967c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1968ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar if (dpy && sur) { 1969e37a11c21bcac1fbcac995cd34884eac37492b95Mathias Agopian // list can be NULL which means hwc is temporarily disabled. 1970e37a11c21bcac1fbcac995cd34884eac37492b95Mathias Agopian // however, if dpy and sur are null it means we're turning the 1971e37a11c21bcac1fbcac995cd34884eac37492b95Mathias Agopian // screen off. no shall not call eglSwapBuffers() in that case. 1972ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar 1973ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar if (hwc_dev->use_sgx) { 1974ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar if (!eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur)) { 197546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("eglSwapBuffers error"); 1976ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar err = HWC_EGL_ERROR; 1977ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar goto err_out; 1978ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar } 1979c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1980c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1981ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar //dump_dsscomp(dsscomp); 1982c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 198302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian // signal the event thread that a post has happened 1984751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen wakeup_hdmi_thread(hwc_dev); 198502150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (hwc_dev->force_sgx > 0) 198602150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian hwc_dev->force_sgx--; 198702150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 1988876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->comp_data.blit_data.rgz_flags = hwc_dev->blit_flags; 1989876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->comp_data.blit_data.rgz_items = hwc_dev->blit_num; 1990876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int omaplfb_comp_data_sz = sizeof(hwc_dev->comp_data) + 1991876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen (hwc_dev->comp_data.blit_data.rgz_items * sizeof(struct rgz_blt_entry)); 1992876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1993876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1994876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int nbufs = hwc_dev->post2_layers; 1995876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_blit_buffers) { 1996876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* 1997876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * We don't want to pass a NULL entry in the Post2, but we need to 1998876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * fix up buffer handle array and overlay indexes to account for 1999876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * this 2000876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 2001876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen nbufs += hwc_dev->post2_blit_buffers - 1; 2002876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2003876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_layers > 1) { 2004876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int i, j; 2005876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < nbufs; i++) { 2006876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers[i] = hwc_dev->buffers[i+1]; 2007876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2008876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 1, j= 1; j < hwc_dev->post2_layers; i++, j++) { 2009876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[j].ba = i; 2010876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2011876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2012876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2013876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI_IF(debugblt && hwc_dev->blt_policy != BLTPOLICY_DISABLED, 2014876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen "Post2, blits %d, ovl_buffers %d, blit_buffers %d sgx %d", 2015876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_num, hwc_dev->post2_layers, hwc_dev->post2_blit_buffers, 2016876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->use_sgx); 2017876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2018876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen debug_post2(hwc_dev, nbufs); 2019ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar err = hwc_dev->fb_dev->Post2((framebuffer_device_t *)hwc_dev->fb_dev, 2020c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->buffers, 2021876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen nbufs, 2022876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp, omaplfb_comp_data_sz); 20231fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse showfps(); 20241fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2025876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#if 0 2026876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!hwc_dev->use_sgx) { 2027876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen __u32 crt = 0; 2028876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int err2 = ioctl(hwc_dev->fb_fd, FBIO_WAITFORVSYNC, &crt); 2029876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (err2) { 2030876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("failed to wait for vsync (%d)", errno); 2031876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen err = err ? : -errno; 2032876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2033876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2034876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#endif 20357f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar } 203678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->last_ext_ovls = hwc_dev->ext_ovls; 203778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->last_int_ovls = hwc_dev->post2_layers; 2038c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (err) 203946de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("Post2 error"); 2040c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 20416ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden check_sync_fds(numDisplays, displays); 20426ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 2043c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malcheverr_out: 20442125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_unlock(&hwc_dev->lock); 2045bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar 2046876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (invalidate && hwc_dev->procs && hwc_dev->procs->invalidate) 2047bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar hwc_dev->procs->invalidate(hwc_dev->procs); 2048bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar 2049c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return err; 2050c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2051c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 20526ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void omap4_hwc_dump(struct hwc_composer_device_1 *dev, char *buff, int buff_len) 2053c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2054c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *)dev; 2055876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 2056734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar struct dump_buf log = { 2057734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf = buff, 2058734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf_len = buff_len, 2059734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar }; 2060c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int i; 2061c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2062734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "omap4_hwc %d:\n", dsscomp->num_ovls); 2063734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " idle timeout: %dms\n", hwc_dev->idle); 2064c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2065c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev for (i = 0; i < dsscomp->num_ovls; i++) { 2066c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev struct dss2_ovl_cfg *cfg = &dsscomp->ovls[i].cfg; 2067c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2068734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " layer %d:\n", i); 20693d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse dump_printf(&log, " enabled:%s buff:%p %dx%d stride:%d\n", 20703d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->enabled ? "true" : "false", hwc_dev->buffers[i], 20713d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->width, cfg->height, cfg->stride); 20723d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse dump_printf(&log, " src:(%d,%d) %dx%d dst:(%d,%d) %dx%d ix:%d zorder:%d\n", 20733d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->crop.x, cfg->crop.y, cfg->crop.w, cfg->crop.h, 20743d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->win.x, cfg->win.y, cfg->win.w, cfg->win.h, 20753d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->ix, cfg->zorder); 2076c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2077876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2078876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->blt_policy != BLTPOLICY_DISABLED) { 2079876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, " bltpolicy: %s, bltmode: %s\n", 2080876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy == BLTPOLICY_DEFAULT ? "default" : 2081876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy == BLTPOLICY_ALL ? "all" : "unknown", 2082876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_mode == BLTMODE_PAINT ? "paint" : "regionize"); 2083876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2084876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "\n"); 2085c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2086c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 20870aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarstatic void free_png_image(omap4_hwc_device_t *hwc_dev, struct omap4_hwc_img *img) 20880aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar{ 20890aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar memset(img, 0, sizeof(*img)); 20900aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar} 20910aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 20920aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarstatic int load_png_image(omap4_hwc_device_t *hwc_dev, char *path, struct omap4_hwc_img *img) 20930aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar{ 20940aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar void *ptr = NULL; 20950aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_bytepp row_pointers = NULL; 20960aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 20970aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar FILE *fd = fopen(path, "rb"); 20980aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!fd) { 209946de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to open PNG file %s: (%d)", path, errno); 21000aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar return -EINVAL; 21010aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21020aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21030aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar const int SIZE_PNG_HEADER = 8; 21040aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u8 header[SIZE_PNG_HEADER]; 21050aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar fread(header, 1, SIZE_PNG_HEADER, fd); 21060aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (png_sig_cmp(header, 0, SIZE_PNG_HEADER)) { 210746de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("%s is not a PNG file", path); 21080aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail; 21090aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21100aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21110aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 21120aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!png_ptr) 21130aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21140aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_infop info_ptr = png_create_info_struct(png_ptr); 21150aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!info_ptr) 21160aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21170aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21180aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (setjmp(png_jmpbuf(png_ptr))) 21190aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21200aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21210aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_init_io(png_ptr, fd); 21220aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_sig_bytes(png_ptr, SIZE_PNG_HEADER); 21230aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_user_limits(png_ptr, limits.max_width, limits.max_height); 21240aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_info(png_ptr, info_ptr); 21250aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21260aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u8 bit_depth = png_get_bit_depth(png_ptr, info_ptr); 21270aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u32 width = png_get_image_width(png_ptr, info_ptr); 21280aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u32 height = png_get_image_height(png_ptr, info_ptr); 21290aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u8 color_type = png_get_color_type(png_ptr, info_ptr); 21300aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21310aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar switch (color_type) { 21320aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_PALETTE: 21330aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_palette_to_rgb(png_ptr); 21340aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_filler(png_ptr, 128, PNG_FILLER_AFTER); 21350aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar break; 21360aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_GRAY: 21370aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (bit_depth < 8) { 21380aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_expand_gray_1_2_4_to_8(png_ptr); 21390aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) 21400aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_tRNS_to_alpha(png_ptr); 21410aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } else { 21420aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_filler(png_ptr, 128, PNG_FILLER_AFTER); 21430aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21440aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar /* fall through */ 21450aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_GRAY_ALPHA: 21460aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_gray_to_rgb(png_ptr); 21470aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar break; 21480aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_RGB: 21490aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_filler(png_ptr, 128, PNG_FILLER_AFTER); 21500aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar /* fall through */ 21510aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_RGB_ALPHA: 21520aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_bgr(png_ptr); 21530aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar break; 21540aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar default: 215546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("unsupported PNG color: %x", color_type); 21560aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21570aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21580aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21590aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (bit_depth == 16) 21600aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_strip_16(png_ptr); 21610aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21620aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar const int bpp = 4; 21630aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->size = ALIGN(width * height * bpp, 4096); 21640aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (img->size > hwc_dev->img_mem_size) { 216546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("image does not fit into framebuffer area (%d > %d)", img->size, hwc_dev->img_mem_size); 21660aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21670aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21680aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->ptr = hwc_dev->img_mem_ptr; 21690aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21700aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar row_pointers = calloc(height, sizeof(*row_pointers)); 21710aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!row_pointers) { 217246de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to allocate row pointers"); 21730aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21740aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21750aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u32 i; 21760aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar for (i = 0; i < height; i++) 21770aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar row_pointers[i] = img->ptr + i * width * bpp; 21780aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_rows(png_ptr, info_ptr, row_pointers); 21790aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_update_info(png_ptr, info_ptr); 21800aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->rowbytes = png_get_rowbytes(png_ptr, info_ptr); 21810aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21820aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_image(png_ptr, row_pointers); 21830aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_end(png_ptr, NULL); 21840aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar free(row_pointers); 21850aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 21860aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar fclose(fd); 21870aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->width = width; 21880aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->height = height; 21890aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar return 0; 21900aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21910aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarfail_alloc: 21920aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar free_png_image(hwc_dev, img); 21930aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar free(row_pointers); 21940aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!png_ptr || !info_ptr) 219546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to allocate PNG structures"); 21960aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 21970aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarfail: 21980aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar fclose(fd); 21990aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar return -EINVAL; 22000aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar} 22010aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 2202c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2203c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_device_close(hw_device_t* device) 2204c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2205c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) device;; 2206c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 22072125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev) { 22082125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->dsscomp_fd >= 0) 22092125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->dsscomp_fd); 22102125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->hdmi_fb_fd >= 0) 22112125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->hdmi_fb_fd); 22127f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->fb_fd >= 0) 22137f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar close(hwc_dev->fb_fd); 221483f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_fd >= 0) 221583f80658d865b741a024515c523e373df50c091eSunita Nadampalli ion_close(hwc_dev->ion_fd); 221683f80658d865b741a024515c523e373df50c091eSunita Nadampalli 22172125fa148686edfa389121f946377aedaa3d9483Lajos Molnar /* pthread will get killed when parent process exits */ 22182125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_destroy(&hwc_dev->lock); 2219751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_destroy(&hwc_dev->vsync_lock); 2220c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev free(hwc_dev); 22212125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 2222c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2223c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 2224c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2225c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2226c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_open_fb_hal(IMG_framebuffer_device_public_t **fb_dev) 2227c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2228e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar const struct hw_module_t *psModule; 2229c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_gralloc_module_public_t *psGrallocModule; 2230c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int err; 2231c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2232e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &psModule); 2233e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar psGrallocModule = (IMG_gralloc_module_public_t *) psModule; 2234e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar 2235c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if(err) 2236c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev goto err_out; 2237c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2238b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar if (strcmp(psGrallocModule->base.common.author, "Imagination Technologies")) { 2239c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev err = -EINVAL; 2240c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev goto err_out; 2241c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2242c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2243c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *fb_dev = psGrallocModule->psFrameBufferDevice; 2244c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2245c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 2246c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2247c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malcheverr_out: 224846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("Composer HAL failed to load compatible Graphics HAL"); 2249c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return err; 2250c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 22515db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 2252876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic void set_primary_display_transform_matrix(omap4_hwc_device_t *hwc_dev) 2253876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 2254876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* create primary display translation matrix */ 22555db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->fb_dis.ix = 0;/*Default display*/ 2256c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2257876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_DISPLAY, &hwc_dev->fb_dis); 2258876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (ret) 2259876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("failed to get display info (%d): %m", errno); 2260876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2261876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int lcd_w = hwc_dev->fb_dis.timings.x_res; 2262876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int lcd_h = hwc_dev->fb_dis.timings.y_res; 2263876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int orig_w = hwc_dev->fb_dev->base.width; 2264876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int orig_h = hwc_dev->fb_dev->base.height; 2265876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_rect_t region = {.left = 0, .top = 0, .right = orig_w, .bottom = orig_h}; 2266876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->primary_region = region; 2267876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->primary_rotation = ((lcd_w > lcd_h) ^ (orig_w > orig_h)) ? 1 : 0; 2268876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->primary_transform = ((lcd_w != orig_w)||(lcd_h != orig_h)) ? 1 : 0; 2269876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2270876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("transforming FB (%dx%d) => (%dx%d) rot%d", orig_w, orig_h, lcd_w, lcd_h, hwc_dev->primary_rotation); 2271876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2272876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* reorientation matrix is: 2273876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m = (center-from-target-center) * (scale-to-target) * (mirror) * (rotate) * (center-to-original-center) */ 2274876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2275876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen memcpy(hwc_dev->primary_m, m_unit, sizeof(m_unit)); 2276876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_translate(hwc_dev->primary_m, -(orig_w >> 1), -(orig_h >> 1)); 2277876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_rotate(hwc_dev->primary_m, hwc_dev->primary_rotation); 2278876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->primary_rotation & 1) 2279876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen swap(orig_w, orig_h); 2280876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_scale(hwc_dev->primary_m, orig_w, lcd_w, orig_h, lcd_h); 2281876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_translate(hwc_dev->primary_m, lcd_w >> 1, lcd_h >> 1); 22825db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket} 2283751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2284876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 22852b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnarstatic void handle_hotplug(omap4_hwc_device_t *hwc_dev) 22862125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 2287ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 22882b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar __u8 state = ext->hdmi_state; 2289876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 22905db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket /* Ignore external HDMI logic if the primary display is HDMI */ 22915db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (hwc_dev->on_tv) { 22925db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ALOGI("Primary display is HDMI - skip clone/dock logic"); 22935db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 22945db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (state) { 2295876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen __u32 xres = hwc_dev->fb_dev->base.width; 2296876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen __u32 yres = hwc_dev->fb_dev->base.height; 22975db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (omap4_hwc_set_best_hdmi_mode(hwc_dev, xres, yres, ext->lcd_xpy)) { 2298876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("Failed to set HDMI mode"); 22995db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2300876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen set_primary_display_transform_matrix(hwc_dev); 2301876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 23025db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ioctl(hwc_dev->fb_fd, FBIOBLANK, FB_BLANK_UNBLANK); 23035db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 23045db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (hwc_dev->procs && hwc_dev->procs->invalidate) { 23055db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->procs->invalidate(hwc_dev->procs); 23065db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2307876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else 23085db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ext->last_mode = 0; 23095db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 23105db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket return; 23115db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2312ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 23132125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_lock(&hwc_dev->lock); 2314ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.enabled = ext->mirror.enabled = 0; 23152125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (state) { 231641bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar /* check whether we can clone and/or dock */ 231741bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar char value[PROPERTY_VALUE_MAX]; 2318aa9be8a14744cae50a8f99e6cbb44be0d0c2c938Erik Gilling property_get("persist.hwc.docking.enabled", value, "1"); 2319ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.enabled = atoi(value) > 0; 2320aa9be8a14744cae50a8f99e6cbb44be0d0c2c938Erik Gilling property_get("persist.hwc.mirroring.enabled", value, "1"); 2321ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.enabled = atoi(value) > 0; 23224e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar property_get("persist.hwc.avoid_mode_change", value, "1"); 23234e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar ext->avoid_mode_change = atoi(value) > 0; 232441bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar 232541bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar /* get cloning transformation */ 2326aa9be8a14744cae50a8f99e6cbb44be0d0c2c938Erik Gilling property_get("persist.hwc.docking.transform", value, "0"); 2327ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.rotation = atoi(value) & EXT_ROTATION; 2328ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.hflip = (atoi(value) & EXT_HFLIP) > 0; 2329ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.docking = 1; 23305db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket property_get("persist.hwc.mirroring.transform", value, hwc_dev->fb_dis.timings.y_res > hwc_dev->fb_dis.timings.x_res ? "3" : "0"); 2331ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.rotation = atoi(value) & EXT_ROTATION; 2332ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.hflip = (atoi(value) & EXT_HFLIP) > 0; 2333ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.docking = 0; 2334ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 23352b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar if (ext->force_dock) { 23362b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar /* restrict to docking with no transform */ 23372b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->mirror.enabled = 0; 23382b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->dock.rotation = 0; 23392b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->dock.hflip = 0; 23400aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 23410aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!dock_image.rowbytes) { 23420aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar property_get("persist.hwc.dock_image", value, "/vendor/res/images/dock/dock.png"); 23430aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar load_png_image(hwc_dev, value, &dock_image); 23440aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 23452b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar } 23462b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar 2347ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar /* select best mode for mirroring */ 2348ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar if (ext->mirror.enabled) { 23493837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->current = ext->mirror; 23503797fa989f5fee97caea2bbadf433a5a9ac03d8dLajos Molnar ext->mirror_mode = 0; 23513837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (setup_mirroring(hwc_dev) == 0) { 23524e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar ext->mirror_mode = ext->last_mode; 2353ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ioctl(hwc_dev->hdmi_fb_fd, FBIOBLANK, FB_BLANK_UNBLANK); 23544e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar } else 2355ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.enabled = 0; 2356ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar } 235783f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* Allocate backup buffers for FB rotation 235883f80658d865b741a024515c523e373df50c091eSunita Nadampalli * This is required only if the FB tranform is different from that 235983f80658d865b741a024515c523e373df50c091eSunita Nadampalli * of the external display and the FB is not in TILER2D space 236083f80658d865b741a024515c523e373df50c091eSunita Nadampalli */ 236183f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ext->mirror.rotation && (limits.fbmem_type != DSSCOMP_FBMEM_TILER2D)) 236283f80658d865b741a024515c523e373df50c091eSunita Nadampalli allocate_tiler2d_buffers(hwc_dev); 236383f80658d865b741a024515c523e373df50c091eSunita Nadampalli 23644cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar } else { 23654cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar ext->last_mode = 0; 236683f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ext->mirror.rotation && (limits.fbmem_type != DSSCOMP_FBMEM_TILER2D)) { 236783f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* free tiler 2D buffer on detach */ 236883f80658d865b741a024515c523e373df50c091eSunita Nadampalli free_tiler2d_buffers(hwc_dev); 236983f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 23702125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 2371bb0a9edbe9d4072ed227550d898f0c2d0149e0baSteve Block ALOGI("external display changed (state=%d, mirror={%s tform=%ddeg%s}, dock={%s tform=%ddeg%s%s}, tv=%d", state, 2372ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.enabled ? "enabled" : "disabled", 2373ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.rotation * 90, 2374ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.hflip ? "+hflip" : "", 2375ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.enabled ? "enabled" : "disabled", 2376ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.rotation * 90, 2377ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.hflip ? "+hflip" : "", 23782b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->force_dock ? " forced" : "", 2379ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->on_tv); 2380ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 2381bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar pthread_mutex_unlock(&hwc_dev->lock); 2382834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 23833a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall /* hwc_dev->procs is set right after the device is opened, but there is 23843a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall * still a race condition where a hotplug event might occur after the open 23853a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall * but before the procs are registered. */ 2386876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->procs && hwc_dev->procs->invalidate) 2387876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->procs->invalidate(hwc_dev->procs); 23882125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 23892125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2390e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopianstatic void handle_uevents(omap4_hwc_device_t *hwc_dev, const char *buff, int len) 23912125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 2392e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int dock; 2393e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int hdmi; 2394e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int vsync; 2395e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int state = 0; 2396e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian uint64_t timestamp = 0; 2397e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian const char *s = buff; 2398e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2399e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian dock = !strcmp(s, "change@/devices/virtual/switch/dock"); 2400e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian hdmi = !strcmp(s, "change@/devices/virtual/switch/hdmi"); 2401bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling vsync = !strcmp(s, "change@/devices/platform/omapfb") || 2402bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling !strcmp(s, "change@/devices/virtual/switch/omapfb-vsync"); 2403e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2404e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (!dock && !vsync && !hdmi) 2405e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return; 24062125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24072125fa148686edfa389121f946377aedaa3d9483Lajos Molnar s += strlen(s) + 1; 24082125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24092125fa148686edfa389121f946377aedaa3d9483Lajos Molnar while(*s) { 2410e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (!strncmp(s, "SWITCH_STATE=", strlen("SWITCH_STATE="))) 2411e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian state = atoi(s + strlen("SWITCH_STATE=")); 2412e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian else if (!strncmp(s, "SWITCH_TIME=", strlen("SWITCH_TIME="))) 2413e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian timestamp = strtoull(s + strlen("SWITCH_TIME="), NULL, 0); 2414bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling else if (!strncmp(s, "VSYNC=", strlen("VSYNC="))) 2415bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling timestamp = strtoull(s + strlen("VSYNC="), NULL, 0); 24162125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24172125fa148686edfa389121f946377aedaa3d9483Lajos Molnar s += strlen(s) + 1; 2418e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (s - buff >= len) 2419e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian break; 2420e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2421e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2422e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (vsync) { 2423751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fire_vsync_event(hwc_dev, timestamp); 2424e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } else { 2425751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (dock) { 2426e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian hwc_dev->ext.force_dock = state == 1; 2427751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } else { 2428751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* If the primary display is HDMI, VSYNC is enabled, and HDMI's plug 2429751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * state has just gone from 1->0, then we need to be sure to start 2430751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * faking the VSYNC events. 2431751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen */ 2432751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->on_tv) { 2433751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int new_state, state_change; 2434751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2435751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 2436751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2437751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen new_state = state == 1; 2438751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen state_change = (new_state != hwc_dev->ext.hdmi_state); 2439751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->ext.hdmi_state = new_state; 2440751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (state_change && !new_state) 2441751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen wakeup_hdmi_thread(hwc_dev); 2442751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2443751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 2444751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } else { 2445751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->ext.hdmi_state = state == 1; 2446751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2447751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2448e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian handle_hotplug(hwc_dev); 24492125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 24502125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 24512125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24522125fa148686edfa389121f946377aedaa3d9483Lajos Molnarstatic void *omap4_hwc_hdmi_thread(void *data) 24532125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 24542125fa148686edfa389121f946377aedaa3d9483Lajos Molnar omap4_hwc_device_t *hwc_dev = data; 24552125fa148686edfa389121f946377aedaa3d9483Lajos Molnar static char uevent_desc[4096]; 245602150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian struct pollfd fds[2]; 2457b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis int invalidate = 0; 245802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian int timeout; 245902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian int err; 246002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 2461e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); 2462e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 24632125fa148686edfa389121f946377aedaa3d9483Lajos Molnar uevent_init(); 24642125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 246502150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian fds[0].fd = uevent_get_fd(); 246602150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian fds[0].events = POLLIN; 2467751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fds[1].fd = hwc_dev->wakeup_evt; 246802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian fds[1].events = POLLIN; 246902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 247002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian timeout = hwc_dev->idle ? hwc_dev->idle : -1; 247102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 24722125fa148686edfa389121f946377aedaa3d9483Lajos Molnar memset(uevent_desc, 0, sizeof(uevent_desc)); 24732125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24742125fa148686edfa389121f946377aedaa3d9483Lajos Molnar do { 2475751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t idle_wakeup = (uint64_t)(-1); 2476751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t vsync_wakeup = (uint64_t)(-1); 2477751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t now = vsync_clock_now(); 2478751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t effective_wakeup; 2479751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int effective_timeout; 2480751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2481751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (timeout >= 0) 2482751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen idle_wakeup = now + (((uint64_t)timeout) * 1000000); 2483751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2484751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->on_tv) { 2485751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 2486751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2487751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!hwc_dev->ext.hdmi_state && hwc_dev->vsync_enabled) { 2488751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen vsync_wakeup = hwc_dev->last_vsync_time_valid 2489751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ? hwc_dev->last_vsync_time 2490751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen : now; 2491751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2492751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen vsync_wakeup += hwc_dev->fake_vsync_period; 2493751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2494751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (vsync_wakeup < now) 2495751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen vsync_wakeup = now; 2496751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2497751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2498751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 2499751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2500751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2501751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_wakeup = idle_wakeup < vsync_wakeup 2502751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ? idle_wakeup 2503751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen : vsync_wakeup; 2504751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (effective_wakeup == (uint64_t)(-1)) 2505751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_timeout = -1; 2506751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen else if (effective_wakeup <= now) 2507751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_timeout = 0; 2508751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen else 2509751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_timeout = (int)((effective_wakeup - now + 999999) / 1000000); 2510751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2511751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (effective_timeout) 2512751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = poll(fds, 2, effective_timeout); 2513751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen else 2514751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = 0; 2515751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2516751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen now = vsync_clock_now(); 251702150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 251802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (err == 0) { 2519751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int fired = 0; 2520751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2521751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (now >= vsync_wakeup) { 2522751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fire_vsync_event(hwc_dev, vsync_wakeup); 2523751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fired = 1; 2524751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2525751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2526751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->idle && (now >= idle_wakeup)) { 25273a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall if (hwc_dev->procs) { 2528b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis pthread_mutex_lock(&hwc_dev->lock); 2529a9bec459a62ebc71f9e74832047c2d9da8a84ff0Dima Svetlov invalidate = !hwc_dev->force_sgx; 2530b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis if (invalidate) { 2531b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis hwc_dev->force_sgx = 2; 2532b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis } 2533b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis pthread_mutex_unlock(&hwc_dev->lock); 2534b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis 2535b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis if (invalidate) { 2536b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis hwc_dev->procs->invalidate(hwc_dev->procs); 2537b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis timeout = -1; 2538b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis } 253902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 254002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 2541751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fired = 1; 254202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 2543751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2544751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (fired) 2545751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen continue; 254602150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 254702150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 254802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (err == -1) { 254902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (errno != EINTR) 255046de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("event error: %m"); 255102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian continue; 255202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 255302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 2554751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (fds[1].revents & POLLIN) { 2555751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t tmp; 2556751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2557751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen read(hwc_dev->wakeup_evt, &tmp, sizeof(tmp)); 2558751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 255902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (!hwc_dev->force_sgx) 256002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian timeout = hwc_dev->idle ? hwc_dev->idle : -1; 256102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 256202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 256302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (fds[0].revents & POLLIN) { 256402150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian /* keep last 2 zeroes to ensure double 0 termination */ 2565e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int len = uevent_next_event(uevent_desc, sizeof(uevent_desc) - 2); 2566e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian handle_uevents(hwc_dev, uevent_desc, len); 256702150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 25682125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } while (1); 25692125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 25702125fa148686edfa389121f946377aedaa3d9483Lajos Molnar return NULL; 25712125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 25722125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 25736ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void omap4_hwc_registerProcs(struct hwc_composer_device_1* dev, 25742125fa148686edfa389121f946377aedaa3d9483Lajos Molnar hwc_procs_t const* procs) 25752125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 2576b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) dev; 25772125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2578b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar hwc_dev->procs = (typeof(hwc_dev->procs)) procs; 25792125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 25802125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 25816ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_query(struct hwc_composer_device_1* dev, 2582e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int what, int* value) 2583e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian{ 2584e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) dev; 2585e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2586e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian switch (what) { 2587e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian case HWC_BACKGROUND_LAYER_SUPPORTED: 2588e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian // we don't support the background layer yet 2589e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian value[0] = 0; 2590e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian break; 2591e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian case HWC_VSYNC_PERIOD: 2592e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian // vsync period in nanosecond 2593e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian value[0] = 1000000000.0 / hwc_dev->fb_dev->base.fps; 2594e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian break; 2595e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian default: 2596e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian // unsupported query 2597e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return -EINVAL; 2598e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2599e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return 0; 2600e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian} 2601e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 26026ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_event_control(struct hwc_composer_device_1* dev, 26036ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden int dpy, int event, int enabled) 2604e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian{ 2605e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) dev; 2606e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2607e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian switch (event) { 2608e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian case HWC_EVENT_VSYNC: 2609e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian { 2610e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int val = !!enabled; 2611e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int err; 2612e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2613751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* If the primary display is HDMI, then we need to be sure to fake a 2614751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * stream vsync events if vsync is enabled, but HDMI happens to be 2615751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * disconnected. 2616751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen */ 2617751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->on_tv) { 2618751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 2619751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2620751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!val) 2621751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time_valid = 0; 2622751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2623751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* If VSYNC is enabled, but HDMI is not actually plugged in, we need 2624751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * to fake it. Poke the work thread to make sure it is taking care 2625751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * of things. 2626751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen */ 2627751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!hwc_dev->ext.hdmi_state && !hwc_dev->vsync_enabled && val) 2628751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen wakeup_hdmi_thread(hwc_dev); 2629751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2630751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->vsync_enabled = val; 2631751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2632751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = ioctl(hwc_dev->fb_fd, OMAPFB_ENABLEVSYNC, &val); 2633751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 2634751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } else { 2635751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = ioctl(hwc_dev->fb_fd, OMAPFB_ENABLEVSYNC, &val); 2636751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2637751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2638e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (err < 0) 2639e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return -errno; 2640e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2641e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return 0; 2642e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2643e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian default: 2644e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return -EINVAL; 2645e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2646e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian} 2647e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 26483a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hallstatic int omap4_hwc_blank(struct hwc_composer_device_1 *dev, int dpy, int blank) 26496ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden{ 26506ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden // We're using an older method of screen blanking based on 26516ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden // early_suspend in the kernel. No need to do anything here. 26526ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden return 0; 26536ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden} 26546ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 2655c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_device_open(const hw_module_t* module, const char* name, 2656c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hw_device_t** device) 2657c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2658c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_module_t *hwc_mod = (omap4_hwc_module_t *)module; 2659c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev; 26602125fa148686edfa389121f946377aedaa3d9483Lajos Molnar int err = 0; 2661c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2662c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (strcmp(name, HWC_HARDWARE_COMPOSER)) { 2663c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return -EINVAL; 2664c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2665c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2666c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!hwc_mod->fb_dev) { 2667c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev err = omap4_hwc_open_fb_hal(&hwc_mod->fb_dev); 2668c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (err) 2669c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return err; 2670c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2671c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!hwc_mod->fb_dev) { 267246de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("Framebuffer HAL not opened before HWC"); 2673c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return -EFAULT; 2674c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2675c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_mod->fb_dev->bBypassPost = 1; 2676c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2677c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2678c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev = (omap4_hwc_device_t *)malloc(sizeof(*hwc_dev)); 2679c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (hwc_dev == NULL) 2680c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return -ENOMEM; 2681c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2682c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev memset(hwc_dev, 0, sizeof(*hwc_dev)); 2683c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2684c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.common.tag = HARDWARE_DEVICE_TAG; 26856ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_dev->base.common.version = HWC_DEVICE_API_VERSION_1_0; 2686c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.common.module = (hw_module_t *)module; 2687c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.common.close = omap4_hwc_device_close; 2688c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.prepare = omap4_hwc_prepare; 2689c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.set = omap4_hwc_set; 26903a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.eventControl = omap4_hwc_event_control; 26913a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.blank = omap4_hwc_blank; 2692e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian hwc_dev->base.query = omap4_hwc_query; 26933a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.registerProcs = omap4_hwc_registerProcs; 26943a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.dump = omap4_hwc_dump; 2695c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev = hwc_mod->fb_dev; 2696751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->wakeup_evt = -1; 2697c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *device = &hwc_dev->base.common; 2698c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2699751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->vsync_enabled = 0; 2700751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time_valid = 0; 2701751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->fake_vsync_period = 1000000000ull/60; 2702751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 27032125fa148686edfa389121f946377aedaa3d9483Lajos Molnar hwc_dev->dsscomp_fd = open("/dev/dsscomp", O_RDWR); 27047f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->dsscomp_fd < 0) { 270546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to open dsscomp (%d)", errno); 27067f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar err = -errno; 27077f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar goto done; 27087f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar } 27092125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2710876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_PLATFORM, &limits); 2711876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (ret) { 2712876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("failed to get platform limits (%d): %m", errno); 2713876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen err = -errno; 2714876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto done; 2715876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2716876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 27177f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar hwc_dev->fb_fd = open("/dev/graphics/fb0", O_RDWR); 27187f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->fb_fd < 0) { 271946de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to open fb (%d)", errno); 27207f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar err = -errno; 27217f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar goto done; 27227f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar } 27232125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 27240aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar struct fb_fix_screeninfo fix; 27250aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (ioctl(hwc_dev->fb_fd, FBIOGET_FSCREENINFO, &fix)) { 272646de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to get fb info (%d)", errno); 27270aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar err = -errno; 27280aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto done; 27290aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 27300aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 27310aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar hwc_dev->img_mem_size = fix.smem_len; 27320aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar hwc_dev->img_mem_ptr = mmap(NULL, fix.smem_len, PROT_WRITE, MAP_SHARED, hwc_dev->fb_fd, 0); 27330aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (hwc_dev->img_mem_ptr == MAP_FAILED) { 273446de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to map fb memory"); 27350aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar err = -errno; 27360aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto done; 27370aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 27380aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 2739876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Allocate the maximum buffers that we can receive from HWC */ 2740876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers = malloc(sizeof(buffer_handle_t) * MAX_HWC_LAYERS); 2741c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!hwc_dev->buffers) { 27422125fa148686edfa389121f946377aedaa3d9483Lajos Molnar err = -ENOMEM; 27432125fa148686edfa389121f946377aedaa3d9483Lajos Molnar goto done; 27442125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 27452125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2746876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_DISPLAY, &hwc_dev->fb_dis); 2747d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (ret) { 274846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to get display info (%d): %m", errno); 2749d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar err = -errno; 2750d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar goto done; 2751d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar } 2752f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk 275383f80658d865b741a024515c523e373df50c091eSunita Nadampalli hwc_dev->ion_fd = ion_open(); 275483f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_fd < 0) { 275583f80658d865b741a024515c523e373df50c091eSunita Nadampalli ALOGE("failed to open ion driver (%d)", errno); 275683f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 275783f80658d865b741a024515c523e373df50c091eSunita Nadampalli 275883f80658d865b741a024515c523e373df50c091eSunita Nadampalli int i; 275983f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 276083f80658d865b741a024515c523e373df50c091eSunita Nadampalli hwc_dev->ion_handles[i] = NULL; 276183f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 276283f80658d865b741a024515c523e373df50c091eSunita Nadampalli 2763f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk /* use default value in case some of requested display parameters missing */ 2764f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->ext.lcd_xpy = 1.0; 2765f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk if (hwc_dev->fb_dis.timings.x_res && hwc_dev->fb_dis.height_in_mm) { 2766f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->ext.lcd_xpy = (float) 2767f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->fb_dis.width_in_mm / hwc_dev->fb_dis.timings.x_res / 2768f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->fb_dis.height_in_mm * hwc_dev->fb_dis.timings.y_res; 2769f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk } 2770d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 27716d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket if (hwc_dev->fb_dis.channel == OMAP_DSS_CHANNEL_DIGIT) { 27725db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ALOGI("Primary display is HDMI"); 27735db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->on_tv = 1; 27745db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 27756d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket else { 27765db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->hdmi_fb_fd = open("/dev/graphics/fb1", O_RDWR); 27775db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (hwc_dev->hdmi_fb_fd < 0) { 27785db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ALOGE("failed to open hdmi fb (%d)", errno); 27795db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket err = -errno; 27805db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket goto done; 27815db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 27825db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2783876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen set_primary_display_transform_matrix(hwc_dev); 27845db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 2785751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if ((hwc_dev->wakeup_evt = eventfd(0, EFD_NONBLOCK)) < 0) { 2786751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ALOGE("failed to eventfd (%d): %m", errno); 278702150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian err = -errno; 278802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian goto done; 278902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 279002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 27912125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (pthread_mutex_init(&hwc_dev->lock, NULL)) { 279246de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to create mutex (%d): %m", errno); 2793b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar err = -errno; 2794b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar goto done; 27952125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 2796751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2797751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (pthread_mutex_init(&hwc_dev->vsync_lock, NULL)) { 2798751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ALOGE("failed to create vsync mutex (%d): %m", errno); 2799751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = -errno; 2800751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen goto done; 2801751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2802751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2803876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (pthread_create(&hwc_dev->hdmi_thread, NULL, omap4_hwc_hdmi_thread, hwc_dev)) 2804876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen { 280546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to create HDMI listening thread (%d): %m", errno); 2806b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar err = -errno; 2807b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar goto done; 2808c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2809c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2810c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* get debug properties */ 2811c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2812c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* see if hwc is enabled at all */ 2813c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev char value[PROPERTY_VALUE_MAX]; 2814c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev property_get("debug.hwc.rgb_order", value, "1"); 2815c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->flags_rgb_order = atoi(value); 2816c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev property_get("debug.hwc.nv12_only", value, "0"); 2817c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->flags_nv12_only = atoi(value); 281802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian property_get("debug.hwc.idle", value, "250"); 281902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian hwc_dev->idle = atoi(value); 28202125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 28218d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* get the board specific clone properties */ 28228d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* 0:0:1280:720 */ 2823dd922b9387f70e24b3462afe1bdc86ceb7541d4bLajos Molnar if (property_get("persist.hwc.mirroring.region", value, "") <= 0 || 28248d546610cba3698c62af537d97e38a7368362f1aLajos Molnar sscanf(value, "%d:%d:%d:%d", 28258d546610cba3698c62af537d97e38a7368362f1aLajos Molnar &hwc_dev->ext.mirror_region.left, &hwc_dev->ext.mirror_region.top, 28268d546610cba3698c62af537d97e38a7368362f1aLajos Molnar &hwc_dev->ext.mirror_region.right, &hwc_dev->ext.mirror_region.bottom) != 4 || 28278d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.left >= hwc_dev->ext.mirror_region.right || 28288d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.top >= hwc_dev->ext.mirror_region.bottom) { 2829876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct hwc_rect fb_region = { .right = hwc_dev->fb_dev->base.width, .bottom = hwc_dev->fb_dev->base.height }; 28308d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region = fb_region; 28318d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 2832bb0a9edbe9d4072ed227550d898f0c2d0149e0baSteve Block ALOGI("clone region is set to (%d,%d) to (%d,%d)", 28338d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.left, hwc_dev->ext.mirror_region.top, 28348d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.right, hwc_dev->ext.mirror_region.bottom); 28358d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 28362125fa148686edfa389121f946377aedaa3d9483Lajos Molnar /* read switch state */ 28372125fa148686edfa389121f946377aedaa3d9483Lajos Molnar int sw_fd = open("/sys/class/switch/hdmi/state", O_RDONLY); 28382125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (sw_fd >= 0) { 28392125fa148686edfa389121f946377aedaa3d9483Lajos Molnar char value; 28402125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (read(sw_fd, &value, 1) == 1) 28412b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar hwc_dev->ext.hdmi_state = value == '1'; 28422b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar close(sw_fd); 28432b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar } 28442b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar sw_fd = open("/sys/class/switch/dock/state", O_RDONLY); 28452b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar if (sw_fd >= 0) { 28462b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar char value; 28472b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar if (read(sw_fd, &value, 1) == 1) 28482b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar hwc_dev->ext.force_dock = value == '1'; 28492125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(sw_fd); 28502125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 28512b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar handle_hotplug(hwc_dev); 28522125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2853bb0a9edbe9d4072ed227550d898f0c2d0149e0baSteve Block ALOGI("omap4_hwc_device_open(rgb_order=%d nv12_only=%d)", 2854c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->flags_rgb_order, hwc_dev->flags_nv12_only); 2855c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2856876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int gc2d_fd = open("/dev/gcioctl", O_RDWR); 2857876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (gc2d_fd < 0) { 2858876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("Unable to open gc-core device (%d), blits disabled", errno); 2859876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy = BLTPOLICY_DISABLED; 2860876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else { 2861876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen property_get("persist.hwc.bltmode", value, "1"); 2862876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_mode = atoi(value); 2863876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen property_get("persist.hwc.bltpolicy", value, "1"); 2864876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy = atoi(value); 2865876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("blitter present, blits mode %d, blits policy %d", hwc_dev->blt_mode, hwc_dev->blt_policy); 2866876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen close(gc2d_fd); 2867876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2868876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_get_screengeometry(hwc_dev->fb_fd, &gscrngeom, 2869876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->fb_dev->base.format) != 0) { 2870876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen err = -EINVAL; 2871876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto done; 2872876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2873876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2874876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2875f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar property_get("persist.hwc.upscaled_nv12_limit", value, "2."); 2876f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar sscanf(value, "%f", &hwc_dev->upscaled_nv12_limit); 2877f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (hwc_dev->upscaled_nv12_limit < 0. || hwc_dev->upscaled_nv12_limit > 2048.) { 2878f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar ALOGW("Invalid upscaled_nv12_limit (%s), setting to 2.", value); 2879f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar hwc_dev->upscaled_nv12_limit = 2.; 2880f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar } 28811fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 28822125fa148686edfa389121f946377aedaa3d9483Lajos Molnardone: 28832125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (err && hwc_dev) { 28842125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->dsscomp_fd >= 0) 28852125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->dsscomp_fd); 28862125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->hdmi_fb_fd >= 0) 28872125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->hdmi_fb_fd); 28887f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->fb_fd >= 0) 28897f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar close(hwc_dev->fb_fd); 2890751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->wakeup_evt >= 0) 2891751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen close(hwc_dev->wakeup_evt); 28922125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_destroy(&hwc_dev->lock); 2893751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_destroy(&hwc_dev->vsync_lock); 28942125fa148686edfa389121f946377aedaa3d9483Lajos Molnar free(hwc_dev->buffers); 28952125fa148686edfa389121f946377aedaa3d9483Lajos Molnar free(hwc_dev); 28962125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 28972125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 28982125fa148686edfa389121f946377aedaa3d9483Lajos Molnar return err; 2899c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2900c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2901c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic struct hw_module_methods_t omap4_hwc_module_methods = { 2902c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .open = omap4_hwc_device_open, 2903c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}; 2904c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2905c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevomap4_hwc_module_t HAL_MODULE_INFO_SYM = { 2906c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .base = { 2907c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .common = { 2908c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .tag = HARDWARE_MODULE_TAG, 2909e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian .module_api_version = HWC_MODULE_API_VERSION_0_1, 2910a35209b2e26289458670e04d6e62dee3d085ea63Mathias Agopian .hal_api_version = HARDWARE_HAL_API_VERSION, 2911c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .id = HWC_HARDWARE_MODULE_ID, 2912c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .name = "OMAP 44xx Hardware Composer HAL", 2913c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .author = "Texas Instruments", 2914c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .methods = &omap4_hwc_module_methods, 2915c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev }, 2916c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev }, 2917c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}; 2918