hwc.c revision 25df2c673b1cdecd6d97f5c46905f58a834c9bdd
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; 155c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons 156c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons unsigned int large_rgb32_layers; 15758aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse}; 15858aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse 159c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstruct omap4_hwc_device { 16000d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar /* static data */ 1616ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_composer_device_1_t base; 1622125fa148686edfa389121f946377aedaa3d9483Lajos Molnar hwc_procs_t *procs; 1632125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_t hdmi_thread; 1642125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_t lock; 165c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 166c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_framebuffer_device_public_t *fb_dev; 167d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar struct dsscomp_display_info fb_dis; 16800d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int fb_fd; /* file descriptor for /dev/fb0 */ 16900d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int dsscomp_fd; /* file descriptor for /dev/dsscomp */ 17000d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int hdmi_fb_fd; /* file descriptor for /dev/fb1 */ 171751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int wakeup_evt; /* eventfd used to wakeup event thread */ 17200d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar 1730aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar int img_mem_size; /* size of fb for hdmi */ 1740aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar void *img_mem_ptr; /* start of fb for hdmi */ 1750aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 17600d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int flags_rgb_order; 17700d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int flags_nv12_only; 178f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar float upscaled_nv12_limit; 179c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 180876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int on_tv; /* using a tv */ 18100d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int force_sgx; 18200d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar omap4_hwc_ext_t ext; /* external mirroring data */ 18300d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int idle; 184ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 185876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen float primary_m[2][3]; /* internal transformation matrix */ 186876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int primary_transform; 187876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int primary_rotation; 188876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_rect_t primary_region; 1895db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 190c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev buffer_handle_t *buffers; 191c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int use_sgx; 19278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar int swap_rb; 193876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int post2_layers; /* Buffers used with DSS pipes*/ 194876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int post2_blit_buffers; /* Buffers used with blit */ 19500d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int ext_ovls; /* # of overlays on external display for current composition */ 19600d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int ext_ovls_wanted; /* # of overlays that should be on external display for current composition */ 19700d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar int last_ext_ovls; /* # of overlays on external/internal display for last composition */ 19878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar int last_int_ovls; 199876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 200876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen enum bltmode blt_mode; 201876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen enum bltpolicy blt_policy; 202876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 203876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int blit_flags; 204876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int blit_num; 205876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct omap_hwc_data comp_data; /* This is a kernel data structure */ 206876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct rgz_blt_entry blit_ops[RGZ_MAX_BLITS]; 20758aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse struct counts stats; 20883f80658d865b741a024515c523e373df50c091eSunita Nadampalli int ion_fd; 20983f80658d865b741a024515c523e373df50c091eSunita Nadampalli struct ion_handle *ion_handles[2]; 210751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 211751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* fake vsync event state */ 212751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_t vsync_lock; 213751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int vsync_enabled; 214751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t last_vsync_time; 215751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int last_vsync_time_valid; 216751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t fake_vsync_period; 217c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}; 218c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct omap4_hwc_device omap4_hwc_device_t; 219c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 220734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar#define HAL_FMT(f) ((f) == HAL_PIXEL_FORMAT_TI_NV12 ? "NV12" : \ 221dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse (f) == HAL_PIXEL_FORMAT_TI_NV12_1D ? "NV12" : \ 222734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_YV12 ? "YV12" : \ 223734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_BGRX_8888 ? "xRGB32" : \ 224734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_RGBX_8888 ? "xBGR32" : \ 225734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_BGRA_8888 ? "ARGB32" : \ 226734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_RGBA_8888 ? "ABGR32" : \ 227734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == HAL_PIXEL_FORMAT_RGB_565 ? "RGB565" : "??") 228734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 229734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar#define DSS_FMT(f) ((f) == OMAP_DSS_COLOR_NV12 ? "NV12" : \ 230734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == OMAP_DSS_COLOR_RGB24U ? "xRGB32" : \ 231734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == OMAP_DSS_COLOR_ARGB32 ? "ARGB32" : \ 232734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar (f) == OMAP_DSS_COLOR_RGB16 ? "RGB565" : "??") 233734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 234c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int debug = 0; 235876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic int debugpost2 = 0; 236876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic int debugblt = 0; 237876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic rgz_t grgz; 238876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic struct bvsurfgeom gscrngeom; 239c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2401fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthousestatic void showfps(void) 2411fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse{ 2421fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static int framecount = 0; 2431fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static int lastframecount = 0; 2441fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static nsecs_t lastfpstime = 0; 2451fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse static float fps = 0; 2461fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse char value[PROPERTY_VALUE_MAX]; 2471fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2481fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse property_get("debug.hwc.showfps", value, "0"); 2491fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse if (!atoi(value)) { 2501fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse return; 2511fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse } 2521fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2531fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse framecount++; 2541fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse if (!(framecount & 0x7)) { 2551fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); 2561fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse nsecs_t diff = now - lastfpstime; 2571fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse fps = ((framecount - lastframecount) * (float)(s2ns(1))) / diff; 2581fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse lastfpstime = now; 2591fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse lastframecount = framecount; 2601fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse ALOGI("%d Frames, %f FPS", framecount, fps); 2611fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse } 2621fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse} 2631fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2646ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void dump_layer(hwc_layer_1_t const* l) 265c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2663a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}, {%d,%d,%d,%d}", 267b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->compositionType, l->flags, l->handle, l->transform, l->blending, 268b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.left, 269b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.top, 270b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.right, 271b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->sourceCrop.bottom, 272b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.left, 273b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.top, 274b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.right, 275b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar l->displayFrame.bottom); 276c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 277c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 278c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic void dump_dsscomp(struct dsscomp_setup_dispc_data *d) 279c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 28078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar unsigned i; 281c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2823a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("[%08x] set: %c%c%c %d ovls\n", 283c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev d->sync_id, 284c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev (d->mode & DSSCOMP_SETUP_MODE_APPLY) ? 'A' : '-', 285c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev (d->mode & DSSCOMP_SETUP_MODE_DISPLAY) ? 'D' : '-', 286c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev (d->mode & DSSCOMP_SETUP_MODE_CAPTURE) ? 'C' : '-', 287c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev d->num_ovls); 288c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 28978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar for (i = 0; i < d->num_mgrs; i++) { 29000d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar struct dss2_mgr_info *mi = &d->mgrs[i]; 2913a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD(" (dis%d alpha=%d col=%08x ilace=%d)\n", 292b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar mi->ix, 293b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar mi->alpha_blending, mi->default_color, 294b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar mi->interlaced); 29578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 29678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 297c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev for (i = 0; i < d->num_ovls; i++) { 29800d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar struct dss2_ovl_info *oi = &d->ovls[i]; 299b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar struct dss2_ovl_cfg *c = &oi->cfg; 300b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar if (c->zonly) 3013a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("ovl%d(%s z%d)\n", 302b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->ix, c->enabled ? "ON" : "off", c->zorder); 303b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar else 3043a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve 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", 305b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->ix, c->enabled ? "ON" : "off", c->zorder, DSS_FMT(c->color_mode), 306b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->pre_mult_alpha ? " premult" : "", 307b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar (c->global_alpha * 100 + 128) / 255, 308b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->width, c->height, c->crop.x, c->crop.y, 309b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->crop.w, c->crop.h, 310b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->rotation, c->mirror ? "+mir" : "", 311b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar c->win.x, c->win.y, c->win.w, c->win.h, 312b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar (void *) oi->ba, (void *) oi->uv, c->stride); 313c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 314c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 315c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 316734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnarstruct dump_buf { 317734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar char *buf; 318734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar int buf_len; 319734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar int len; 320734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar}; 321734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 322734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnarstatic void dump_printf(struct dump_buf *buf, const char *fmt, ...) 323734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar{ 324734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar va_list ap; 325734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 326734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar va_start(ap, fmt); 327734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar buf->len += vsnprintf(buf->buf + buf->len, buf->buf_len - buf->len, fmt, ap); 328734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar va_end(ap); 329734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar} 330734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 3316ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void dump_set_info(omap4_hwc_device_t *hwc_dev, hwc_display_contents_1_t* list) 332734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar{ 333876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 334734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar char logbuf[1024]; 335734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar struct dump_buf log = { 336734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf = logbuf, 337734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf_len = sizeof(logbuf), 338734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar }; 339734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar unsigned int i; 340734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 341734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "set H{"); 342734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar for (i = 0; list && i < list->numHwLayers; i++) { 343734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (i) 344734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " "); 3456ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer = &list->hwLayers[i]; 346734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 347876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_blit_buffers) { 348876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if ((i + 1) < hwc_dev->post2_layers) 349876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p:%s,", handle, "DSS"); 350876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen else 351876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p:%s,", handle, "BV2D"); 352876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 353876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen else 354876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p:%s,", handle, layer->compositionType == HWC_OVERLAY ? "DSS" : "SGX"); 355734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if ((layer->flags & HWC_SKIP_LAYER) || !handle) { 356734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "SKIP"); 357734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar continue; 358734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 359734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (layer->flags & HWC_HINT_CLEAR_FB) 360734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "CLR,"); 361734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%d*%d(%s)", handle->iWidth, handle->iHeight, HAL_FMT(handle->iFormat)); 362734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (layer->transform) 363734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "~%d", layer->transform); 364734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 365734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "} D{"); 366734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar for (i = 0; i < dsscomp->num_ovls; i++) { 367734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (i) 368734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " "); 369734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%d=", dsscomp->ovls[i].cfg.ix); 370734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (dsscomp->ovls[i].cfg.enabled) 371734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%08x:%d*%d,%s", 372734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dsscomp->ovls[i].ba, 373734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dsscomp->ovls[i].cfg.width, 374734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dsscomp->ovls[i].cfg.height, 375734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar DSS_FMT(dsscomp->ovls[i].cfg.color_mode)); 376734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar else 377734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "-"); 378734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 379734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "} L{"); 380734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar for (i = 0; i < hwc_dev->post2_layers; i++) { 381734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (i) 382734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " "); 383734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "%p", hwc_dev->buffers[i]); 384734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar } 385876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_blit_buffers) { 386876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "} B{"); 387876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = hwc_dev->post2_layers; 388876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen i < hwc_dev->post2_blit_buffers + hwc_dev->post2_layers; i++) { 389876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "%p ", hwc_dev->buffers[i]); 390876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 391876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 392734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "}%s\n", hwc_dev->use_sgx ? " swap" : ""); 393734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 3943a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("%s", log.buf); 395734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar} 396734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar 3975706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int sync_id = 0; 3985706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 399c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_is_valid_format(int format) 400c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 401c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev switch(format) { 402c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGB_565: 403c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGBX_8888: 404c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGBA_8888: 405c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRA_8888: 406c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRX_8888: 407c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_TI_NV12: 408dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse case HAL_PIXEL_FORMAT_TI_NV12_1D: 409c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 1; 410c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 411c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev default: 412c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 413c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 414c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 415c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 416876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic int scaled(hwc_layer_1_t *layer) 417c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 4182704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int w = WIDTH(layer->sourceCrop); 4192704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int h = HEIGHT(layer->sourceCrop); 420d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 421d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar if (layer->transform & HWC_TRANSFORM_ROT_90) 422d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar swap(w, h); 423d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 424876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return WIDTH(layer->displayFrame) != w || HEIGHT(layer->displayFrame) != h; 425c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 426c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 4276ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int is_protected(hwc_layer_1_t *layer) 4284ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli{ 4294ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 4304ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli 4314ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli return (handle->usage & GRALLOC_USAGE_PROTECTED); 4324ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli} 4334ce532200f33ca2c77cd66de924c83decaf7fa30Sunita Nadampalli 4345706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar#define is_BLENDED(layer) ((layer)->blending != HWC_BLENDING_NONE) 4355706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 436fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrechtstatic int is_RGB32(IMG_native_handle_t *handle) 437fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht{ 438fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht switch(handle->iFormat) 439fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht { 440fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht case HAL_PIXEL_FORMAT_BGRA_8888: 441fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht case HAL_PIXEL_FORMAT_BGRX_8888: 442fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht return 1; 443fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht default: 444fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht return 0; 445fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht } 446fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht} 447fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht 4485706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_RGB(IMG_native_handle_t *handle) 4495706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4505706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar switch(handle->iFormat) 4515706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar { 4525706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_BGRA_8888: 4535706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_BGRX_8888: 4545706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGB_565: 4555706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 1; 4565706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar default: 4575706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 0; 4585706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar } 4595706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 460a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthousestatic int get_rgb_bpp(IMG_native_handle_t *handle) 461a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse{ 462a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse switch(handle->iFormat) 463a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse { 464a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse case HAL_PIXEL_FORMAT_BGRA_8888: 465a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse case HAL_PIXEL_FORMAT_BGRX_8888: 466a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse case HAL_PIXEL_FORMAT_RGBX_8888: 467a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse case HAL_PIXEL_FORMAT_RGBA_8888: 468a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse return 32; 469a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse case HAL_PIXEL_FORMAT_RGB_565: 470a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse return 16; 471a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse default: 472a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse return 0; 473a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse } 474a41d64f2cc51096c1110f518b948c316bf15943bTony Lofthouse} 475c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 4765706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_BGR_format(int format) 4775706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4785706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar switch (format) { 4795706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGBX_8888: 4805706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGBA_8888: 4815706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 1; 4825706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar default: 4835706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 0; 4845706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar } 4855706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 486a3a76c576a0a1706c102570697b4fc0017eb46fbMathias Agopian 4875706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_BGR(IMG_native_handle_t *handle) 4885706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4895706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return is_BGR_format(handle->iFormat); 4905706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 4915706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 4925706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnarstatic int is_NV12(IMG_native_handle_t *handle) 4935706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar{ 4945706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar switch(handle->iFormat) 4955706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar { 4965706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_TI_NV12: 497dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse case HAL_PIXEL_FORMAT_TI_NV12_1D: 4985706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 1; 4995706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar default: 5005706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return 0; 5015706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar } 5025706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar} 503c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 504284005c3a0e0b21f28febca5ad1dd647f912d9feJason Simmonsstatic int is_upscaled_NV12(omap4_hwc_device_t *hwc_dev, hwc_layer_1_t *layer) 505f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar{ 506f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (!layer) 507f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar return 0; 508f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 509f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 510f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (!is_NV12(handle)) 511f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar return 0; 512f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 513f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar int w = WIDTH(layer->sourceCrop); 514f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar int h = HEIGHT(layer->sourceCrop); 515f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 516f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (layer->transform & HWC_TRANSFORM_ROT_90) 517f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar swap(w, h); 518f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 519f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar return (WIDTH(layer->displayFrame) >= w * hwc_dev->upscaled_nv12_limit || 520f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar HEIGHT(layer->displayFrame) >= h * hwc_dev->upscaled_nv12_limit); 521f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar} 522f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar 523284005c3a0e0b21f28febca5ad1dd647f912d9feJason Simmonsstatic int dockable(hwc_layer_1_t *layer) 524834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar{ 525834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 526834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 527834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar return (handle->usage & GRALLOC_USAGE_EXTERNAL_DISP); 528834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar} 529834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 530c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons/* test if layer appears to be RGB32 (4 Bpp) and > 1280x720 */ 531c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmonsstatic int is_large_rgb32_layer(const hwc_layer_1_t *layer) 532c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons{ 533c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 534c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons 535c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons return is_RGB32(handle) && 536c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons (((layer->sourceCrop.right - layer->sourceCrop.left) > 1280) || 537c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons ((layer->sourceCrop.bottom - layer->sourceCrop.top) > 720)); 538c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons} 539c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons 540751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chenstatic uint64_t vsync_clock_now() 541751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen{ 542751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t now = 0; 543751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen struct timespec ts; 544751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 545751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!clock_gettime(CLOCK_MONOTONIC, &ts)) 546751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen now = ((uint64_t)ts.tv_sec) * 1000000000ull + ts.tv_nsec; 547751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 548751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen return now; 549751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen} 550751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 551751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chenstatic void wakeup_hdmi_thread(omap4_hwc_device_t *hwc_dev) 552751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen{ 553751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t tmp = 1; 554751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen write(hwc_dev->wakeup_evt, &tmp, sizeof(tmp)); 555751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen} 556751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 557751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chenstatic void fire_vsync_event(omap4_hwc_device_t *hwc_dev, uint64_t timestamp) 558751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen{ 559751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 560751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 561751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time_valid = 1; 562751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time = timestamp; 563751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 564751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 565751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 566876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->procs && hwc_dev->procs->vsync) 567751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->procs->vsync(hwc_dev->procs, 0, timestamp); 568751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen} 569751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 57038934f125a600817dded7aeba9639c6a75afe358Lajos Molnarstatic unsigned int mem1d(IMG_native_handle_t *handle) 57138934f125a600817dded7aeba9639c6a75afe358Lajos Molnar{ 5725706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar if (handle == NULL || is_NV12(handle)) 573b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar return 0; 57438934f125a600817dded7aeba9639c6a75afe358Lajos Molnar 5755706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar int bpp = handle->iFormat == HAL_PIXEL_FORMAT_RGB_565 ? 2 : 4; 57638934f125a600817dded7aeba9639c6a75afe358Lajos Molnar int stride = ALIGN(handle->iWidth, HW_ALIGN) * bpp; 57738934f125a600817dded7aeba9639c6a75afe358Lajos Molnar return stride * handle->iHeight; 57838934f125a600817dded7aeba9639c6a75afe358Lajos Molnar} 57938934f125a600817dded7aeba9639c6a75afe358Lajos Molnar 580c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic void 5815706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnaromap4_hwc_setup_layer_base(struct dss2_ovl_cfg *oc, int index, int format, int blended, int width, int height) 582c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 583c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev unsigned int bits_per_pixel; 584c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 585c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* YUV2RGB conversion */ 586c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev const struct omap_dss_cconv_coefs ctbl_bt601_5 = { 587c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 298, 409, 0, 298, -208, -100, 298, 0, 517, 0, 588c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev }; 589c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 590c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* convert color format */ 591c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev switch (format) { 592c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGBA_8888: 593c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRA_8888: 594c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_ARGB32; 595c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 32; 5965706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar if (blended) 5975706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar break; 598c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 5995706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar case HAL_PIXEL_FORMAT_RGBX_8888: 600c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_BGRX_8888: 601c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_RGB24U; 602c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 32; 603c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev break; 604c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 605c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_RGB_565: 606c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_RGB16; 607c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 16; 608c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev break; 609c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 610c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev case HAL_PIXEL_FORMAT_TI_NV12: 611dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse case HAL_PIXEL_FORMAT_TI_NV12_1D: 612c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->color_mode = OMAP_DSS_COLOR_NV12; 613c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev bits_per_pixel = 8; 614c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->cconv = ctbl_bt601_5; 615c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev break; 616c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 617c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev default: 618c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Should have been filtered out */ 619ac837f2654f5a7a7fbecf05e4b085b87a7701714Steve Block ALOGV("Unsupported pixel format"); 620c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return; 621c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 622c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 623c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->width = width; 624c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->height = height; 625c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->stride = ALIGN(width, HW_ALIGN) * bits_per_pixel / 8; 626c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 627c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->enabled = 1; 628c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->global_alpha = 255; 629c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->zorder = index; 630c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->ix = 0; 631c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 632c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* defaults for SGX framebuffer renders */ 633c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.w = oc->win.w = width; 634c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.h = oc->win.h = height; 635c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 636c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* for now interlacing and vc1 info is not supplied */ 637c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->ilace = OMAP_DSS_ILACE_NONE; 638c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->vc1.enable = 0; 639c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 640c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 641c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic void 642c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevomap4_hwc_setup_layer(omap4_hwc_device_t *hwc_dev, struct dss2_ovl_info *ovl, 6436ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer, int index, 644c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int format, int width, int height) 645c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 646c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev struct dss2_ovl_cfg *oc = &ovl->cfg; 647c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 648c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev //dump_layer(layer); 649c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 6505706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar omap4_hwc_setup_layer_base(oc, index, format, is_BLENDED(layer), width, height); 651c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 652c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* convert transformation - assuming 0-set config */ 653c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform & HWC_TRANSFORM_FLIP_H) 654c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->mirror = 1; 655c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform & HWC_TRANSFORM_FLIP_V) { 656c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->rotation = 2; 65778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar oc->mirror = !oc->mirror; 658c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 659c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform & HWC_TRANSFORM_ROT_90) { 660c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->rotation += oc->mirror ? -1 : 1; 661c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->rotation &= 3; 662c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 663c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 664c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->pre_mult_alpha = layer->blending == HWC_BLENDING_PREMULT; 665c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 666c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* display position */ 667c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->win.x = layer->displayFrame.left; 668c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->win.y = layer->displayFrame.top; 6692704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->win.w = WIDTH(layer->displayFrame); 6702704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->win.h = HEIGHT(layer->displayFrame); 671c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 672c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* crop */ 673c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.x = layer->sourceCrop.left; 674c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev oc->crop.y = layer->sourceCrop.top; 6752704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->crop.w = WIDTH(layer->sourceCrop); 6762704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar oc->crop.h = HEIGHT(layer->sourceCrop); 677c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 678c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 6792952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarconst float m_unit[2][3] = { { 1., 0., 0. }, { 0., 1., 0. } }; 6802952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6812952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline void m_translate(float m[2][3], int dx, int dy) 6822952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6832952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[0][2] += dx; 6842952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[1][2] += dy; 6852952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6862952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6872952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline void m_scale1(float m[3], int from, int to) 6882952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6892952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[0] = m[0] * to / from; 6902952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[1] = m[1] * to / from; 6912952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m[2] = m[2] * to / from; 6922952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6932952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 6942952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline void m_scale(float m[2][3], int x_from, int x_to, int y_from, int y_to) 6952952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 6962952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m_scale1(m[0], x_from, x_to); 6972952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m_scale1(m[1], y_from, y_to); 6982952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 6992952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 7002952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic void m_rotate(float m[2][3], int quarter_turns) 7012952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 7022952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar if (quarter_turns & 2) 7032952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m_scale(m, 1, -1, 1, -1); 7042952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar if (quarter_turns & 1) { 7052952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar int q; 7062952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar q = m[0][0]; m[0][0] = -m[1][0]; m[1][0] = q; 7072952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar q = m[0][1]; m[0][1] = -m[1][1]; m[1][1] = q; 7082952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar q = m[0][2]; m[0][2] = -m[1][2]; m[1][2] = q; 7092952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar } 7102952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 7112952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 7122952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic inline int m_round(float x) 7132952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 7142952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* int truncates towards 0 */ 7152952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar return (int) (x < 0 ? x - 0.5 : x + 0.5); 7162952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 7172952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 718ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar/* 7191b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar * assuming xpy (xratio:yratio) original pixel ratio, calculate the adjusted width 720ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar * and height for a screen of xres/yres and physical size of width/height. 721ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar * The adjusted size is the largest that fits into the screen. 722ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar */ 723ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnarstatic void get_max_dimensions(__u32 orig_xres, __u32 orig_yres, 7241b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float xpy, 725ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 scr_xres, __u32 scr_yres, 726ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 scr_width, __u32 scr_height, 727ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 *adj_xres, __u32 *adj_yres) 728ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar{ 729ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* assume full screen (largest size)*/ 730ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_xres = scr_xres; 731ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_yres = scr_yres; 732ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 733ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* assume 1:1 pixel ratios if none supplied */ 734ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar if (!scr_width || !scr_height) { 735ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar scr_width = scr_xres; 736ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar scr_height = scr_yres; 737ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar } 738ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 739ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* trim to keep aspect ratio */ 7401b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float x_factor = orig_xres * xpy * scr_height; 7411b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float y_factor = orig_yres * scr_width; 742ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 743ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* allow for tolerance so we avoid scaling if framebuffer is standard size */ 744ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar if (x_factor < y_factor * (1.f - ASPECT_RATIO_TOLERANCE)) 745ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_xres = (__u32) (x_factor * *adj_xres / y_factor + 0.5); 746ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar else if (x_factor * (1.f - ASPECT_RATIO_TOLERANCE) > y_factor) 747ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar *adj_yres = (__u32) (y_factor * *adj_yres / x_factor + 0.5); 748ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar} 749ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar 7508d546610cba3698c62af537d97e38a7368362f1aLajos Molnarstatic void set_ext_matrix(omap4_hwc_ext_t *ext, struct hwc_rect region) 7512952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 7528d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int orig_w = WIDTH(region); 7538d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int orig_h = HEIGHT(region); 7543797fa989f5fee97caea2bbadf433a5a9ac03d8dLajos Molnar float xpy = ext->lcd_xpy; 7552952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 7562952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* reorientation matrix is: 7572952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar m = (center-from-target-center) * (scale-to-target) * (mirror) * (rotate) * (center-to-original-center) */ 7582952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 759ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar memcpy(ext->m, m_unit, sizeof(m_unit)); 7608d546610cba3698c62af537d97e38a7368362f1aLajos Molnar m_translate(ext->m, -(orig_w >> 1) - region.left, -(orig_h >> 1) - region.top); 761ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_rotate(ext->m, ext->current.rotation); 762ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar if (ext->current.hflip) 763ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_scale(ext->m, 1, -1, 1, 1); 7642952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 765ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar if (ext->current.rotation & 1) { 766d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar swap(orig_w, orig_h); 7671b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar xpy = 1. / xpy; 7682952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar } 7692952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 770ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar /* get target size */ 771ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar __u32 adj_xres, adj_yres; 7721b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar get_max_dimensions(orig_w, orig_h, xpy, 773ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->xres, ext->yres, ext->width, ext->height, 774ae5ccc208800debb41acfc45096d318847e8db50Lajos Molnar &adj_xres, &adj_yres); 7752952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 776ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_scale(ext->m, orig_w, adj_xres, orig_h, adj_yres); 777ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar m_translate(ext->m, ext->xres >> 1, ext->yres >> 1); 7782952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 7792952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 7808d546610cba3698c62af537d97e38a7368362f1aLajos Molnarstatic int 7818d546610cba3698c62af537d97e38a7368362f1aLajos Molnarcrop_to_rect(struct dss2_ovl_cfg *cfg, struct hwc_rect vis_rect) 7828d546610cba3698c62af537d97e38a7368362f1aLajos Molnar{ 7838d546610cba3698c62af537d97e38a7368362f1aLajos Molnar struct { 7848d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int xy[2]; 7858d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int wh[2]; 7868d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } crop, win; 7878d546610cba3698c62af537d97e38a7368362f1aLajos Molnar struct { 7888d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int lt[2]; 7898d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int rb[2]; 7908d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } vis; 7918d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[0] = cfg->win.x; win.xy[1] = cfg->win.y; 7928d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.wh[0] = cfg->win.w; win.wh[1] = cfg->win.h; 7938d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[0] = cfg->crop.x; crop.xy[1] = cfg->crop.y; 7948d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.wh[0] = cfg->crop.w; crop.wh[1] = cfg->crop.h; 7958d546610cba3698c62af537d97e38a7368362f1aLajos Molnar vis.lt[0] = vis_rect.left; vis.lt[1] = vis_rect.top; 7968d546610cba3698c62af537d97e38a7368362f1aLajos Molnar vis.rb[0] = vis_rect.right; vis.rb[1] = vis_rect.bottom; 7978d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 7988d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int c, swap = cfg->rotation & 1; 7998d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8008d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* align crop window with display coordinates */ 8018d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (swap) 8028d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[1] -= (crop.wh[1] = -crop.wh[1]); 8038d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (cfg->rotation & 2) 8048d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[!swap] -= (crop.wh[!swap] = -crop.wh[!swap]); 8058d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if ((!cfg->mirror) ^ !(cfg->rotation & 2)) 8068d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[swap] -= (crop.wh[swap] = -crop.wh[swap]); 8078d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8088d546610cba3698c62af537d97e38a7368362f1aLajos Molnar for (c = 0; c < 2; c++) { 8098d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* see if complete buffer is outside the vis or it is 8108d546610cba3698c62af537d97e38a7368362f1aLajos Molnar fully cropped or scaled to 0 */ 8118d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (win.wh[c] <= 0 || vis.rb[c] <= vis.lt[c] || 8128d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[c] + win.wh[c] <= vis.lt[c] || 8138d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[c] >= vis.rb[c] || 8148d546610cba3698c62af537d97e38a7368362f1aLajos Molnar !crop.wh[c ^ swap]) 8158d546610cba3698c62af537d97e38a7368362f1aLajos Molnar return -ENOENT; 8168d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8178d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* crop left/top */ 8188d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (win.xy[c] < vis.lt[c]) { 8198d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* correction term */ 8208d546610cba3698c62af537d97e38a7368362f1aLajos Molnar int a = (vis.lt[c] - win.xy[c]) * crop.wh[c ^ swap] / win.wh[c]; 8218d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[c ^ swap] += a; 8228d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.wh[c ^ swap] -= a; 8238d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.wh[c] -= vis.lt[c] - win.xy[c]; 8248d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.xy[c] = vis.lt[c]; 8258d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 8268d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* crop right/bottom */ 8278d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (win.xy[c] + win.wh[c] > vis.rb[c]) { 8288d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.wh[c ^ swap] = crop.wh[c ^ swap] * (vis.rb[c] - win.xy[c]) / win.wh[c]; 8298d546610cba3698c62af537d97e38a7368362f1aLajos Molnar win.wh[c] = vis.rb[c] - win.xy[c]; 8308d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 8318d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8328d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (!crop.wh[c ^ swap] || !win.wh[c]) 8338d546610cba3698c62af537d97e38a7368362f1aLajos Molnar return -ENOENT; 8348d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 8358d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8368d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* realign crop window to buffer coordinates */ 8378d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (cfg->rotation & 2) 8388d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[!swap] -= (crop.wh[!swap] = -crop.wh[!swap]); 8398d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if ((!cfg->mirror) ^ !(cfg->rotation & 2)) 8408d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[swap] -= (crop.wh[swap] = -crop.wh[swap]); 8418d546610cba3698c62af537d97e38a7368362f1aLajos Molnar if (swap) 8428d546610cba3698c62af537d97e38a7368362f1aLajos Molnar crop.xy[1] -= (crop.wh[1] = -crop.wh[1]); 8438d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8448d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->win.x = win.xy[0]; cfg->win.y = win.xy[1]; 8458d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->win.w = win.wh[0]; cfg->win.h = win.wh[1]; 8468d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->crop.x = crop.xy[0]; cfg->crop.y = crop.xy[1]; 8478d546610cba3698c62af537d97e38a7368362f1aLajos Molnar cfg->crop.w = crop.wh[0]; cfg->crop.h = crop.wh[1]; 8488d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8498d546610cba3698c62af537d97e38a7368362f1aLajos Molnar return 0; 8508d546610cba3698c62af537d97e38a7368362f1aLajos Molnar} 8518d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 8522952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnarstatic void 853876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenomap4_hwc_apply_transform(float transform[2][3],struct dss2_ovl_cfg *oc) 8542952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar{ 8552952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar float x, y, w, h; 8562952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 8572952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* display position */ 858876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen x = transform[0][0] * oc->win.x + transform[0][1] * oc->win.y + transform[0][2]; 859876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen y = transform[1][0] * oc->win.x + transform[1][1] * oc->win.y + transform[1][2]; 860876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen w = transform[0][0] * oc->win.w + transform[0][1] * oc->win.h; 861876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen h = transform[1][0] * oc->win.w + transform[1][1] * oc->win.h; 8622952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.x = m_round(w > 0 ? x : x + w); 8632952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.y = m_round(h > 0 ? y : y + h); 8642952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.w = m_round(w > 0 ? w : -w); 8652952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar oc->win.h = m_round(h > 0 ? h : -h); 8662952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar} 8672952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar 8685db21d521ed41e2e2cc110b698981e841e027287Dandawate Saketstatic void 869876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenomap4_hwc_adjust_ext_layer(omap4_hwc_ext_t *ext, struct dss2_ovl_info *ovl) 8705db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket{ 8715db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket struct dss2_ovl_cfg *oc = &ovl->cfg; 8725db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 873876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* crop to clone region if mirroring */ 874876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!ext->current.docking && 875876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen crop_to_rect(&ovl->cfg, ext->mirror_region) != 0) { 8765db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ovl->cfg.enabled = 0; 8775db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket return; 8785db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 8795db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 880876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen omap4_hwc_apply_transform(ext->m, oc); 8815db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 8825db21d521ed41e2e2cc110b698981e841e027287Dandawate 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 */ 883876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->rotation += (oc->mirror ? -1 : 1) * ext->current.rotation; 8845db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket oc->rotation &= 3; 885876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (ext->current.hflip) 886876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->mirror = !oc->mirror; 8875db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket} 888876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 889876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic struct dsscomp_platform_info limits; 890876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 8915db21d521ed41e2e2cc110b698981e841e027287Dandawate Saketstatic void 892876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenomap4_hwc_adjust_primary_display_layer(omap4_hwc_device_t *hwc_dev, struct dss2_ovl_info *ovl) 8935db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket{ 8945db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket struct dss2_ovl_cfg *oc = &ovl->cfg; 8955db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 896876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (crop_to_rect(&ovl->cfg, hwc_dev->primary_region) != 0) { 8975db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ovl->cfg.enabled = 0; 8985db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket return; 8995db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 9005db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 901876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen omap4_hwc_apply_transform(hwc_dev->primary_m, oc); 9025db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 903876331fc77f6763c8c390d1289ead00f89f8d9feMike 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 */ 904876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->rotation += (oc->mirror ? -1 : 1) * hwc_dev->primary_rotation; 905876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen oc->rotation &= 3; 9065db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket} 9075db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 908e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnarstatic int omap4_hwc_can_scale(__u32 src_w, __u32 src_h, __u32 dst_w, __u32 dst_h, int is_2d, 909876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_display_info *dis, struct dsscomp_platform_info *limits, 9104a3fef97a616e47d9b26a8cffa2833f230aba19bTony Lofthouse __u32 pclk, void *handle) 911d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar{ 912d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar __u32 fclk = limits->fclk / 1000; 91316b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar __u32 min_src_w = DIV_ROUND_UP(src_w, is_2d ? limits->max_xdecim_2d : limits->max_xdecim_1d); 91416b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar __u32 min_src_h = DIV_ROUND_UP(src_h, is_2d ? limits->max_ydecim_2d : limits->max_ydecim_1d); 915d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 916d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* ERRATAs */ 917d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* cannot render 1-width layers on DSI video mode panels - we just disallow all 1-width LCD layers */ 918d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (dis->channel != OMAP_DSS_CHANNEL_DIGIT && dst_w < limits->min_width) 919d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 920d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 921d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* NOTE: no support for checking YUV422 layers that are tricky to scale */ 922d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 9231a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian /* FIXME: limit vertical downscale well below theoretical limit as we saw display artifacts */ 9241a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian if (dst_h < src_h / 4) 9251a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian return 0; 9261a45d7e2f85f1e3f3eeef590aa52316376055440Mathias Agopian 927d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* max downscale */ 92816b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar if (dst_h * limits->max_downscale < min_src_h) 929d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 930d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 9314ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar /* for manual panels pclk is 0, and there are no pclk based scaling limits */ 9324ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar if (!pclk) 933b319783cc9e00318eb67b554029bef5932d5436dSunita Nadampalli return !(dst_w < src_w / limits->max_downscale / (is_2d ? limits->max_xdecim_2d : limits->max_xdecim_1d)); 9344ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar 935d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* :HACK: limit horizontal downscale well below theoretical limit as we saw display artifacts */ 93616b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar if (dst_w * 4 < src_w) 937d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 938d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 939b29f69b6b65a33ec0052036e8b6bf0c219cc157eTony Lofthouse if (handle) 940b29f69b6b65a33ec0052036e8b6bf0c219cc157eTony Lofthouse if (get_rgb_bpp(handle) == 32 && src_w > 1280 && dst_w * 3 < src_w) 941b29f69b6b65a33ec0052036e8b6bf0c219cc157eTony Lofthouse return 0; 942b29f69b6b65a33ec0052036e8b6bf0c219cc157eTony Lofthouse 943d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* max horizontal downscale is 4, or the fclk/pixclk */ 944d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (fclk > pclk * limits->max_downscale) 945d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar fclk = pclk * limits->max_downscale; 946d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* for small parts, we need to use integer fclk/pixclk */ 947d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (src_w < limits->integer_scale_ratio_limit) 948d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar fclk = fclk / pclk * pclk; 94916b7f6c4b06ac7350c30309d0559a466097d8ae7Lajos Molnar if ((__u32) dst_w * fclk < min_src_w * pclk) 950d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 0; 951d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 952d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return 1; 953d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar} 954d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 9556ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_can_scale_layer(omap4_hwc_device_t *hwc_dev, hwc_layer_1_t *layer, IMG_native_handle_t *handle) 956d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar{ 9572704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int src_w = WIDTH(layer->sourceCrop); 9582704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int src_h = HEIGHT(layer->sourceCrop); 9592704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int dst_w = WIDTH(layer->displayFrame); 9602704d381ccfba0fe96e61cd368507506c3adfacaLajos Molnar int dst_h = HEIGHT(layer->displayFrame); 961d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 962d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar /* account for 90-degree rotation */ 963d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar if (layer->transform & HWC_TRANSFORM_ROT_90) 964d4599029522592f46eccf9d57add7ebd7d23fdd1Lajos Molnar swap(src_w, src_h); 965d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 9664ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar /* NOTE: layers should be able to be scaled externally since 9674ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar framebuffer is able to be scaled on selected external resolution */ 9685706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar return omap4_hwc_can_scale(src_w, src_h, dst_w, dst_h, is_NV12(handle), &hwc_dev->fb_dis, &limits, 9694a3fef97a616e47d9b26a8cffa2833f230aba19bTony Lofthouse hwc_dev->fb_dis.timings.pixel_clock, handle); 970d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar} 971d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 972d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnarstatic int omap4_hwc_is_valid_layer(omap4_hwc_device_t *hwc_dev, 9736ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer, 974c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_native_handle_t *handle) 975c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 976c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Skip layers are handled by SF */ 977c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if ((layer->flags & HWC_SKIP_LAYER) || !handle) 978c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 979c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 980c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!omap4_hwc_is_valid_format(handle->iFormat)) 981c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 982c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 983c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* 1D buffers: no transform, must fit in TILER slot */ 9845706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar if (!is_NV12(handle)) { 985c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (layer->transform) 986c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 987876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (mem1d(handle) > limits.tiler1d_slot_size) 988c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 989c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 990d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 991d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return omap4_hwc_can_scale_layer(hwc_dev, layer, handle); 992c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 993c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 994e14d52936107e390e2464df1e6653efde5409096Lajos Molnarstatic __u32 add_scaling_score(__u32 score, 995e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 xres, __u32 yres, __u32 refresh, 996e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 ext_xres, __u32 ext_yres, 997e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_xres, __u32 mode_yres, __u32 mode_refresh) 998e14d52936107e390e2464df1e6653efde5409096Lajos Molnar{ 999e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 area = xres * yres; 1000e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 ext_area = ext_xres * ext_yres; 1001e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_area = mode_xres * mode_yres; 1002e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 1003e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* prefer to upscale (1% tolerance) [0..1] (insert after 1st bit) */ 1004e14d52936107e390e2464df1e6653efde5409096Lajos Molnar int upscale = (ext_xres >= xres * 99 / 100 && ext_yres >= yres * 99 / 100); 1005e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (((score & ~1) | upscale) << 1) | (score & 1); 1006e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 1007e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* pick minimum scaling [0..16] */ 1008e14d52936107e390e2464df1e6653efde5409096Lajos Molnar if (ext_area > area) 1009e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 5) | (16 * area / ext_area); 1010e14d52936107e390e2464df1e6653efde5409096Lajos Molnar else 1011e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 5) | (16 * ext_area / area); 1012e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 1013e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* pick smallest leftover area [0..16] */ 1014e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 5) | ((16 * ext_area + (mode_area >> 1)) / mode_area); 1015e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 1016e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* adjust mode refresh rate */ 1017e14d52936107e390e2464df1e6653efde5409096Lajos Molnar mode_refresh += mode_refresh % 6 == 5; 1018e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 1019e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* prefer same or higher frame rate */ 1020e14d52936107e390e2464df1e6653efde5409096Lajos Molnar upscale = (mode_refresh >= refresh); 1021e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 1) | upscale; 1022e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 1023e14d52936107e390e2464df1e6653efde5409096Lajos Molnar /* pick closest frame rate */ 1024e14d52936107e390e2464df1e6653efde5409096Lajos Molnar if (mode_refresh > refresh) 1025e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 8) | (240 * refresh / mode_refresh); 1026e14d52936107e390e2464df1e6653efde5409096Lajos Molnar else 1027e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = (score << 8) | (240 * mode_refresh / refresh); 1028e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 1029e14d52936107e390e2464df1e6653efde5409096Lajos Molnar return score; 1030e14d52936107e390e2464df1e6653efde5409096Lajos Molnar} 1031e14d52936107e390e2464df1e6653efde5409096Lajos Molnar 103204c7041e0dc1e9c7d2c4e1be1e78a092de993c27Lajos Molnarstatic int omap4_hwc_set_best_hdmi_mode(omap4_hwc_device_t *hwc_dev, __u32 xres, __u32 yres, 10331b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar float xpy) 1034bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar{ 10355db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket int dis_ix = hwc_dev->on_tv ? 0 : 1; 1036ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen int forced_preferred_mode = 0; 10375db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 1038bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar struct _qdis { 1039bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar struct dsscomp_display_info dis; 104004512dd8a3fd2830139e3f352a295841c7eed190Travis Geiselbrecht struct dsscomp_videomode modedb[32]; 10415db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } d = { .dis = { .ix = dis_ix } }; 1042ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 1043bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1044bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar d.dis.modedb_len = sizeof(d.modedb) / sizeof(*d.modedb); 1045cb64c2be21ad9550b1f5d2b4a8361e997b9be757Lajos Molnar int ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_DISPLAY, &d); 1046bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (ret) 1047bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar return ret; 1048bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 10496c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar if (d.dis.timings.x_res * d.dis.timings.y_res == 0 || 10506c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar xres * yres == 0) 10516c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar return -EINVAL; 10526c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar 1053bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 i, best = ~0, best_score = 0; 1054ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->width = d.dis.width_in_mm; 1055ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->height = d.dis.height_in_mm; 1056ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->xres = d.dis.timings.x_res; 1057ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->yres = d.dis.timings.y_res; 10583837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 10593837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* use VGA external resolution as default */ 10603837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (!ext->xres || !ext->yres) { 10613837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->xres = 640; 10623837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->yres = 480; 10633837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 10643837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 1065ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* 1066ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht * copy the xres/yres from the preferred mode 1067ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht */ 1068ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht __u32 preferred_mode_xres = 0; 1069ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht __u32 preferred_mode_yres = 0; 1070ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen 1071ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen char value[PROPERTY_VALUE_MAX]; 1072ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (property_get("persist.hwc.preferred_mode", value, "") <= 0 || 1073ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen sscanf(value, "%dx%d", &preferred_mode_xres, 1074ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen &preferred_mode_yres) != 2) { 1075ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen for (i = 0; i < d.dis.modedb_len; i++) { 1076ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (d.modedb[i].flag & FB_FLAG_PREFERRED) { 1077ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen preferred_mode_xres = d.modedb[i].xres; 1078ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen preferred_mode_yres = d.modedb[i].yres; 1079ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen ALOGD("preferred mode %d: xres %u yres %u\n", 1080ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen i, d.modedb[i].xres, d.modedb[i].yres); 1081ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen break; 1082ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen } 1083ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht } 1084ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen } else { 1085ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen ALOGD("forced preferred mode xres %u yres %u\n", 1086ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen preferred_mode_xres, preferred_mode_yres); 1087ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen forced_preferred_mode = 1; 1088ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht } 1089ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1090bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_fb_xres, ext_fb_yres; 1091bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar for (i = 0; i < d.dis.modedb_len; i++) { 1092bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 score = 0; 1093e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_xres = d.modedb[i].xres; 1094e14d52936107e390e2464df1e6653efde5409096Lajos Molnar __u32 mode_yres = d.modedb[i].yres; 1095bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_width = d.dis.width_in_mm; 1096bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_height = d.dis.height_in_mm; 1097bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1098ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* reject it because the hw says it can't actually use this mode */ 1099ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht if ((d.modedb[i].flag & FB_FLAG_HW_CAPABLE) == 0) 1100ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht continue; 1101ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1102620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli if (d.modedb[i].vmode & FB_VMODE_INTERLACED) 1103620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli mode_yres /= 2; 1104620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli 1105bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (d.modedb[i].flag & FB_FLAG_RATIO_4_3) { 1106bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width = 4; 1107bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_height = 3; 1108bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } else if (d.modedb[i].flag & FB_FLAG_RATIO_16_9) { 1109bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width = 16; 1110bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_height = 9; 1111bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1112bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1113e14d52936107e390e2464df1e6653efde5409096Lajos Molnar if (!mode_xres || !mode_yres) 11146c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar continue; 11156c12df17d9a51d20ca799ca22ffee6818d438c94Lajos Molnar 1116e14d52936107e390e2464df1e6653efde5409096Lajos Molnar get_max_dimensions(xres, yres, xpy, mode_xres, mode_yres, 1117bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width, ext_height, &ext_fb_xres, &ext_fb_yres); 1118bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1119f4524c063d4cc4afeb19b08966f51b42257d3acdLajos Molnar /* we need to ensure that even TILER2D buffers can be scaled */ 11204ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar if (!d.modedb[i].pixclock || 1121620a972bf780aff56d3a3c76e8f53ca8b0a3c17dSunita Nadampalli (d.modedb[i].vmode & ~FB_VMODE_INTERLACED) || 11224ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar !omap4_hwc_can_scale(xres, yres, ext_fb_xres, ext_fb_yres, 1123ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 1, &d.dis, &limits, 11244a3fef97a616e47d9b26a8cffa2833f230aba19bTony Lofthouse 1000000000 / d.modedb[i].pixclock, NULL)) 1125bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar continue; 1126bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1127bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar /* prefer CEA modes */ 1128bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (d.modedb[i].flag & (FB_FLAG_RATIO_4_3 | FB_FLAG_RATIO_16_9)) 1129ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht score += 1; 1130ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1131ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* prefer modes that match the preferred mode's resolution */ 1132ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht if (d.modedb[i].xres == preferred_mode_xres && 1133ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht d.modedb[i].yres == preferred_mode_yres) { 1134ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (forced_preferred_mode) 1135ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen score += 10; 1136ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen else 1137ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen score += 1; 1138ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht } 1139ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht 1140ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht /* prefer modes the kernel has hinted is the correct mode */ 1141ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen if (!forced_preferred_mode && (d.modedb[i].flag & FB_FLAG_PREFERRED)) 1142ab9d83c73ae44ed9a8479d17ab4ab6b11354e8c4Travis Geiselbrecht score += 1; 1143bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 11444e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar /* prefer the same mode as we use for mirroring to avoid mode change */ 1145ef2e2467d7c5487cf3be888956adcdc686b03412Mike J. Chen score = (score << 1) | (i == ~ext->mirror_mode && ext->avoid_mode_change); 1146bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1147e14d52936107e390e2464df1e6653efde5409096Lajos Molnar score = add_scaling_score(score, xres, yres, 60, ext_fb_xres, ext_fb_yres, 1148e14d52936107e390e2464df1e6653efde5409096Lajos Molnar mode_xres, mode_yres, d.modedb[i].refresh ? : 1); 1149bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 1150876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGD("#%d: %dx%d %dHz flag 0x%x vmode 0x%x, score 0x%x", 1151876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen i, mode_xres, mode_yres, 1152876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen d.modedb[i].refresh, d.modedb[i].flag, d.modedb[i].vmode, 1153876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen score); 1154876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1155bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (debug) 11563a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD(" score=0x%x adj.res=%dx%d", score, ext_fb_xres, ext_fb_yres); 1157bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (best_score < score) { 1158ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->width = ext_width; 1159ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->height = ext_height; 1160e14d52936107e390e2464df1e6653efde5409096Lajos Molnar ext->xres = mode_xres; 1161e14d52936107e390e2464df1e6653efde5409096Lajos Molnar ext->yres = mode_yres; 1162bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar best = i; 1163bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar best_score = score; 1164bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1165bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1166bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (~best) { 11675db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket struct dsscomp_setup_display_data sdis = { .ix = dis_ix, }; 1168bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar sdis.mode = d.dis.modedb[best]; 11693a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("picking #%d", best); 11704cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar /* only reconfigure on change */ 11715142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen if (ext->last_mode != ~best) { 11725142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen /* set a property that apps that care (e.g. YouTube) can use 11735142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * to determine whether or not to stream lower resolution 11745142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * videos when the hdmi mode is < 1080p. 11755142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * otherwise, they'd give us 1080p and we'd just scale it 11765142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * down to the hdmi mode res. UI apps are always going 11775142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * to draw at 1080p and we'll scale down because the 11785142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen * system can't support dynamic dpi changes. 11795142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen */ 11805142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen char display[PROPERTY_VALUE_MAX]; 11815142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen snprintf(display, sizeof(display), "%dx%d", 11825142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen d.modedb[best].xres, d.modedb[best].yres); 11835142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen ALOGD("setting property sys.display-size to %s", display); 11845142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen property_set("sys.display-size", display); 11855142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen 1186cb64c2be21ad9550b1f5d2b4a8361e997b9be757Lajos Molnar ioctl(hwc_dev->dsscomp_fd, DSSCIOC_SETUP_DISPLAY, &sdis); 11875142031872205241cfc707a7ac9bd77d095ff0f8Mike J. Chen } 11884cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar ext->last_mode = ~best; 1189bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } else { 1190bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_width = d.dis.width_in_mm; 1191bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_height = d.dis.height_in_mm; 1192bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar __u32 ext_fb_xres, ext_fb_yres; 1193bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 11941b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar get_max_dimensions(xres, yres, xpy, d.dis.timings.x_res, d.dis.timings.y_res, 1195bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar ext_width, ext_height, &ext_fb_xres, &ext_fb_yres); 11964ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar if (!d.dis.timings.pixel_clock || 11974ceb627d195b2efb8cfa3612f38cee211436a7a2Lajos Molnar !omap4_hwc_can_scale(xres, yres, ext_fb_xres, ext_fb_yres, 1198ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 1, &d.dis, &limits, 11994a3fef97a616e47d9b26a8cffa2833f230aba19bTony Lofthouse d.dis.timings.pixel_clock, NULL)) { 1200a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("DSS scaler cannot support HDMI cloning"); 1201bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar return -1; 1202bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1203bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar } 1204ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->last_xres_used = xres; 1205ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->last_yres_used = yres; 12061b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->last_xpy = xpy; 1207bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar if (d.dis.channel == OMAP_DSS_CHANNEL_DIGIT) 1208ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->on_tv = 1; 1209bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar return 0; 1210bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar} 1211bd43f27d21c976df59645759598e530ba1a8e01eLajos Molnar 12126ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void gather_layer_statistics(omap4_hwc_device_t *hwc_dev, struct counts *num, hwc_display_contents_1_t *list) 121344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar{ 121444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar unsigned int i; 121544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 121644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar /* Figure out how many layers we can support via DSS */ 121744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar for (i = 0; list && i < list->numHwLayers; i++) { 12186ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer = &list->hwLayers[i]; 121944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 122044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 122144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar layer->compositionType = HWC_FRAMEBUFFER; 122244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 122344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (omap4_hwc_is_valid_layer(hwc_dev, layer, handle)) { 122444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->possible_overlay_layers++; 122544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 122644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar /* NV12 layers can only be rendered on scaling overlays */ 1227876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (scaled(layer) || is_NV12(handle) || hwc_dev->primary_transform) 122844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->scaled_layers++; 122944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 123044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (is_BGR(handle)) 123144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->BGR++; 123244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar else if (is_RGB(handle)) 123344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->RGB++; 123444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar else if (is_NV12(handle)) 123544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->NV12++; 123644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 123744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (dockable(layer)) 123844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->dockable++; 123944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 124044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (is_protected(layer)) 124144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->protected++; 124244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 124344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num->mem += mem1d(handle); 1244c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons 1245c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons if (is_large_rgb32_layer(layer)) 1246c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons num->large_rgb32_layers++; 124744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 124844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 124958aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse hwc_dev->stats = *num; 125044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar} 125144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 125244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnarstatic void decide_supported_cloning(omap4_hwc_device_t *hwc_dev, struct counts *num) 125378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar{ 1254ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 125578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar int nonscaling_ovls = NUM_NONSCALING_OVERLAYS; 125678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays = MAX_HW_OVERLAYS; 125778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 125878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* 125978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * We cannot atomically switch overlays from one display to another. First, they 126078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * have to be disabled, and the disabling has to take effect on the current display. 126178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * We keep track of the available number of overlays here. 126278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar */ 12630aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (ext->dock.enabled && !(ext->mirror.enabled && !(num->dockable || ext->force_dock))) { 126478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* some overlays may already be used by the external display, so we account for this */ 126578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 126678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* reserve just a video pipeline for HDMI if docking */ 12670aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar hwc_dev->ext_ovls = (num->dockable || ext->force_dock) ? 1 : 0; 126878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays -= max(hwc_dev->ext_ovls, hwc_dev->last_ext_ovls); 12691b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar 12701b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar /* use mirroring transform if we are auto-switching to docking mode while mirroring*/ 12711b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar if (ext->mirror.enabled) { 12721b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->current = ext->mirror; 12731b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->current.docking = 1; 12741b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar } else { 12751b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar ext->current = ext->dock; 12761b24d08333d1f847e6211aaa1b81f5792aca2704Lajos Molnar } 1277ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar } else if (ext->mirror.enabled) { 127878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* 127978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * otherwise, manage just from half the pipelines. NOTE: there is 128078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * no danger of having used too many overlays for external display here. 128178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar */ 12826d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket 128378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays >>= 1; 128478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar nonscaling_ovls >>= 1; 128578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = MAX_HW_OVERLAYS - num->max_hw_overlays; 1286ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->current = ext->mirror; 128778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } else { 128878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->max_hw_overlays -= hwc_dev->last_ext_ovls; 128978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = 0; 1290ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->current.enabled = 0; 129178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 129278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 129378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* 129478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * :TRICKY: We may not have enough overlays on the external display. We "reserve" them 129578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * here to figure out if mirroring is supported, but may not do mirroring for the first 129678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar * frame while the overlays required for it are cleared. 129778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar */ 1298bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar hwc_dev->ext_ovls_wanted = hwc_dev->ext_ovls; 129978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = min(MAX_HW_OVERLAYS - hwc_dev->last_int_ovls, hwc_dev->ext_ovls); 130078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1301ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar /* if mirroring, we are limited by both internal and external overlays. However, 1302ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext_ovls is always <= MAX_HW_OVERLAYS / 2 <= max_hw_overlays */ 130358aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse if (!num->protected && hwc_dev->ext_ovls && ext->current.enabled && !ext->current.docking) 1304b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar num->max_hw_overlays = hwc_dev->ext_ovls; 130578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 13066d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket /* If FB is not same resolution as LCD don't use GFX pipe line*/ 1307876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->primary_transform) { 1308876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen num->max_hw_overlays -= NUM_NONSCALING_OVERLAYS; 13096d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket num->max_scaling_overlays = num->max_hw_overlays; 1310876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else 13115db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket num->max_scaling_overlays = num->max_hw_overlays - nonscaling_ovls; 131244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar} 131378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 131425df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmons/* how many large layers can be composited by the DSS */ 131525df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmonsstatic const unsigned int MAX_DSS_LARGE_LAYERS = 2; 131625df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmons 131744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnarstatic int can_dss_render_all(omap4_hwc_device_t *hwc_dev, struct counts *num) 131844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar{ 131944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 13205db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket int on_tv = hwc_dev->on_tv || (ext->on_tv && ext->current.enabled); 132144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar int tform = ext->current.enabled && (ext->current.rotation || ext->current.hflip); 1322ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 13234b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar return !hwc_dev->force_sgx && 13244b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar /* must have at least one layer if using composition bypass to get sync object */ 132578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->possible_overlay_layers && 132678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->possible_overlay_layers <= num->max_hw_overlays && 132778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->possible_overlay_layers == num->composited_layers && 132878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar num->scaled_layers <= num->max_scaling_overlays && 13294af5978e0677b13118611721f265e2dbaba849ffLajos Molnar num->NV12 <= num->max_scaling_overlays && 133038934f125a600817dded7aeba9639c6a75afe358Lajos Molnar /* fits into TILER slot */ 1331876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen num->mem <= limits.tiler1d_slot_size && 133278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* we cannot clone non-NV12 transformed layers */ 13335a87355f6a7ed393d5d8f71bf7aac5f65b87c640Muralidhar Dixit (!tform || (num->NV12 == num->possible_overlay_layers) || 13345a87355f6a7ed393d5d8f71bf7aac5f65b87c640Muralidhar Dixit (num->NV12 && ext->current.docking)) && 133578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* HDMI cannot display BGR */ 1336c4e8e253c404231b74eb318bdb21d7898766f1afJason Simmons (num->BGR == 0 || (num->RGB == 0 && !on_tv) || !hwc_dev->flags_rgb_order) && 133725df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmons /* current hardware can only handle a limited number of 'large' RGB32 layers */ 133825df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmons num->large_rgb32_layers <= MAX_DSS_LARGE_LAYERS; 133978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar} 134078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 134178fce72baff38f488a0117591d4241d278a48b1bLajos Molnarstatic inline int can_dss_render_layer(omap4_hwc_device_t *hwc_dev, 13426ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer) 134378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar{ 134478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 134578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 134644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 1347876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int cloning = ext->current.enabled && (!ext->current.docking || (handle!=NULL ? dockable(layer) : 0)); 1348876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int on_tv = hwc_dev->on_tv || (ext->on_tv && cloning); 1349876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int tform = cloning && (ext->current.rotation || ext->current.hflip); 135078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1351d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar return omap4_hwc_is_valid_layer(hwc_dev, layer, handle) && 13522952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar /* cannot rotate non-NV12 layers on external display */ 13535706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar (!tform || is_NV12(handle)) && 135478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* skip non-NV12 layers if also using SGX (if nv12_only flag is set) */ 13555706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar (!hwc_dev->flags_nv12_only || (!hwc_dev->use_sgx || is_NV12(handle))) && 135678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* make sure RGB ordering is consistent (if rgb_order flag is set) */ 13575706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar (!(hwc_dev->swap_rb ? is_RGB(handle) : is_BGR(handle)) || 135878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar !hwc_dev->flags_rgb_order) && 135978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* TV can only render RGB */ 13605706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar !(on_tv && is_BGR(handle)); 136178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar} 136278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1363834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnarstatic inline int display_area(struct dss2_ovl_info *o) 1364834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar{ 1365834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar return o->cfg.win.w * o->cfg.win.h; 1366834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar} 1367834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 13683837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnarstatic int clone_layer(omap4_hwc_device_t *hwc_dev, int ix) { 1369876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 13703837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 13713837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar int ext_ovl_ix = dsscomp->num_ovls - hwc_dev->post2_layers; 13723837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar struct dss2_ovl_info *o = &dsscomp->ovls[dsscomp->num_ovls]; 13733837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13743837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (dsscomp->num_ovls >= MAX_HW_OVERLAYS) { 137546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** cannot clone layer #%d. using all %d overlays.", ix, dsscomp->num_ovls); 13763837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return -EBUSY; 13773837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 13783837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13793837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar memcpy(o, dsscomp->ovls + ix, sizeof(*o)); 13803837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 13813837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* reserve overlays at end for other display */ 13823837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar o->cfg.ix = MAX_HW_OVERLAYS - 1 - ext_ovl_ix; 13833837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar o->cfg.mgr_ix = 1; 138483f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* 138583f80658d865b741a024515c523e373df50c091eSunita Nadampalli * Here the assumption is that overlay0 is the one attached to FB. 138683f80658d865b741a024515c523e373df50c091eSunita Nadampalli * Hence this clone_layer call is for FB cloning (provided use_sgx is true). 138783f80658d865b741a024515c523e373df50c091eSunita Nadampalli */ 138883f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* For the external displays whose transform is the same as 138983f80658d865b741a024515c523e373df50c091eSunita Nadampalli * that of primary display, ion_handles would be NULL hence 139083f80658d865b741a024515c523e373df50c091eSunita Nadampalli * the below logic doesn't execute. 139183f80658d865b741a024515c523e373df50c091eSunita Nadampalli */ 139283f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ix == 0 && hwc_dev->ion_handles[sync_id%2] && hwc_dev->use_sgx) { 139383f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->addressing = OMAP_DSS_BUFADDR_ION; 139483f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->ba = (int)hwc_dev->ion_handles[sync_id%2]; 139583f80658d865b741a024515c523e373df50c091eSunita Nadampalli } else { 139683f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->addressing = OMAP_DSS_BUFADDR_OVL_IX; 139783f80658d865b741a024515c523e373df50c091eSunita Nadampalli o->ba = ix; 139883f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 13993837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14003837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* use distinct z values (to simplify z-order checking) */ 14013837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar o->cfg.zorder += hwc_dev->post2_layers; 14023837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14033837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_adjust_ext_layer(&hwc_dev->ext, o); 14043837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar dsscomp->num_ovls++; 14053837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return 0; 14063837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar} 14073837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14083837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnarstatic int clone_external_layer(omap4_hwc_device_t *hwc_dev, int ix) { 1409876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 14103837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 14113837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14123837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* mirror only 1 external layer */ 14133837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar struct dss2_ovl_info *o = &dsscomp->ovls[ix]; 14143837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14153837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* full screen video after transformation */ 14163837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar __u32 xres = o->cfg.crop.w, yres = o->cfg.crop.h; 14173837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if ((ext->current.rotation + o->cfg.rotation) & 1) 14183837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar swap(xres, yres); 14193837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar float xpy = ext->lcd_xpy * o->cfg.win.w / o->cfg.win.h; 14203837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (o->cfg.rotation & 1) 14213837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy = o->cfg.crop.h / xpy / o->cfg.crop.w; 14223837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar else 14233837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy = o->cfg.crop.h * xpy / o->cfg.crop.w; 14243837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.rotation & 1) 14253837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy = 1. / xpy; 14263837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14273837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* adjust hdmi mode based on resolution */ 14283837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (xres != ext->last_xres_used || 14293837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar yres != ext->last_yres_used || 14303837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy < ext->last_xpy * (1.f - ASPECT_RATIO_TOLERANCE) || 14313837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar xpy * (1.f - ASPECT_RATIO_TOLERANCE) > ext->last_xpy) { 14323a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve Block ALOGD("set up HDMI for %d*%d\n", xres, yres); 14333837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (omap4_hwc_set_best_hdmi_mode(hwc_dev, xres, yres, xpy)) { 14343837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->current.enabled = 0; 14353837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return -ENODEV; 14363837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 14373837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } 14383837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14393837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar struct hwc_rect region = { 14403837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar .left = o->cfg.win.x, .top = o->cfg.win.y, 14413837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar .right = o->cfg.win.x + o->cfg.win.w, 14423837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar .bottom = o->cfg.win.y + o->cfg.win.h 14433837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar }; 14443837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar set_ext_matrix(&hwc_dev->ext, region); 14453837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14463837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return clone_layer(hwc_dev, ix); 14473837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar} 14483837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14493837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnarstatic int setup_mirroring(omap4_hwc_device_t *hwc_dev) 14503837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar{ 14513837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 14523837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14533837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar __u32 xres = WIDTH(ext->mirror_region); 14543837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar __u32 yres = HEIGHT(ext->mirror_region); 14553837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.rotation & 1) 14563837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar swap(xres, yres); 14573837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (omap4_hwc_set_best_hdmi_mode(hwc_dev, xres, yres, ext->lcd_xpy)) 14583837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return -ENODEV; 14593837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar set_ext_matrix(ext, ext->mirror_region); 14603837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar return 0; 14613837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar} 14623837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 14636ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden/* 14646ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden * We're using "implicit" synchronization, so make sure we aren't passing any 14656ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden * sync object descriptors around. 14666ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden */ 14676ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void check_sync_fds(size_t numDisplays, hwc_display_contents_1_t** displays) 14686ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden{ 14696ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden //ALOGD("checking sync FDs"); 14706ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden unsigned int i, j; 14716ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden for (i = 0; i < numDisplays; i++) { 14726ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t* list = displays[i]; 14733d6b69f0a0fb325443ef8c2987c16af1f8618d3eJesse Hall if (list->retireFenceFd >= 0) { 14743d6b69f0a0fb325443ef8c2987c16af1f8618d3eJesse Hall ALOGW("retireFenceFd[%u] was %d", i, list->retireFenceFd); 14753d6b69f0a0fb325443ef8c2987c16af1f8618d3eJesse Hall list->retireFenceFd = -1; 14766ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14776ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 14786ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden for (j = 0; j < list->numHwLayers; j++) { 14796ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t* layer = &list->hwLayers[j]; 14806ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (layer->acquireFenceFd >= 0) { 14816ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden ALOGW("acquireFenceFd[%u][%u] was %d, closing", i, j, layer->acquireFenceFd); 14826ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden close(layer->acquireFenceFd); 14836ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden layer->acquireFenceFd = -1; 14846ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14856ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (layer->releaseFenceFd >= 0) { 14866ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden ALOGW("releaseFenceFd[%u][%u] was %d", i, j, layer->releaseFenceFd); 14876ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden layer->releaseFenceFd = -1; 14886ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14896ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14906ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 14916ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden} 14926ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 1493876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic void blit_reset(omap4_hwc_device_t *hwc_dev, int flags) 1494876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 1495876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_flags = 0; 1496876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_num = 0; 1497876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->post2_blit_buffers = 0; 1498876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->comp_data.blit_data.rgz_items = 0; 1499876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1500876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* We want to maintain the rgz dirty region data if there are no geometry changes */ 1501876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (flags & HWC_GEOMETRY_CHANGED) 1502876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_release(&grgz); 1503876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen} 1504876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1505284005c3a0e0b21f28febca5ad1dd647f912d9feJason Simmonsstatic int blit_layers(omap4_hwc_device_t *hwc_dev, hwc_display_contents_1_t *list, int bufoff) 1506876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 1507876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Do not blit if this frame will be composed entirely by the GPU */ 1508876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!list || hwc_dev->force_sgx) 1509876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1510876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1511876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int rgz_in_op; 1512876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int rgz_out_op; 1513876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1514876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen switch (hwc_dev->blt_mode) { 1515876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen case BLTMODE_PAINT: 1516876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_in_op = RGZ_IN_HWCCHK; 1517876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_out_op = RGZ_OUT_BVCMD_PAINT; 1518876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen break; 1519876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen case BLTMODE_REGION: 1520876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen default: 1521876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_in_op = RGZ_IN_HWC; 1522876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_out_op = RGZ_OUT_BVCMD_REGION; 1523876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen break; 1524876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1525876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1526876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_in_params_t in = { 1527876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .op = rgz_in_op, 1528876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .data = { 1529876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .hwc = { 1530876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .dstgeom = &gscrngeom, 1531876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .layers = list->hwLayers, 1532876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .layerno = list->numHwLayers 1533876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1534876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1535876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen }; 1536876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1537876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* 1538876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * This means if all the layers marked for the FRAMEBUFFER cannot be 1539876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * blitted, do not blit, for e.g. SKIP layers 1540876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1541876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_in(&in, &grgz) != RGZ_ALL) 1542876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1543876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1544876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int i, count = 0; 1545876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < list->numHwLayers; i++) { 1546876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (list->hwLayers[i].compositionType != HWC_OVERLAY) { 1547876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen count++; 1548876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1549876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1550876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1551876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_out_params_t out = { 1552876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .op = rgz_out_op, 1553876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .data = { 1554876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .bvc = { 1555876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .dstgeom = &gscrngeom, 1556876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen .noblend = 0, 1557876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1558876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1559876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen }; 1560876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1561876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_out(&grgz, &out) != 0) { 1562876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("Failed generating blits"); 1563876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1564876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1565876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1566876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* This is a special situation where the regionizer decided no blits are 1567876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * needed for this frame but there are blit buffers to synchronize with. Can 1568876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * happen only if the regionizer is enabled otherwise it's likely a bug 1569876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1570876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_out_op != RGZ_OUT_BVCMD_REGION && out.data.bvc.out_blits == 0 && out.data.bvc.out_nhndls > 0) { 1571876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("Regionizer invalid output blit_num %d, post2_blit_buffers %d", out.data.bvc.out_blits, out.data.bvc.out_nhndls); 1572876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto err_out; 1573876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1574876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1575876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_flags |= HWC_BLT_FLAG_USE_FB; 1576876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_num = out.data.bvc.out_blits; 1577876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->post2_blit_buffers = out.data.bvc.out_nhndls; 1578876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < hwc_dev->post2_blit_buffers; i++) { 1579876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen //ALOGI("blit buffers[%d] = %p", bufoff, out.data.bvc.out_hndls[i]); 1580876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers[bufoff++] = out.data.bvc.out_hndls[i]; 1581876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1582876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1583876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct rgz_blt_entry *res_blit_ops = (struct rgz_blt_entry *) out.data.bvc.cmdp; 1584876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen memcpy(hwc_dev->comp_data.blit_data.rgz_blts, res_blit_ops, sizeof(*res_blit_ops) * out.data.bvc.cmdlen); 1585876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI_IF(debugblt, "blt struct sz %d", sizeof(*res_blit_ops) * out.data.bvc.cmdlen); 1586876331fc77f6763c8c390d1289ead00f89f8d9feMike 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); 1587876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1588876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* all layers will be rendered without SGX help either via DSS or blitter */ 1589876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < list->numHwLayers; i++) { 1590876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (list->hwLayers[i].compositionType != HWC_OVERLAY) { 1591876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen list->hwLayers[i].compositionType = HWC_OVERLAY; 1592876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen //ALOGI("blitting layer %d", i); 1593a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse list->hwLayers[i].hints &= ~HWC_HINT_TRIPLE_BUFFER; 1594876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1595876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen list->hwLayers[i].hints &= ~HWC_HINT_CLEAR_FB; 1596876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1597876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return 1; 1598876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1599876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenerr_out: 1600876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen rgz_release(&grgz); 1601876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return 0; 1602876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen} 1603876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1604876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenvoid debug_post2(omap4_hwc_device_t *hwc_dev, int nbufs) 1605876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 1606876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!debugpost2) 1607876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen return; 1608876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 1609876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int i; 1610876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i=0; i<nbufs; i++) { 1611876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("buf[%d] hndl %p", i, hwc_dev->buffers[i]); 1612876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1613876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i=0; i < dsscomp->num_ovls; i++) { 1614876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("ovl[%d] ba %d", i, dsscomp->ovls[i].ba); 1615876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1616876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen} 1617876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 161883f80658d865b741a024515c523e373df50c091eSunita Nadampallistatic int free_tiler2d_buffers(omap4_hwc_device_t *hwc_dev) 161983f80658d865b741a024515c523e373df50c091eSunita Nadampalli{ 162083f80658d865b741a024515c523e373df50c091eSunita Nadampalli int i; 162183f80658d865b741a024515c523e373df50c091eSunita Nadampalli 162283f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0 ; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 162383f80658d865b741a024515c523e373df50c091eSunita Nadampalli ion_free(hwc_dev->ion_fd, hwc_dev->ion_handles[i]); 162483f80658d865b741a024515c523e373df50c091eSunita Nadampalli hwc_dev->ion_handles[i] = NULL; 162583f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 162683f80658d865b741a024515c523e373df50c091eSunita Nadampalli return 0; 162783f80658d865b741a024515c523e373df50c091eSunita Nadampalli} 162883f80658d865b741a024515c523e373df50c091eSunita Nadampalli 162983f80658d865b741a024515c523e373df50c091eSunita Nadampallistatic int allocate_tiler2d_buffers(omap4_hwc_device_t *hwc_dev) 163083f80658d865b741a024515c523e373df50c091eSunita Nadampalli{ 163183f80658d865b741a024515c523e373df50c091eSunita Nadampalli int ret, i; 163283f80658d865b741a024515c523e373df50c091eSunita Nadampalli size_t stride; 163383f80658d865b741a024515c523e373df50c091eSunita Nadampalli 163483f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_fd < 0) { 163583f80658d865b741a024515c523e373df50c091eSunita Nadampalli ALOGE("No ion fd, hence can't allocate tiler2d buffers"); 163683f80658d865b741a024515c523e373df50c091eSunita Nadampalli return -1; 163783f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 163883f80658d865b741a024515c523e373df50c091eSunita Nadampalli 163983f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 164083f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_handles[i]) 164183f80658d865b741a024515c523e373df50c091eSunita Nadampalli return 0; 164283f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 164383f80658d865b741a024515c523e373df50c091eSunita Nadampalli 164483f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0 ; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 164583f80658d865b741a024515c523e373df50c091eSunita Nadampalli ret = ion_alloc_tiler(hwc_dev->ion_fd, hwc_dev->fb_dev->base.width, hwc_dev->fb_dev->base.height, 164683f80658d865b741a024515c523e373df50c091eSunita Nadampalli TILER_PIXEL_FMT_32BIT, 0, &hwc_dev->ion_handles[i], &stride); 164783f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ret) 164883f80658d865b741a024515c523e373df50c091eSunita Nadampalli goto handle_error; 164983f80658d865b741a024515c523e373df50c091eSunita Nadampalli 165083f80658d865b741a024515c523e373df50c091eSunita Nadampalli ALOGI("ion handle[%d][%p]", i, hwc_dev->ion_handles[i]); 165183f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 165283f80658d865b741a024515c523e373df50c091eSunita Nadampalli return 0; 165383f80658d865b741a024515c523e373df50c091eSunita Nadampalli 165483f80658d865b741a024515c523e373df50c091eSunita Nadampallihandle_error: 165583f80658d865b741a024515c523e373df50c091eSunita Nadampalli free_tiler2d_buffers(hwc_dev); 165683f80658d865b741a024515c523e373df50c091eSunita Nadampalli return -1; 165783f80658d865b741a024515c523e373df50c091eSunita Nadampalli} 165883f80658d865b741a024515c523e373df50c091eSunita Nadampalli 16596ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_prepare(struct hwc_composer_device_1 *dev, size_t numDisplays, 16606ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t** displays) 1661c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 16626ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (!numDisplays || displays == NULL) { 16636ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden return 0; 16646ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 16656ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 16666ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t* list = displays[0]; // ignore displays beyond the first 1667c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *)dev; 1668876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 16690b62b7ca3c6430caaebb2d3815642b2ff80f527aLajos Molnar struct counts num = { .composited_layers = list ? list->numHwLayers : 0 }; 16703837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar unsigned int i, ix; 1671c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 16722125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_lock(&hwc_dev->lock); 1673c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev memset(dsscomp, 0x0, sizeof(*dsscomp)); 1674c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev dsscomp->sync_id = sync_id++; 1675c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 167644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar gather_layer_statistics(hwc_dev, &num, list); 1677834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 167844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar decide_supported_cloning(hwc_dev, &num); 1679c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 168078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* phase 3 logic */ 16814b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar if (can_dss_render_all(hwc_dev, &num)) { 1682c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* All layers can be handled by the DSS -- don't use SGX for composition */ 1683c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->use_sgx = 0; 168478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->swap_rb = num.BGR != 0; 1685c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } else { 1686c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Use SGX for composition plus first 3 layers that are DSS renderable */ 1687c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->use_sgx = 1; 16885706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar hwc_dev->swap_rb = is_BGR_format(hwc_dev->fb_dev->base.format); 1689c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1690c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1691c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* setup pipes */ 1692c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int z = 0; 1693a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar int fb_z = -1; 1694c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int scaled_gfx = 0; 1695834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar int ix_docking = -1; 169625df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmons unsigned int big_layers = 0; 1697c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1698876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int blit_all = 0; 16992acde915b4868129963ef7dc7afe1f3b35ffeeacJon Pry blit_reset(hwc_dev, list ? list->flags : 0); 1700876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1701876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* If the SGX is used or we are going to blit something we need a framebuffer 1702876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * and a DSS pipe 1703876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1704876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int needs_fb = hwc_dev->use_sgx; 1705876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1706876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->blt_policy == BLTPOLICY_ALL) { 1707876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Check if we can blit everything */ 1708876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen blit_all = blit_layers(hwc_dev, list, 0); 1709876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (blit_all) { 1710876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen needs_fb = 1; 1711876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->use_sgx = 0; 1712876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1713876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1714876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1715876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* If a framebuffer is needed, begin using VID1 for DSS overlay layers, 1716876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * we need GFX for FB 1717876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1718876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->num_ovls = needs_fb ? 1 /*VID1*/ : 0 /*GFX*/; 1719876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1720c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* set up if DSS layers */ 172138934f125a600817dded7aeba9639c6a75afe358Lajos Molnar unsigned int mem_used = 0; 1722876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; list && i < list->numHwLayers && !blit_all; i++) { 17236ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_layer_1_t *layer = &list->hwLayers[i]; 1724c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_native_handle_t *handle = (IMG_native_handle_t *)layer->handle; 1725c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 17264b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar if (dsscomp->num_ovls < num.max_hw_overlays && 1727a1be32cc5c3978f9bac62c3b40a257bba2315861Lajos Molnar can_dss_render_layer(hwc_dev, layer) && 17284b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar (!hwc_dev->force_sgx || 17294b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar /* render protected and dockable layers via DSS */ 17305706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar is_protected(layer) || 1731f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar is_upscaled_NV12(hwc_dev, layer) || 17324b267e18b9e98b788d2b1bf2f1268ed25e5b726dLajos Molnar (hwc_dev->ext.current.docking && hwc_dev->ext.current.enabled && dockable(layer))) && 17338594f3edb1632ad900d7a5f06e2819e65114924bGustavo Diaz Prado mem_used + mem1d(handle) <= limits.tiler1d_slot_size && 1734c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* can't have a transparent overlay in the middle of the framebuffer stack */ 1735fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht !(is_BLENDED(layer) && fb_z >= 0) && 173625df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmons /* current hardware can only handle a limited number of 'large' RGB32 layers */ 173725df2c673b1cdecd6d97f5c46905f58a834c9bddJason Simmons !(is_large_rgb32_layer(layer) && big_layers >= MAX_DSS_LARGE_LAYERS)) { 17385706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 1739c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* render via DSS overlay */ 174038934f125a600817dded7aeba9639c6a75afe358Lajos Molnar mem_used += mem1d(handle); 1741c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev layer->compositionType = HWC_OVERLAY; 1742a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse /* 1743a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse * This hint will not be used in vanilla ICS, but maybe in 1744a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse * JellyBean, it is useful to distinguish between blts and true 1745a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse * overlays 1746a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse */ 1747a718b61ddb61e613cef6f0053624b20d151da6eaTony Lofthouse layer->hints |= HWC_HINT_TRIPLE_BUFFER; 1748b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar 1749b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar /* clear FB above all opaque layers if rendering via SGX */ 1750b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar if (hwc_dev->use_sgx && !is_BLENDED(layer)) 1751b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar layer->hints |= HWC_HINT_CLEAR_FB; 1752b81fb68ce4c70170ebc9e41f9fe4540cc05685d5Lajos Molnar 1753e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar hwc_dev->buffers[dsscomp->num_ovls] = layer->handle; 1754c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1755c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_setup_layer(hwc_dev, 1756c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev &dsscomp->ovls[dsscomp->num_ovls], 1757f1e357b2cf26fa5a50789061e068e4f0bd4ea772Mathias Agopian layer, 1758c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev z, 1759c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev handle->iFormat, 1760c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev handle->iWidth, 1761c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev handle->iHeight); 1762d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 1763876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[dsscomp->num_ovls].cfg.ix = dsscomp->num_ovls + hwc_dev->primary_transform; 176412c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[dsscomp->num_ovls].addressing = OMAP_DSS_BUFADDR_LAYER_IX; 176512c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[dsscomp->num_ovls].ba = dsscomp->num_ovls; 1766c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1767c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* ensure GFX layer is never scaled */ 1768876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if ((dsscomp->num_ovls == 0) && (!hwc_dev->primary_transform)) { 1769876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen scaled_gfx = scaled(layer) || is_NV12(handle); 1770876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else if (scaled_gfx && !scaled(layer) && !is_NV12(handle)) { 1771c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* swap GFX layer with this one */ 1772c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev dsscomp->ovls[dsscomp->num_ovls].cfg.ix = 0; 1773876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[0].cfg.ix = dsscomp->num_ovls; 1774c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev scaled_gfx = 0; 1775c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1776c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1777834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar /* remember largest dockable layer */ 1778834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar if (dockable(layer) && 1779834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar (ix_docking < 0 || 178000d8485d3d319633f410e52cab1562fe165af1e3Lajos Molnar display_area(&dsscomp->ovls[dsscomp->num_ovls]) > display_area(&dsscomp->ovls[ix_docking]))) 1781834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar ix_docking = dsscomp->num_ovls; 178278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 1783c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev dsscomp->num_ovls++; 1784c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev z++; 1785fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht 1786fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht /* record whether or not this was a 'big' RGB32 layer */ 1787fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht if (is_large_rgb32_layer(layer)) { 1788fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht big_layers++; 1789fc13c9292160e3eb83fe5b4f191d1ccee2fd67d9Travis Geiselbrecht } 1790c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } else if (hwc_dev->use_sgx) { 1791c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (fb_z < 0) { 1792c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* NOTE: we are not handling transparent cutout for now */ 1793a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar fb_z = z; 1794c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev z++; 1795c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } else { 1796c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* move fb z-order up (by lowering dss layers) */ 1797a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar while (fb_z < z - 1) 1798a51ba32b3ed323a74235d28a6cb0f31e51d8e514Lajos Molnar dsscomp->ovls[1 + fb_z++].cfg.zorder--; 1799c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1800c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1801c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1802c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1803c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* if scaling GFX (e.g. only 1 scaled surface) use a VID pipe */ 1804c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (scaled_gfx) 1805876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[0].cfg.ix = dsscomp->num_ovls; 1806876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1807876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->blt_policy == BLTPOLICY_DEFAULT) { 1808876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->use_sgx) { 1809876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (blit_layers(hwc_dev, list, dsscomp->num_ovls == 1 ? 0 : dsscomp->num_ovls)) { 1810876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->use_sgx = 0; 1811876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1812876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1813876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1814c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 1815876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* If the SGX is not used and there is blit data we need a framebuffer and 1816876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * a DSS pipe well configured for it 1817876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 1818876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (needs_fb) { 1819b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar /* assign a z-layer for fb */ 1820449e98a958753e6ae8f16b923596af0c6783ff8aLajos Molnar if (fb_z < 0) { 1821876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!hwc_dev->blt_policy != BLTPOLICY_DISABLED && num.composited_layers) 18226d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket ALOGE("**** should have assigned z-layer for fb"); 1823449e98a958753e6ae8f16b923596af0c6783ff8aLajos Molnar fb_z = z++; 1824449e98a958753e6ae8f16b923596af0c6783ff8aLajos Molnar } 1825876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* 1826876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * This is needed because if we blit all we would lose the handle of 1827876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * the first layer 1828876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 18292d7bd1ee60dd7a35573728c17fcae49999f8edd9Gustavo Diaz Prado if (hwc_dev->use_sgx) { 1830876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers[0] = NULL; 1831876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1832c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_setup_layer_base(&dsscomp->ovls[0].cfg, fb_z, 1833c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev->base.format, 18345706ba0da054830e63b82b195ec32a97c390bd2cLajos Molnar 1, /* FB is always premultiplied */ 1835c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev->base.width, 1836c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev->base.height); 1837c35f8ef2dc4bf1606f2b27f750057b12e51cb99aErik Gilling dsscomp->ovls[0].cfg.pre_mult_alpha = 1; 183812c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[0].addressing = OMAP_DSS_BUFADDR_LAYER_IX; 183912c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[0].ba = 0; 1840876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[0].cfg.ix = hwc_dev->primary_transform; 1841c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 1842c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 184378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar /* mirror layers */ 184478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->post2_layers = dsscomp->num_ovls; 18453837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar 18463837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 18473837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.enabled && hwc_dev->ext_ovls) { 18483837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.docking && ix_docking >= 0) { 1849876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (clone_external_layer(hwc_dev, ix_docking) == 0) 185012c821dbf70ee94bd9702e7cb60c66c8156c83d6Erik Gilling dsscomp->ovls[dsscomp->num_ovls - 1].cfg.zorder = z++; 18510aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } else if (ext->current.docking && ix_docking < 0 && ext->force_dock) { 18520aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar ix_docking = dsscomp->num_ovls; 18530aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar struct dss2_ovl_info *oi = &dsscomp->ovls[ix_docking]; 18540aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar omap4_hwc_setup_layer_base(&oi->cfg, 0, HAL_PIXEL_FORMAT_BGRA_8888, 1, 18550aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar dock_image.width, dock_image.height); 18560aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar oi->cfg.stride = dock_image.rowbytes; 18570aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (clone_external_layer(hwc_dev, ix_docking) == 0) { 18580aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar oi->addressing = OMAP_DSS_BUFADDR_FB; 18590aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar oi->ba = 0; 18600aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar z++; 18610aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 18623837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar } else if (!ext->current.docking) { 18633837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar int res = 0; 1864834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 1865834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar /* reset mode if we are coming from docking */ 18663837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->last.docking) 18673837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar res = setup_mirroring(hwc_dev); 1868c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 18693837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar /* mirror all layers */ 18703837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar for (ix = 0; res == 0 && ix < hwc_dev->post2_layers; ix++) { 18713837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (clone_layer(hwc_dev, ix)) 18723837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar break; 18733837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar z++; 18742952fd7510718abf21a5fc6d683fd1b4a6025171Lajos Molnar } 187578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 187678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 1877876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 1878876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Apply transform for primary display */ 1879876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->primary_transform) 1880876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < dsscomp->num_ovls; i++) { 1881876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if(dsscomp->ovls[i].cfg.mgr_ix == 0) 1882876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen omap4_hwc_adjust_primary_display_layer(hwc_dev, &dsscomp->ovls[i]); 1883876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 1884876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 18853837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->last = ext->current; 188678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 188778fce72baff38f488a0117591d4241d278a48b1bLajos Molnar if (z != dsscomp->num_ovls || dsscomp->num_ovls > MAX_HW_OVERLAYS) 188846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** used %d z-layers for %d overlays\n", z, dsscomp->num_ovls); 188978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 189044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar /* verify all z-orders and overlay indices are distinct */ 189144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar for (i = z = ix = 0; i < dsscomp->num_ovls; i++) { 189244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar struct dss2_ovl_cfg *c = &dsscomp->ovls[i].cfg; 189344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 189444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (z & (1 << c->zorder)) 189546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** used z-order #%d multiple times", c->zorder); 189644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (ix & (1 << c->ix)) 189746de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("**** used ovl index #%d multiple times", c->ix); 189844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar z |= 1 << c->zorder; 189944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ix |= 1 << c->ix; 190044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 190178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mode = DSSCOMP_SETUP_DISPLAY; 190278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[0].ix = 0; 190378fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[0].alpha_blending = 1; 190478fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[0].swap_rb = hwc_dev->swap_rb; 190578fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->num_mgrs = 1; 190678fce72baff38f488a0117591d4241d278a48b1bLajos Molnar 19073837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (ext->current.enabled || hwc_dev->last_ext_ovls) { 190878fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[1] = dsscomp->mgrs[0]; 190978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->mgrs[1].ix = 1; 191078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar dsscomp->num_mgrs++; 191178fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->ext_ovls = dsscomp->num_ovls - hwc_dev->post2_layers; 191278fce72baff38f488a0117591d4241d278a48b1bLajos Molnar } 191344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 1914b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket /* 1915b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket * Whilst the mode of the display is being changed drop compositions to the 1916b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket * display 1917b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket */ 1918b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket if (ext->last_mode == 0 && hwc_dev->on_tv) { 1919b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket dsscomp->num_ovls = 0; 1920b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket } 1921b05c5715bd7f2321c9783a2943a8b98c719944c8Dandawate Saket 192244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar if (debug) { 19233a7df2c042eb8c7289e24e77dd316f73bd0c456fSteve 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", 192444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar dsscomp->sync_id, 192544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar hwc_dev->use_sgx ? "SGX+OVL" : "all-OVL", 192644a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num.composited_layers, 192744a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num.possible_overlay_layers, num.scaled_layers, 192844a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar num.RGB, num.BGR, num.NV12, 192944a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->on_tv ? "tv+" : "", 193044a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->current.enabled ? ext->current.docking ? "dock+" : "mirror+" : "OFF+", 193144a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->current.rotation * 90, 193244a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar ext->current.hflip ? "+hflip" : "", 193344a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar hwc_dev->ext_ovls, num.max_hw_overlays, hwc_dev->last_ext_ovls, hwc_dev->last_int_ovls); 193444a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar } 193544a0023db5b752a81fb0bd3badd4cca1a1c4edc0Lajos Molnar 19362125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_unlock(&hwc_dev->lock); 1937c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 1938c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 1939c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 194024a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnarstatic void omap4_hwc_reset_screen(omap4_hwc_device_t *hwc_dev) 194124a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar{ 194224a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar static int first_set = 1; 194324a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar int ret; 194424a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 194524a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (first_set) { 194624a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar first_set = 0; 194724a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar struct dsscomp_setup_dispc_data d = { 1948b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar .num_mgrs = 1, 194924a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar }; 195024a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar /* remove bootloader image from the screen as blank/unblank does not change the composition */ 1951cb64c2be21ad9550b1f5d2b4a8361e997b9be757Lajos Molnar ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_SETUP_DISPC, &d); 195224a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (ret) 1953a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("failed to remove bootloader image"); 195424a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 195524a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar /* blank and unblank fd to make sure display is properly programmed on boot. 195624a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar * This is needed because the bootloader can not be trusted. 195724a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar */ 195824a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar ret = ioctl(hwc_dev->fb_fd, FBIOBLANK, FB_BLANK_POWERDOWN); 195924a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (ret) 1960a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("failed to blank display"); 196124a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 196224a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar ret = ioctl(hwc_dev->fb_fd, FBIOBLANK, FB_BLANK_UNBLANK); 196324a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar if (ret) 1964a4e4aeab47b17a82524ac56f2d69daa3e47c1ce7Steve Block ALOGW("failed to blank display"); 196524a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar } 196624a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar} 196724a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 19686ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_set(struct hwc_composer_device_1 *dev, 19696ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden size_t numDisplays, hwc_display_contents_1_t** displays) 1970c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 19716ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (!numDisplays || displays == NULL) { 19726ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden ALOGD("set: empty display list"); 19736ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden return 0; 19746ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 19756ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_t dpy = NULL; 19766ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_surface_t sur = NULL; 19776ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_display_contents_1_t* list = displays[0]; // ignore displays beyond the first 19786ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden if (list != NULL) { 19796ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden dpy = list->dpy; 19806ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden sur = list->sur; 19816ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden } 1982c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *)dev; 1983876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 1984ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar int err = 0; 1985bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar int invalidate; 1986c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 19872125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_lock(&hwc_dev->lock); 198824a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 198927843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht /* disable resetting the screen on the first boot for devices 199027843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht * with hdmi as primary input. 199127843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht */ 199227843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht if (!hwc_dev->on_tv) 199327843d0acbb3d17ec4458900b6cd5e281a464611Travis Geiselbrecht omap4_hwc_reset_screen(hwc_dev); 199424a18d2f746877f2abd63e95b4be9c54dac4472eLajos Molnar 199558aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse invalidate = hwc_dev->ext_ovls_wanted && (hwc_dev->ext_ovls < hwc_dev->ext_ovls_wanted) && 199658aa32dc9d23875627e39f16831ffb471baf7890Tony Lofthouse (hwc_dev->stats.protected || !hwc_dev->ext_ovls); 1997bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar 1998734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar if (debug) 1999734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_set_info(hwc_dev, list); 2000c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2001ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar if (dpy && sur) { 2002e37a11c21bcac1fbcac995cd34884eac37492b95Mathias Agopian // list can be NULL which means hwc is temporarily disabled. 2003e37a11c21bcac1fbcac995cd34884eac37492b95Mathias Agopian // however, if dpy and sur are null it means we're turning the 2004e37a11c21bcac1fbcac995cd34884eac37492b95Mathias Agopian // screen off. no shall not call eglSwapBuffers() in that case. 2005ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar 2006ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar if (hwc_dev->use_sgx) { 2007ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar if (!eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur)) { 200846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("eglSwapBuffers error"); 2009ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar err = HWC_EGL_ERROR; 2010ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar goto err_out; 2011ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar } 2012c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2013c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2014ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar //dump_dsscomp(dsscomp); 2015c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 201602150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian // signal the event thread that a post has happened 2017751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen wakeup_hdmi_thread(hwc_dev); 201802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (hwc_dev->force_sgx > 0) 201902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian hwc_dev->force_sgx--; 202002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 2021876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->comp_data.blit_data.rgz_flags = hwc_dev->blit_flags; 2022876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->comp_data.blit_data.rgz_items = hwc_dev->blit_num; 2023876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int omaplfb_comp_data_sz = sizeof(hwc_dev->comp_data) + 2024876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen (hwc_dev->comp_data.blit_data.rgz_items * sizeof(struct rgz_blt_entry)); 2025876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2026876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2027876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int nbufs = hwc_dev->post2_layers; 2028876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_blit_buffers) { 2029876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* 2030876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * We don't want to pass a NULL entry in the Post2, but we need to 2031876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * fix up buffer handle array and overlay indexes to account for 2032876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen * this 2033876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen */ 2034876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen nbufs += hwc_dev->post2_blit_buffers - 1; 2035876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2036876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->post2_layers > 1) { 2037876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen unsigned int i, j; 2038876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 0; i < nbufs; i++) { 2039876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers[i] = hwc_dev->buffers[i+1]; 2040876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2041876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen for (i = 1, j= 1; j < hwc_dev->post2_layers; i++, j++) { 2042876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp->ovls[j].ba = i; 2043876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2044876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2045876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2046876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI_IF(debugblt && hwc_dev->blt_policy != BLTPOLICY_DISABLED, 2047876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen "Post2, blits %d, ovl_buffers %d, blit_buffers %d sgx %d", 2048876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blit_num, hwc_dev->post2_layers, hwc_dev->post2_blit_buffers, 2049876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->use_sgx); 2050876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2051876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen debug_post2(hwc_dev, nbufs); 2052ee0725d529a6adced20dd0182f9fd470607ce495Lajos Molnar err = hwc_dev->fb_dev->Post2((framebuffer_device_t *)hwc_dev->fb_dev, 2053c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->buffers, 2054876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen nbufs, 2055876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dsscomp, omaplfb_comp_data_sz); 20561fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse showfps(); 20571fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 2058876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#if 0 2059876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (!hwc_dev->use_sgx) { 2060876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen __u32 crt = 0; 2061876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int err2 = ioctl(hwc_dev->fb_fd, FBIO_WAITFORVSYNC, &crt); 2062876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (err2) { 2063876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("failed to wait for vsync (%d)", errno); 2064876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen err = err ? : -errno; 2065876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2066876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2067876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen#endif 20687f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar } 206978fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->last_ext_ovls = hwc_dev->ext_ovls; 207078fce72baff38f488a0117591d4241d278a48b1bLajos Molnar hwc_dev->last_int_ovls = hwc_dev->post2_layers; 2071c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (err) 207246de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("Post2 error"); 2073c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 20746ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden check_sync_fds(numDisplays, displays); 20756ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 2076c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malcheverr_out: 20772125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_unlock(&hwc_dev->lock); 2078bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar 2079876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (invalidate && hwc_dev->procs && hwc_dev->procs->invalidate) 2080bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar hwc_dev->procs->invalidate(hwc_dev->procs); 2081bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar 2082c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return err; 2083c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2084c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 20856ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void omap4_hwc_dump(struct hwc_composer_device_1 *dev, char *buff, int buff_len) 2086c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2087c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *)dev; 2088876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct dsscomp_setup_dispc_data *dsscomp = &hwc_dev->comp_data.dsscomp_data; 2089734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar struct dump_buf log = { 2090734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf = buff, 2091734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar .buf_len = buff_len, 2092734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar }; 2093c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int i; 2094c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2095734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, "omap4_hwc %d:\n", dsscomp->num_ovls); 2096734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " idle timeout: %dms\n", hwc_dev->idle); 2097c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2098c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev for (i = 0; i < dsscomp->num_ovls; i++) { 2099c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev struct dss2_ovl_cfg *cfg = &dsscomp->ovls[i].cfg; 2100c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2101734de7a7631e5f115ee89c5b2f35c7c484098779Lajos Molnar dump_printf(&log, " layer %d:\n", i); 21023d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse dump_printf(&log, " enabled:%s buff:%p %dx%d stride:%d\n", 21033d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->enabled ? "true" : "false", hwc_dev->buffers[i], 21043d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->width, cfg->height, cfg->stride); 21053d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse dump_printf(&log, " src:(%d,%d) %dx%d dst:(%d,%d) %dx%d ix:%d zorder:%d\n", 21063d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->crop.x, cfg->crop.y, cfg->crop.w, cfg->crop.h, 21073d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->win.x, cfg->win.y, cfg->win.w, cfg->win.h, 21083d32f43362ff52bdac5a83855c63e8a8274da55aTony Lofthouse cfg->ix, cfg->zorder); 2109c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2110876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2111876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->blt_policy != BLTPOLICY_DISABLED) { 2112876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, " bltpolicy: %s, bltmode: %s\n", 2113876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy == BLTPOLICY_DEFAULT ? "default" : 2114876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy == BLTPOLICY_ALL ? "all" : "unknown", 2115876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_mode == BLTMODE_PAINT ? "paint" : "regionize"); 2116876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2117876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen dump_printf(&log, "\n"); 2118c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2119c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 21200aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarstatic void free_png_image(omap4_hwc_device_t *hwc_dev, struct omap4_hwc_img *img) 21210aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar{ 21220aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar memset(img, 0, sizeof(*img)); 21230aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar} 21240aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21250aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarstatic int load_png_image(omap4_hwc_device_t *hwc_dev, char *path, struct omap4_hwc_img *img) 21260aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar{ 21270aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar void *ptr = NULL; 21280aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_bytepp row_pointers = NULL; 21290aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21300aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar FILE *fd = fopen(path, "rb"); 21310aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!fd) { 213246de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to open PNG file %s: (%d)", path, errno); 21330aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar return -EINVAL; 21340aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21350aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21360aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar const int SIZE_PNG_HEADER = 8; 21370aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u8 header[SIZE_PNG_HEADER]; 21380aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar fread(header, 1, SIZE_PNG_HEADER, fd); 21390aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (png_sig_cmp(header, 0, SIZE_PNG_HEADER)) { 214046de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("%s is not a PNG file", path); 21410aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail; 21420aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21430aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21440aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 21450aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!png_ptr) 21460aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21470aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_infop info_ptr = png_create_info_struct(png_ptr); 21480aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!info_ptr) 21490aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21500aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21510aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (setjmp(png_jmpbuf(png_ptr))) 21520aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21530aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21540aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_init_io(png_ptr, fd); 21550aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_sig_bytes(png_ptr, SIZE_PNG_HEADER); 21560aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_user_limits(png_ptr, limits.max_width, limits.max_height); 21570aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_info(png_ptr, info_ptr); 21580aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21590aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u8 bit_depth = png_get_bit_depth(png_ptr, info_ptr); 21600aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u32 width = png_get_image_width(png_ptr, info_ptr); 21610aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u32 height = png_get_image_height(png_ptr, info_ptr); 21620aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u8 color_type = png_get_color_type(png_ptr, info_ptr); 21630aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21640aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar switch (color_type) { 21650aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_PALETTE: 21660aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_palette_to_rgb(png_ptr); 21670aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_filler(png_ptr, 128, PNG_FILLER_AFTER); 21680aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar break; 21690aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_GRAY: 21700aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (bit_depth < 8) { 21710aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_expand_gray_1_2_4_to_8(png_ptr); 21720aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) 21730aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_tRNS_to_alpha(png_ptr); 21740aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } else { 21750aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_filler(png_ptr, 128, PNG_FILLER_AFTER); 21760aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21770aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar /* fall through */ 21780aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_GRAY_ALPHA: 21790aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_gray_to_rgb(png_ptr); 21800aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar break; 21810aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_RGB: 21820aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_filler(png_ptr, 128, PNG_FILLER_AFTER); 21830aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar /* fall through */ 21840aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar case PNG_COLOR_TYPE_RGB_ALPHA: 21850aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_bgr(png_ptr); 21860aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar break; 21870aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar default: 218846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("unsupported PNG color: %x", color_type); 21890aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 21900aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 21910aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21920aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (bit_depth == 16) 21930aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_strip_16(png_ptr); 21940aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 21950aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar const int bpp = 4; 21960aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->size = ALIGN(width * height * bpp, 4096); 21970aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (img->size > hwc_dev->img_mem_size) { 219846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("image does not fit into framebuffer area (%d > %d)", img->size, hwc_dev->img_mem_size); 21990aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 22000aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 22010aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->ptr = hwc_dev->img_mem_ptr; 22020aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 22030aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar row_pointers = calloc(height, sizeof(*row_pointers)); 22040aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!row_pointers) { 220546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to allocate row pointers"); 22060aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto fail_alloc; 22070aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 22080aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar __u32 i; 22090aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar for (i = 0; i < height; i++) 22100aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar row_pointers[i] = img->ptr + i * width * bpp; 22110aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_set_rows(png_ptr, info_ptr, row_pointers); 22120aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_update_info(png_ptr, info_ptr); 22130aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->rowbytes = png_get_rowbytes(png_ptr, info_ptr); 22140aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 22150aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_image(png_ptr, row_pointers); 22160aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_read_end(png_ptr, NULL); 22170aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar free(row_pointers); 22180aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 22190aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar fclose(fd); 22200aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->width = width; 22210aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar img->height = height; 22220aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar return 0; 22230aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 22240aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarfail_alloc: 22250aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar free_png_image(hwc_dev, img); 22260aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar free(row_pointers); 22270aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!png_ptr || !info_ptr) 222846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to allocate PNG structures"); 22290aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 22300aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnarfail: 22310aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar fclose(fd); 22320aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar return -EINVAL; 22330aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar} 22340aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 2235c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2236c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_device_close(hw_device_t* device) 2237c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2238c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) device;; 2239c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 22402125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev) { 22412125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->dsscomp_fd >= 0) 22422125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->dsscomp_fd); 22432125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->hdmi_fb_fd >= 0) 22442125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->hdmi_fb_fd); 22457f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->fb_fd >= 0) 22467f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar close(hwc_dev->fb_fd); 224783f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_fd >= 0) 224883f80658d865b741a024515c523e373df50c091eSunita Nadampalli ion_close(hwc_dev->ion_fd); 224983f80658d865b741a024515c523e373df50c091eSunita Nadampalli 22502125fa148686edfa389121f946377aedaa3d9483Lajos Molnar /* pthread will get killed when parent process exits */ 22512125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_destroy(&hwc_dev->lock); 2252751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_destroy(&hwc_dev->vsync_lock); 2253c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev free(hwc_dev); 22542125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 2255c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2256c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 2257c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2258c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2259c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_open_fb_hal(IMG_framebuffer_device_public_t **fb_dev) 2260c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2261e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar const struct hw_module_t *psModule; 2262c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_gralloc_module_public_t *psGrallocModule; 2263c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int err; 2264c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2265e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &psModule); 2266e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar psGrallocModule = (IMG_gralloc_module_public_t *) psModule; 2267e055e4bf77e6c429d7a159e8e853974d9dfc57adLajos Molnar 2268c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if(err) 2269c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev goto err_out; 2270c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2271b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar if (strcmp(psGrallocModule->base.common.author, "Imagination Technologies")) { 2272c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev err = -EINVAL; 2273c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev goto err_out; 2274c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2275c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2276c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *fb_dev = psGrallocModule->psFrameBufferDevice; 2277c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2278c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return 0; 2279c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2280c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malcheverr_out: 228146de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("Composer HAL failed to load compatible Graphics HAL"); 2282c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return err; 2283c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 22845db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 2285876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chenstatic void set_primary_display_transform_matrix(omap4_hwc_device_t *hwc_dev) 2286876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen{ 2287876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* create primary display translation matrix */ 22885db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->fb_dis.ix = 0;/*Default display*/ 2289c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2290876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_DISPLAY, &hwc_dev->fb_dis); 2291876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (ret) 2292876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("failed to get display info (%d): %m", errno); 2293876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2294876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int lcd_w = hwc_dev->fb_dis.timings.x_res; 2295876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int lcd_h = hwc_dev->fb_dis.timings.y_res; 2296876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int orig_w = hwc_dev->fb_dev->base.width; 2297876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int orig_h = hwc_dev->fb_dev->base.height; 2298876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_rect_t region = {.left = 0, .top = 0, .right = orig_w, .bottom = orig_h}; 2299876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->primary_region = region; 2300876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->primary_rotation = ((lcd_w > lcd_h) ^ (orig_w > orig_h)) ? 1 : 0; 2301876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->primary_transform = ((lcd_w != orig_w)||(lcd_h != orig_h)) ? 1 : 0; 2302876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2303876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("transforming FB (%dx%d) => (%dx%d) rot%d", orig_w, orig_h, lcd_w, lcd_h, hwc_dev->primary_rotation); 2304876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2305876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* reorientation matrix is: 2306876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m = (center-from-target-center) * (scale-to-target) * (mirror) * (rotate) * (center-to-original-center) */ 2307876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2308876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen memcpy(hwc_dev->primary_m, m_unit, sizeof(m_unit)); 2309876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_translate(hwc_dev->primary_m, -(orig_w >> 1), -(orig_h >> 1)); 2310876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_rotate(hwc_dev->primary_m, hwc_dev->primary_rotation); 2311876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->primary_rotation & 1) 2312876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen swap(orig_w, orig_h); 2313876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_scale(hwc_dev->primary_m, orig_w, lcd_w, orig_h, lcd_h); 2314876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen m_translate(hwc_dev->primary_m, lcd_w >> 1, lcd_h >> 1); 23155db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket} 2316751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2317876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 23182b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnarstatic void handle_hotplug(omap4_hwc_device_t *hwc_dev) 23192125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 2320ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar omap4_hwc_ext_t *ext = &hwc_dev->ext; 23212b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar __u8 state = ext->hdmi_state; 2322876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 23235db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket /* Ignore external HDMI logic if the primary display is HDMI */ 23245db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (hwc_dev->on_tv) { 23255db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ALOGI("Primary display is HDMI - skip clone/dock logic"); 23265db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 23275db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (state) { 2328876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen __u32 xres = hwc_dev->fb_dev->base.width; 2329876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen __u32 yres = hwc_dev->fb_dev->base.height; 23305db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (omap4_hwc_set_best_hdmi_mode(hwc_dev, xres, yres, ext->lcd_xpy)) { 2331876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("Failed to set HDMI mode"); 23325db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2333876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen set_primary_display_transform_matrix(hwc_dev); 2334876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 23355db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ioctl(hwc_dev->fb_fd, FBIOBLANK, FB_BLANK_UNBLANK); 23365db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 23375db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (hwc_dev->procs && hwc_dev->procs->invalidate) { 23385db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->procs->invalidate(hwc_dev->procs); 23395db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2340876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else 23415db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ext->last_mode = 0; 23425db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 23435db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket return; 23445db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2345ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 23462125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_lock(&hwc_dev->lock); 2347ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.enabled = ext->mirror.enabled = 0; 23482125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (state) { 234941bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar /* check whether we can clone and/or dock */ 235041bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar char value[PROPERTY_VALUE_MAX]; 2351aa9be8a14744cae50a8f99e6cbb44be0d0c2c938Erik Gilling property_get("persist.hwc.docking.enabled", value, "1"); 2352ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.enabled = atoi(value) > 0; 2353aa9be8a14744cae50a8f99e6cbb44be0d0c2c938Erik Gilling property_get("persist.hwc.mirroring.enabled", value, "1"); 2354ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.enabled = atoi(value) > 0; 23554e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar property_get("persist.hwc.avoid_mode_change", value, "1"); 23564e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar ext->avoid_mode_change = atoi(value) > 0; 235741bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar 235841bb71e35280943ebe07ecfe1cf9e015918164e8Lajos Molnar /* get cloning transformation */ 2359aa9be8a14744cae50a8f99e6cbb44be0d0c2c938Erik Gilling property_get("persist.hwc.docking.transform", value, "0"); 2360ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.rotation = atoi(value) & EXT_ROTATION; 2361ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.hflip = (atoi(value) & EXT_HFLIP) > 0; 2362ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.docking = 1; 23635db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket property_get("persist.hwc.mirroring.transform", value, hwc_dev->fb_dis.timings.y_res > hwc_dev->fb_dis.timings.x_res ? "3" : "0"); 2364ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.rotation = atoi(value) & EXT_ROTATION; 2365ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.hflip = (atoi(value) & EXT_HFLIP) > 0; 2366ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.docking = 0; 2367ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 23682b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar if (ext->force_dock) { 23692b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar /* restrict to docking with no transform */ 23702b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->mirror.enabled = 0; 23712b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->dock.rotation = 0; 23722b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->dock.hflip = 0; 23730aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 23740aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (!dock_image.rowbytes) { 23750aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar property_get("persist.hwc.dock_image", value, "/vendor/res/images/dock/dock.png"); 23760aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar load_png_image(hwc_dev, value, &dock_image); 23770aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 23782b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar } 23792b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar 2380ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar /* select best mode for mirroring */ 2381ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar if (ext->mirror.enabled) { 23823837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar ext->current = ext->mirror; 23833797fa989f5fee97caea2bbadf433a5a9ac03d8dLajos Molnar ext->mirror_mode = 0; 23843837de4ff6b7562965758dd2a7af5550af1bd869Lajos Molnar if (setup_mirroring(hwc_dev) == 0) { 23854e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar ext->mirror_mode = ext->last_mode; 2386ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ioctl(hwc_dev->hdmi_fb_fd, FBIOBLANK, FB_BLANK_UNBLANK); 23874e635e537afaa9f1416fa5bdbfd1b03afd8b7e6aLajos Molnar } else 2388ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.enabled = 0; 2389ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar } 239083f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* Allocate backup buffers for FB rotation 239183f80658d865b741a024515c523e373df50c091eSunita Nadampalli * This is required only if the FB tranform is different from that 239283f80658d865b741a024515c523e373df50c091eSunita Nadampalli * of the external display and the FB is not in TILER2D space 239383f80658d865b741a024515c523e373df50c091eSunita Nadampalli */ 239483f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ext->mirror.rotation && (limits.fbmem_type != DSSCOMP_FBMEM_TILER2D)) 239583f80658d865b741a024515c523e373df50c091eSunita Nadampalli allocate_tiler2d_buffers(hwc_dev); 239683f80658d865b741a024515c523e373df50c091eSunita Nadampalli 23974cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar } else { 23984cb51e55fa79a592d50d94c0700660e42c988a0bLajos Molnar ext->last_mode = 0; 239983f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (ext->mirror.rotation && (limits.fbmem_type != DSSCOMP_FBMEM_TILER2D)) { 240083f80658d865b741a024515c523e373df50c091eSunita Nadampalli /* free tiler 2D buffer on detach */ 240183f80658d865b741a024515c523e373df50c091eSunita Nadampalli free_tiler2d_buffers(hwc_dev); 240283f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 24032125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 2404bb0a9edbe9d4072ed227550d898f0c2d0149e0baSteve Block ALOGI("external display changed (state=%d, mirror={%s tform=%ddeg%s}, dock={%s tform=%ddeg%s%s}, tv=%d", state, 2405ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.enabled ? "enabled" : "disabled", 2406ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.rotation * 90, 2407ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->mirror.hflip ? "+hflip" : "", 2408ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.enabled ? "enabled" : "disabled", 2409ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.rotation * 90, 2410ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->dock.hflip ? "+hflip" : "", 24112b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar ext->force_dock ? " forced" : "", 2412ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar ext->on_tv); 2413ffa0d75e7fa7142eb289ccc9c7dc04e4cedb7c46Lajos Molnar 2414bd0fe036293115c9f9b182ed2a911bdd557ea491Lajos Molnar pthread_mutex_unlock(&hwc_dev->lock); 2415834b8ba01376239a2f286a3766c14bdeeb166498Lajos Molnar 24163a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall /* hwc_dev->procs is set right after the device is opened, but there is 24173a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall * still a race condition where a hotplug event might occur after the open 24183a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall * but before the procs are registered. */ 2419876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (hwc_dev->procs && hwc_dev->procs->invalidate) 2420876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->procs->invalidate(hwc_dev->procs); 24212125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 24222125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2423e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopianstatic void handle_uevents(omap4_hwc_device_t *hwc_dev, const char *buff, int len) 24242125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 2425e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int dock; 2426e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int hdmi; 2427e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int vsync; 2428e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int state = 0; 2429e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian uint64_t timestamp = 0; 2430e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian const char *s = buff; 2431e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2432e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian dock = !strcmp(s, "change@/devices/virtual/switch/dock"); 2433e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian hdmi = !strcmp(s, "change@/devices/virtual/switch/hdmi"); 2434bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling vsync = !strcmp(s, "change@/devices/platform/omapfb") || 2435bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling !strcmp(s, "change@/devices/virtual/switch/omapfb-vsync"); 2436e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2437e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (!dock && !vsync && !hdmi) 2438e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return; 24392125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24402125fa148686edfa389121f946377aedaa3d9483Lajos Molnar s += strlen(s) + 1; 24412125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24422125fa148686edfa389121f946377aedaa3d9483Lajos Molnar while(*s) { 2443e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (!strncmp(s, "SWITCH_STATE=", strlen("SWITCH_STATE="))) 2444e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian state = atoi(s + strlen("SWITCH_STATE=")); 2445e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian else if (!strncmp(s, "SWITCH_TIME=", strlen("SWITCH_TIME="))) 2446e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian timestamp = strtoull(s + strlen("SWITCH_TIME="), NULL, 0); 2447bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling else if (!strncmp(s, "VSYNC=", strlen("VSYNC="))) 2448bc85c3e357438aca809270bc8e85f5479bbe6a40Erik Gilling timestamp = strtoull(s + strlen("VSYNC="), NULL, 0); 24492125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24502125fa148686edfa389121f946377aedaa3d9483Lajos Molnar s += strlen(s) + 1; 2451e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (s - buff >= len) 2452e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian break; 2453e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2454e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2455e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (vsync) { 2456751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fire_vsync_event(hwc_dev, timestamp); 2457e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } else { 2458751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (dock) { 2459e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian hwc_dev->ext.force_dock = state == 1; 2460751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } else { 2461751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* If the primary display is HDMI, VSYNC is enabled, and HDMI's plug 2462751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * state has just gone from 1->0, then we need to be sure to start 2463751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * faking the VSYNC events. 2464751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen */ 2465751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->on_tv) { 2466751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int new_state, state_change; 2467751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2468751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 2469751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2470751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen new_state = state == 1; 2471751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen state_change = (new_state != hwc_dev->ext.hdmi_state); 2472751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->ext.hdmi_state = new_state; 2473751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (state_change && !new_state) 2474751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen wakeup_hdmi_thread(hwc_dev); 2475751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2476751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 2477751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } else { 2478751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->ext.hdmi_state = state == 1; 2479751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2480751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2481e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian handle_hotplug(hwc_dev); 24822125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 24832125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 24842125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 24852125fa148686edfa389121f946377aedaa3d9483Lajos Molnarstatic void *omap4_hwc_hdmi_thread(void *data) 24862125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 24872125fa148686edfa389121f946377aedaa3d9483Lajos Molnar omap4_hwc_device_t *hwc_dev = data; 24882125fa148686edfa389121f946377aedaa3d9483Lajos Molnar static char uevent_desc[4096]; 248902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian struct pollfd fds[2]; 2490b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis int invalidate = 0; 249102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian int timeout; 249202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian int err; 249302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 2494e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); 2495e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 24962125fa148686edfa389121f946377aedaa3d9483Lajos Molnar uevent_init(); 24972125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 249802150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian fds[0].fd = uevent_get_fd(); 249902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian fds[0].events = POLLIN; 2500751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fds[1].fd = hwc_dev->wakeup_evt; 250102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian fds[1].events = POLLIN; 250202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 250302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian timeout = hwc_dev->idle ? hwc_dev->idle : -1; 250402150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 25052125fa148686edfa389121f946377aedaa3d9483Lajos Molnar memset(uevent_desc, 0, sizeof(uevent_desc)); 25062125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 25072125fa148686edfa389121f946377aedaa3d9483Lajos Molnar do { 2508751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t idle_wakeup = (uint64_t)(-1); 2509751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t vsync_wakeup = (uint64_t)(-1); 2510751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t now = vsync_clock_now(); 2511751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t effective_wakeup; 2512751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int effective_timeout; 2513751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2514751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (timeout >= 0) 2515751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen idle_wakeup = now + (((uint64_t)timeout) * 1000000); 2516751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2517751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->on_tv) { 2518751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 2519751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2520751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!hwc_dev->ext.hdmi_state && hwc_dev->vsync_enabled) { 2521751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen vsync_wakeup = hwc_dev->last_vsync_time_valid 2522751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ? hwc_dev->last_vsync_time 2523751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen : now; 2524751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2525751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen vsync_wakeup += hwc_dev->fake_vsync_period; 2526751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2527751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (vsync_wakeup < now) 2528751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen vsync_wakeup = now; 2529751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2530751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2531751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 2532751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2533751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2534751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_wakeup = idle_wakeup < vsync_wakeup 2535751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ? idle_wakeup 2536751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen : vsync_wakeup; 2537751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (effective_wakeup == (uint64_t)(-1)) 2538751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_timeout = -1; 2539751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen else if (effective_wakeup <= now) 2540751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_timeout = 0; 2541751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen else 2542751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen effective_timeout = (int)((effective_wakeup - now + 999999) / 1000000); 2543751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2544751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (effective_timeout) 2545751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = poll(fds, 2, effective_timeout); 2546751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen else 2547751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = 0; 2548751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2549751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen now = vsync_clock_now(); 255002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 255102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (err == 0) { 2552751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen int fired = 0; 2553751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2554751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (now >= vsync_wakeup) { 2555751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fire_vsync_event(hwc_dev, vsync_wakeup); 2556751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fired = 1; 2557751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2558751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2559751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->idle && (now >= idle_wakeup)) { 25603a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall if (hwc_dev->procs) { 2561b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis pthread_mutex_lock(&hwc_dev->lock); 2562b78f671651e83c2cd7b77cd67a8ba3abdb519388Tony Lofthouse invalidate = hwc_dev->last_int_ovls > 1 && !hwc_dev->force_sgx; 2563b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis if (invalidate) { 2564b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis hwc_dev->force_sgx = 2; 2565b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis } 2566b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis pthread_mutex_unlock(&hwc_dev->lock); 2567b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis 2568b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis if (invalidate) { 2569b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis hwc_dev->procs->invalidate(hwc_dev->procs); 2570b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis timeout = -1; 2571b1c5d8ef7fc96ef49a1eaef0d81ff35dc4d2e4e7Jamie Gennis } 257202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 257302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 2574751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen fired = 1; 257502150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 2576751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2577751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (fired) 2578751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen continue; 257902150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 258002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 258102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (err == -1) { 258202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (errno != EINTR) 258346de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("event error: %m"); 258402150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian continue; 258502150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 258602150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 2587751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (fds[1].revents & POLLIN) { 2588751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen uint64_t tmp; 2589751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2590751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen read(hwc_dev->wakeup_evt, &tmp, sizeof(tmp)); 2591751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 259202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (!hwc_dev->force_sgx) 259302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian timeout = hwc_dev->idle ? hwc_dev->idle : -1; 259402150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 259502150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 259602150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian if (fds[0].revents & POLLIN) { 259702150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian /* keep last 2 zeroes to ensure double 0 termination */ 2598e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int len = uevent_next_event(uevent_desc, sizeof(uevent_desc) - 2); 2599e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian handle_uevents(hwc_dev, uevent_desc, len); 260002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 26012125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } while (1); 26022125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 26032125fa148686edfa389121f946377aedaa3d9483Lajos Molnar return NULL; 26042125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 26052125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 26066ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic void omap4_hwc_registerProcs(struct hwc_composer_device_1* dev, 26072125fa148686edfa389121f946377aedaa3d9483Lajos Molnar hwc_procs_t const* procs) 26082125fa148686edfa389121f946377aedaa3d9483Lajos Molnar{ 2609b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) dev; 26102125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2611b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar hwc_dev->procs = (typeof(hwc_dev->procs)) procs; 26122125fa148686edfa389121f946377aedaa3d9483Lajos Molnar} 26132125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 26146ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_query(struct hwc_composer_device_1* dev, 2615e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int what, int* value) 2616e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian{ 2617e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) dev; 2618e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2619e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian switch (what) { 2620e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian case HWC_BACKGROUND_LAYER_SUPPORTED: 2621e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian // we don't support the background layer yet 2622e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian value[0] = 0; 2623e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian break; 2624e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian case HWC_VSYNC_PERIOD: 2625e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian // vsync period in nanosecond 2626e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian value[0] = 1000000000.0 / hwc_dev->fb_dev->base.fps; 2627e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian break; 2628e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian default: 2629e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian // unsupported query 2630e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return -EINVAL; 2631e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2632e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return 0; 2633e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian} 2634e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 26356ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFaddenstatic int omap4_hwc_event_control(struct hwc_composer_device_1* dev, 26366ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden int dpy, int event, int enabled) 2637e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian{ 2638e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian omap4_hwc_device_t *hwc_dev = (omap4_hwc_device_t *) dev; 2639e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2640e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian switch (event) { 2641e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian case HWC_EVENT_VSYNC: 2642e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian { 2643e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int val = !!enabled; 2644e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian int err; 2645e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2646751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* If the primary display is HDMI, then we need to be sure to fake a 2647751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * stream vsync events if vsync is enabled, but HDMI happens to be 2648751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * disconnected. 2649751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen */ 2650751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->on_tv) { 2651751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_lock(&hwc_dev->vsync_lock); 2652751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2653751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!val) 2654751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time_valid = 0; 2655751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2656751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen /* If VSYNC is enabled, but HDMI is not actually plugged in, we need 2657751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * to fake it. Poke the work thread to make sure it is taking care 2658751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen * of things. 2659751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen */ 2660751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (!hwc_dev->ext.hdmi_state && !hwc_dev->vsync_enabled && val) 2661751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen wakeup_hdmi_thread(hwc_dev); 2662751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2663751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->vsync_enabled = val; 2664751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2665751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = ioctl(hwc_dev->fb_fd, OMAPFB_ENABLEVSYNC, &val); 2666751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_unlock(&hwc_dev->vsync_lock); 2667751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } else { 2668751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = ioctl(hwc_dev->fb_fd, OMAPFB_ENABLEVSYNC, &val); 2669751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2670751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2671e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian if (err < 0) 2672e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return -errno; 2673e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 2674e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return 0; 2675e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2676e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian default: 2677e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian return -EINVAL; 2678e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian } 2679e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian} 2680e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian 26813a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hallstatic int omap4_hwc_blank(struct hwc_composer_device_1 *dev, int dpy, int blank) 26826ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden{ 26836ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden // We're using an older method of screen blanking based on 26846ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden // early_suspend in the kernel. No need to do anything here. 26856ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden return 0; 26866ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden} 26876ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden 2688c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic int omap4_hwc_device_open(const hw_module_t* module, const char* name, 2689c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hw_device_t** device) 2690c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 2691c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_module_t *hwc_mod = (omap4_hwc_module_t *)module; 2692c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev omap4_hwc_device_t *hwc_dev; 26932125fa148686edfa389121f946377aedaa3d9483Lajos Molnar int err = 0; 2694c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2695c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (strcmp(name, HWC_HARDWARE_COMPOSER)) { 2696c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return -EINVAL; 2697c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2698c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2699c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!hwc_mod->fb_dev) { 2700c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev err = omap4_hwc_open_fb_hal(&hwc_mod->fb_dev); 2701c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (err) 2702c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return err; 2703c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2704c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!hwc_mod->fb_dev) { 270546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("Framebuffer HAL not opened before HWC"); 2706c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return -EFAULT; 2707c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2708c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_mod->fb_dev->bBypassPost = 1; 2709c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2710c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2711c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev = (omap4_hwc_device_t *)malloc(sizeof(*hwc_dev)); 2712c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (hwc_dev == NULL) 2713c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev return -ENOMEM; 2714c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2715c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev memset(hwc_dev, 0, sizeof(*hwc_dev)); 2716c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2717c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.common.tag = HARDWARE_DEVICE_TAG; 27186ce89d3c3ec5d07a21bd1fc33f6ff61d67acbe95Andy McFadden hwc_dev->base.common.version = HWC_DEVICE_API_VERSION_1_0; 2719c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.common.module = (hw_module_t *)module; 2720c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.common.close = omap4_hwc_device_close; 2721c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.prepare = omap4_hwc_prepare; 2722c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->base.set = omap4_hwc_set; 27233a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.eventControl = omap4_hwc_event_control; 27243a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.blank = omap4_hwc_blank; 2725e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian hwc_dev->base.query = omap4_hwc_query; 27263a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.registerProcs = omap4_hwc_registerProcs; 27273a96e09f206327fb5fd64d3fdc7ba3a315421082Jesse Hall hwc_dev->base.dump = omap4_hwc_dump; 2728c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->fb_dev = hwc_mod->fb_dev; 2729751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->wakeup_evt = -1; 2730c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *device = &hwc_dev->base.common; 2731c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2732751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->vsync_enabled = 0; 2733751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->last_vsync_time_valid = 0; 2734751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen hwc_dev->fake_vsync_period = 1000000000ull/60; 2735751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 27362125fa148686edfa389121f946377aedaa3d9483Lajos Molnar hwc_dev->dsscomp_fd = open("/dev/dsscomp", O_RDWR); 27377f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->dsscomp_fd < 0) { 273846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to open dsscomp (%d)", errno); 27397f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar err = -errno; 27407f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar goto done; 27417f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar } 27422125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2743876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_PLATFORM, &limits); 2744876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (ret) { 2745876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGE("failed to get platform limits (%d): %m", errno); 2746876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen err = -errno; 2747876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto done; 2748876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2749876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 27507f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar hwc_dev->fb_fd = open("/dev/graphics/fb0", O_RDWR); 27517f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->fb_fd < 0) { 275246de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to open fb (%d)", errno); 27537f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar err = -errno; 27547f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar goto done; 27557f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar } 27562125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 27570aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar struct fb_fix_screeninfo fix; 27580aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (ioctl(hwc_dev->fb_fd, FBIOGET_FSCREENINFO, &fix)) { 275946de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to get fb info (%d)", errno); 27600aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar err = -errno; 27610aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto done; 27620aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 27630aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 27640aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar hwc_dev->img_mem_size = fix.smem_len; 27650aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar hwc_dev->img_mem_ptr = mmap(NULL, fix.smem_len, PROT_WRITE, MAP_SHARED, hwc_dev->fb_fd, 0); 27660aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar if (hwc_dev->img_mem_ptr == MAP_FAILED) { 276746de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to map fb memory"); 27680aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar err = -errno; 27690aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar goto done; 27700aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar } 27710aead355133c2a087cb369c5eb62a07cbd4a13beLajos Molnar 2772876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen /* Allocate the maximum buffers that we can receive from HWC */ 2773876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->buffers = malloc(sizeof(buffer_handle_t) * MAX_HWC_LAYERS); 2774c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev if (!hwc_dev->buffers) { 27752125fa148686edfa389121f946377aedaa3d9483Lajos Molnar err = -ENOMEM; 27762125fa148686edfa389121f946377aedaa3d9483Lajos Molnar goto done; 27772125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 27782125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2779876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ret = ioctl(hwc_dev->dsscomp_fd, DSSCIOC_QUERY_DISPLAY, &hwc_dev->fb_dis); 2780d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar if (ret) { 278146de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to get display info (%d): %m", errno); 2782d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar err = -errno; 2783d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar goto done; 2784d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar } 2785f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk 278683f80658d865b741a024515c523e373df50c091eSunita Nadampalli hwc_dev->ion_fd = ion_open(); 278783f80658d865b741a024515c523e373df50c091eSunita Nadampalli if (hwc_dev->ion_fd < 0) { 278883f80658d865b741a024515c523e373df50c091eSunita Nadampalli ALOGE("failed to open ion driver (%d)", errno); 278983f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 279083f80658d865b741a024515c523e373df50c091eSunita Nadampalli 279183f80658d865b741a024515c523e373df50c091eSunita Nadampalli int i; 279283f80658d865b741a024515c523e373df50c091eSunita Nadampalli for (i = 0; i < NUM_EXT_DISPLAY_BACK_BUFFERS; i++) { 279383f80658d865b741a024515c523e373df50c091eSunita Nadampalli hwc_dev->ion_handles[i] = NULL; 279483f80658d865b741a024515c523e373df50c091eSunita Nadampalli } 279583f80658d865b741a024515c523e373df50c091eSunita Nadampalli 2796f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk /* use default value in case some of requested display parameters missing */ 2797f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->ext.lcd_xpy = 1.0; 2798f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk if (hwc_dev->fb_dis.timings.x_res && hwc_dev->fb_dis.height_in_mm) { 2799f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->ext.lcd_xpy = (float) 2800f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->fb_dis.width_in_mm / hwc_dev->fb_dis.timings.x_res / 2801f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk hwc_dev->fb_dis.height_in_mm * hwc_dev->fb_dis.timings.y_res; 2802f1eab7b129ea2cf4bbbbfbec717a07b4419313c6Oleksandr Lugovyk } 2803d98920b36b52ca1784742cbd053c631ae62ca1c4Lajos Molnar 28046d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket if (hwc_dev->fb_dis.channel == OMAP_DSS_CHANNEL_DIGIT) { 28055db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ALOGI("Primary display is HDMI"); 28065db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->on_tv = 1; 28075db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 28086d94b7785c5318b6de36193a7f5488a88b6178ebDandawate Saket else { 28095db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket hwc_dev->hdmi_fb_fd = open("/dev/graphics/fb1", O_RDWR); 28105db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket if (hwc_dev->hdmi_fb_fd < 0) { 28115db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket ALOGE("failed to open hdmi fb (%d)", errno); 28125db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket err = -errno; 28135db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket goto done; 28145db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 28155db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket } 2816876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen set_primary_display_transform_matrix(hwc_dev); 28175db21d521ed41e2e2cc110b698981e841e027287Dandawate Saket 2818751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if ((hwc_dev->wakeup_evt = eventfd(0, EFD_NONBLOCK)) < 0) { 2819751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ALOGE("failed to eventfd (%d): %m", errno); 282002150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian err = -errno; 282102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian goto done; 282202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian } 282302150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian 28242125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (pthread_mutex_init(&hwc_dev->lock, NULL)) { 282546de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to create mutex (%d): %m", errno); 2826b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar err = -errno; 2827b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar goto done; 28282125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 2829751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2830751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (pthread_mutex_init(&hwc_dev->vsync_lock, NULL)) { 2831751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen ALOGE("failed to create vsync mutex (%d): %m", errno); 2832751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen err = -errno; 2833751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen goto done; 2834751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen } 2835751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen 2836876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (pthread_create(&hwc_dev->hdmi_thread, NULL, omap4_hwc_hdmi_thread, hwc_dev)) 2837876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen { 283846de639b23db99d7b99ff1c676ac98b84b6336c6Steve Block ALOGE("failed to create HDMI listening thread (%d): %m", errno); 2839b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar err = -errno; 2840b79b42d125e488c0bcf101edfd3b1f30bafae53eLajos Molnar goto done; 2841c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev } 2842c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2843c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* get debug properties */ 2844c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2845c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* see if hwc is enabled at all */ 2846c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev char value[PROPERTY_VALUE_MAX]; 2847c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev property_get("debug.hwc.rgb_order", value, "1"); 2848c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->flags_rgb_order = atoi(value); 2849c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev property_get("debug.hwc.nv12_only", value, "0"); 2850c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->flags_nv12_only = atoi(value); 285102150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian property_get("debug.hwc.idle", value, "250"); 285202150d77cba303ea6c532fa740910fbab5e3e1ccMathias Agopian hwc_dev->idle = atoi(value); 28532125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 28548d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* get the board specific clone properties */ 28558d546610cba3698c62af537d97e38a7368362f1aLajos Molnar /* 0:0:1280:720 */ 2856dd922b9387f70e24b3462afe1bdc86ceb7541d4bLajos Molnar if (property_get("persist.hwc.mirroring.region", value, "") <= 0 || 28578d546610cba3698c62af537d97e38a7368362f1aLajos Molnar sscanf(value, "%d:%d:%d:%d", 28588d546610cba3698c62af537d97e38a7368362f1aLajos Molnar &hwc_dev->ext.mirror_region.left, &hwc_dev->ext.mirror_region.top, 28598d546610cba3698c62af537d97e38a7368362f1aLajos Molnar &hwc_dev->ext.mirror_region.right, &hwc_dev->ext.mirror_region.bottom) != 4 || 28608d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.left >= hwc_dev->ext.mirror_region.right || 28618d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.top >= hwc_dev->ext.mirror_region.bottom) { 2862876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen struct hwc_rect fb_region = { .right = hwc_dev->fb_dev->base.width, .bottom = hwc_dev->fb_dev->base.height }; 28638d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region = fb_region; 28648d546610cba3698c62af537d97e38a7368362f1aLajos Molnar } 2865bb0a9edbe9d4072ed227550d898f0c2d0149e0baSteve Block ALOGI("clone region is set to (%d,%d) to (%d,%d)", 28668d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.left, hwc_dev->ext.mirror_region.top, 28678d546610cba3698c62af537d97e38a7368362f1aLajos Molnar hwc_dev->ext.mirror_region.right, hwc_dev->ext.mirror_region.bottom); 28688d546610cba3698c62af537d97e38a7368362f1aLajos Molnar 28692125fa148686edfa389121f946377aedaa3d9483Lajos Molnar /* read switch state */ 28702125fa148686edfa389121f946377aedaa3d9483Lajos Molnar int sw_fd = open("/sys/class/switch/hdmi/state", O_RDONLY); 28712125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (sw_fd >= 0) { 28722125fa148686edfa389121f946377aedaa3d9483Lajos Molnar char value; 28732125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (read(sw_fd, &value, 1) == 1) 28742b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar hwc_dev->ext.hdmi_state = value == '1'; 28752b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar close(sw_fd); 28762b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar } 28772b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar sw_fd = open("/sys/class/switch/dock/state", O_RDONLY); 28782b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar if (sw_fd >= 0) { 28792b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar char value; 28802b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar if (read(sw_fd, &value, 1) == 1) 28812b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar hwc_dev->ext.force_dock = value == '1'; 28822125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(sw_fd); 28832125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 28842b86fd0cbeb42123fc20b1f646ee81299e831d16Lajos Molnar handle_hotplug(hwc_dev); 28852125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 2886bb0a9edbe9d4072ed227550d898f0c2d0149e0baSteve Block ALOGI("omap4_hwc_device_open(rgb_order=%d nv12_only=%d)", 2887c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev hwc_dev->flags_rgb_order, hwc_dev->flags_nv12_only); 2888c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2889876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen int gc2d_fd = open("/dev/gcioctl", O_RDWR); 2890876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (gc2d_fd < 0) { 2891876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("Unable to open gc-core device (%d), blits disabled", errno); 2892876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy = BLTPOLICY_DISABLED; 2893876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } else { 2894876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen property_get("persist.hwc.bltmode", value, "1"); 2895876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_mode = atoi(value); 2896876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen property_get("persist.hwc.bltpolicy", value, "1"); 2897876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->blt_policy = atoi(value); 2898876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen ALOGI("blitter present, blits mode %d, blits policy %d", hwc_dev->blt_mode, hwc_dev->blt_policy); 2899876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen close(gc2d_fd); 2900876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2901876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen if (rgz_get_screengeometry(hwc_dev->fb_fd, &gscrngeom, 2902876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen hwc_dev->fb_dev->base.format) != 0) { 2903876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen err = -EINVAL; 2904876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen goto done; 2905876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2906876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen } 2907876331fc77f6763c8c390d1289ead00f89f8d9feMike J. Chen 2908f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar property_get("persist.hwc.upscaled_nv12_limit", value, "2."); 2909f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar sscanf(value, "%f", &hwc_dev->upscaled_nv12_limit); 2910f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar if (hwc_dev->upscaled_nv12_limit < 0. || hwc_dev->upscaled_nv12_limit > 2048.) { 2911f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar ALOGW("Invalid upscaled_nv12_limit (%s), setting to 2.", value); 2912f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar hwc_dev->upscaled_nv12_limit = 2.; 2913f11c7bb8c6e7d0254eeaa4aadb8eae412580ac0eLajos Molnar } 29141fd204fb13367eb8279a1e2d1ee245ff0f441571Tony Lofthouse 29152125fa148686edfa389121f946377aedaa3d9483Lajos Molnardone: 29162125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (err && hwc_dev) { 29172125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->dsscomp_fd >= 0) 29182125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->dsscomp_fd); 29192125fa148686edfa389121f946377aedaa3d9483Lajos Molnar if (hwc_dev->hdmi_fb_fd >= 0) 29202125fa148686edfa389121f946377aedaa3d9483Lajos Molnar close(hwc_dev->hdmi_fb_fd); 29217f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar if (hwc_dev->fb_fd >= 0) 29227f2cbf97908a26e0b463d4fa20040b129216f86eLajos Molnar close(hwc_dev->fb_fd); 2923751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen if (hwc_dev->wakeup_evt >= 0) 2924751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen close(hwc_dev->wakeup_evt); 29252125fa148686edfa389121f946377aedaa3d9483Lajos Molnar pthread_mutex_destroy(&hwc_dev->lock); 2926751880491cd2d46a6bb0ff1070a0dc05557aa041Mike J. Chen pthread_mutex_destroy(&hwc_dev->vsync_lock); 29272125fa148686edfa389121f946377aedaa3d9483Lajos Molnar free(hwc_dev->buffers); 29282125fa148686edfa389121f946377aedaa3d9483Lajos Molnar free(hwc_dev); 29292125fa148686edfa389121f946377aedaa3d9483Lajos Molnar } 29302125fa148686edfa389121f946377aedaa3d9483Lajos Molnar 29312125fa148686edfa389121f946377aedaa3d9483Lajos Molnar return err; 2932c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 2933c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2934c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatic struct hw_module_methods_t omap4_hwc_module_methods = { 2935c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .open = omap4_hwc_device_open, 2936c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}; 2937c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 2938c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevomap4_hwc_module_t HAL_MODULE_INFO_SYM = { 2939c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .base = { 2940c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .common = { 2941c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .tag = HARDWARE_MODULE_TAG, 2942e914b7e0a972af85845268ecf962773b8e4da977Mathias Agopian .module_api_version = HWC_MODULE_API_VERSION_0_1, 2943a35209b2e26289458670e04d6e62dee3d085ea63Mathias Agopian .hal_api_version = HARDWARE_HAL_API_VERSION, 2944c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .id = HWC_HARDWARE_MODULE_ID, 2945c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .name = "OMAP 44xx Hardware Composer HAL", 2946c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .author = "Texas Instruments", 2947c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev .methods = &omap4_hwc_module_methods, 2948c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev }, 2949c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev }, 2950c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}; 2951