Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/msm/mdp5: negative x/y in cursor move

modesetting X11 driver may provide negative x/y cordinates in
mdp5_crtc_cursor_move call when rotation is enabled.

Cursor buffer can overlap down to its negative width/height.

ROI has to be recalculated for negative x/y indicating using the
lower/right corner of the cursor buffer and hotspot must be set
in MDP5_LM_CURSOR_XY_SRC_Y MDP5_LM_CURSOR_XY_SRC_X.

Signed-off-by: Carsten Behling <carsten.behling@gmail.com>
Signed-off-by: Rob Clark <robdclark@gmail.com>

authored by

Carsten Behling and committed by
Rob Clark
23f94551 8f7ca540

+43 -8
+43 -8
drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
··· 65 65 struct drm_gem_object *scanout_bo; 66 66 uint64_t iova; 67 67 uint32_t width, height; 68 - uint32_t x, y; 68 + int x, y; 69 69 } cursor; 70 70 }; 71 71 #define to_mdp5_crtc(x) container_of(x, struct mdp5_crtc, base) ··· 760 760 * Cursor Region Of Interest (ROI) is a plane read from cursor 761 761 * buffer to render. The ROI region is determined by the visibility of 762 762 * the cursor point. In the default Cursor image the cursor point will 763 - * be at the top left of the cursor image, unless it is specified 764 - * otherwise using hotspot feature. 763 + * be at the top left of the cursor image. 765 764 * 765 + * Without rotation: 766 766 * If the cursor point reaches the right (xres - x < cursor.width) or 767 767 * bottom (yres - y < cursor.height) boundary of the screen, then ROI 768 768 * width and ROI height need to be evaluated to crop the cursor image 769 769 * accordingly. 770 770 * (xres-x) will be new cursor width when x > (xres - cursor.width) 771 771 * (yres-y) will be new cursor height when y > (yres - cursor.height) 772 + * 773 + * With rotation: 774 + * We get negative x and/or y coordinates. 775 + * (cursor.width - abs(x)) will be new cursor width when x < 0 776 + * (cursor.height - abs(y)) will be new cursor width when y < 0 772 777 */ 773 - *roi_w = min(mdp5_crtc->cursor.width, xres - 778 + if (mdp5_crtc->cursor.x >= 0) 779 + *roi_w = min(mdp5_crtc->cursor.width, xres - 774 780 mdp5_crtc->cursor.x); 775 - *roi_h = min(mdp5_crtc->cursor.height, yres - 781 + else 782 + *roi_w = mdp5_crtc->cursor.width - abs(mdp5_crtc->cursor.x); 783 + if (mdp5_crtc->cursor.y >= 0) 784 + *roi_h = min(mdp5_crtc->cursor.height, yres - 776 785 mdp5_crtc->cursor.y); 786 + else 787 + *roi_h = mdp5_crtc->cursor.height - abs(mdp5_crtc->cursor.y); 777 788 } 778 789 779 790 static void mdp5_crtc_restore_cursor(struct drm_crtc *crtc) ··· 794 783 struct mdp5_kms *mdp5_kms = get_kms(crtc); 795 784 const enum mdp5_cursor_alpha cur_alpha = CURSOR_ALPHA_PER_PIXEL; 796 785 uint32_t blendcfg, stride; 797 - uint32_t x, y, width, height; 786 + uint32_t x, y, src_x, src_y, width, height; 798 787 uint32_t roi_w, roi_h; 799 788 int lm; 800 789 ··· 811 800 812 801 get_roi(crtc, &roi_w, &roi_h); 813 802 803 + /* If cusror buffer overlaps due to rotation on the 804 + * upper or left screen border the pixel offset inside 805 + * the cursor buffer of the ROI is the positive overlap 806 + * distance. 807 + */ 808 + if (mdp5_crtc->cursor.x < 0) { 809 + src_x = abs(mdp5_crtc->cursor.x); 810 + x = 0; 811 + } else { 812 + src_x = 0; 813 + } 814 + if (mdp5_crtc->cursor.y < 0) { 815 + src_y = abs(mdp5_crtc->cursor.y); 816 + y = 0; 817 + } else { 818 + src_y = 0; 819 + } 820 + DBG("%s: x=%d, y=%d roi_w=%d roi_h=%d src_x=%d src_y=%d", 821 + crtc->name, x, y, roi_w, roi_h, src_x, src_y); 822 + 814 823 mdp5_write(mdp5_kms, REG_MDP5_LM_CURSOR_STRIDE(lm), stride); 815 824 mdp5_write(mdp5_kms, REG_MDP5_LM_CURSOR_FORMAT(lm), 816 825 MDP5_LM_CURSOR_FORMAT_FORMAT(CURSOR_FMT_ARGB8888)); ··· 843 812 mdp5_write(mdp5_kms, REG_MDP5_LM_CURSOR_START_XY(lm), 844 813 MDP5_LM_CURSOR_START_XY_Y_START(y) | 845 814 MDP5_LM_CURSOR_START_XY_X_START(x)); 815 + mdp5_write(mdp5_kms, REG_MDP5_LM_CURSOR_XY(lm), 816 + MDP5_LM_CURSOR_XY_SRC_Y(src_y) | 817 + MDP5_LM_CURSOR_XY_SRC_X(src_x)); 846 818 mdp5_write(mdp5_kms, REG_MDP5_LM_CURSOR_BASE_ADDR(lm), 847 819 mdp5_crtc->cursor.iova); 848 820 ··· 966 932 if (unlikely(!crtc->state->enable)) 967 933 return 0; 968 934 969 - mdp5_crtc->cursor.x = x = max(x, 0); 970 - mdp5_crtc->cursor.y = y = max(y, 0); 935 + /* accept negative x/y coordinates up to maximum cursor overlap */ 936 + mdp5_crtc->cursor.x = x = max(x, -(int)mdp5_crtc->cursor.width); 937 + mdp5_crtc->cursor.y = y = max(y, -(int)mdp5_crtc->cursor.height); 971 938 972 939 get_roi(crtc, &roi_w, &roi_h); 973 940