@@ -634,6 +634,7 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
634634 const struct hvs_format * format = vc4_get_hvs_format (fb -> format -> format );
635635 u64 base_format_mod = fourcc_mod_broadcom_mod (fb -> modifier );
636636 int num_planes = fb -> format -> num_planes ;
637+ bool hflip = false, vflip = false;
637638 u32 h_subsample = fb -> format -> hsub ;
638639 u32 v_subsample = fb -> format -> vsub ;
639640 bool mix_plane_alpha ;
@@ -651,6 +652,24 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
651652 if (ret )
652653 return ret ;
653654
655+ rotation = drm_rotation_simplify (state -> rotation ,
656+ DRM_MODE_ROTATE_0 |
657+ DRM_MODE_REFLECT_X |
658+ DRM_MODE_REFLECT_Y );
659+
660+ if ((rotation & DRM_MODE_ROTATE_MASK ) == DRM_MODE_ROTATE_180 ) {
661+ hflip = true;
662+ vflip = true;
663+ }
664+ if (rotation & DRM_MODE_REFLECT_X )
665+ hflip ^= true;
666+ if (rotation & DRM_MODE_REFLECT_Y )
667+ vflip ^= true;
668+
669+ ret = vc4_plane_setup_clipping_and_scaling (state );
670+ if (ret )
671+ return ret ;
672+
654673 /* SCL1 is used for Cb/Cr scaling of planar formats. For RGB
655674 * and 4:4:4, scl1 should be set to scl0 so both channels of
656675 * the scaler do the same thing. For YUV, the Y plane needs
@@ -665,15 +684,15 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
665684 scl1 = vc4_get_scl_field (state , 0 );
666685 }
667686
668- rotation = drm_rotation_simplify ( state -> rotation ,
669- DRM_MODE_ROTATE_0 |
670- DRM_MODE_REFLECT_X |
671- DRM_MODE_REFLECT_Y );
672-
673- /* We must point to the last line when Y reflection is enabled. */
674- src_y = vc4_state -> src_y ;
675- if ( rotation & DRM_MODE_REFLECT_Y )
676- src_y += vc4_state -> src_h [0 ] - 1 ;
687+ if (! vflip )
688+ src_y = vc4_state -> src_y ;
689+ else
690+ /* When vflipped the image offset needs to be
691+ * the start of the last line of the image, and
692+ * the pitch will be subtracted from the offset.
693+ */
694+ src_y = vc4_state -> src_y +
695+ vc4_state -> src_h [0 ] - 1 ;
677696
678697 switch (base_format_mod ) {
679698 case DRM_FORMAT_MOD_LINEAR :
@@ -733,7 +752,7 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
733752 * definitely required (I guess it's also related to the "going
734753 * backward" situation).
735754 */
736- if (rotation & DRM_MODE_REFLECT_Y ) {
755+ if (vflip ) {
737756 y_off = tile_h_mask - y_off ;
738757 pitch0 = SCALER_PITCH0_TILE_LINE_DIR ;
739758 } else {
@@ -831,7 +850,9 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
831850 VC4_SET_FIELD (tiling , SCALER_CTL0_TILING ) |
832851 (vc4_state -> is_unity ? SCALER_CTL0_UNITY : 0 ) |
833852 VC4_SET_FIELD (scl0 , SCALER_CTL0_SCL0 ) |
834- VC4_SET_FIELD (scl1 , SCALER_CTL0_SCL1 ));
853+ VC4_SET_FIELD (scl1 , SCALER_CTL0_SCL1 ) |
854+ (vflip ? SCALER_CTL0_VFLIP : 0 ) |
855+ (hflip ? SCALER_CTL0_HFLIP : 0 ));
835856
836857 /* Position Word 0: Image Positions and Alpha Value */
837858 vc4_state -> pos0_offset = vc4_state -> dlist_count ;
@@ -1330,5 +1351,11 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev,
13301351 DRM_COLOR_YCBCR_BT709 ,
13311352 DRM_COLOR_YCBCR_LIMITED_RANGE );
13321353
1354+ drm_plane_create_rotation_property (plane , DRM_MODE_ROTATE_0 ,
1355+ DRM_MODE_ROTATE_0 |
1356+ DRM_MODE_ROTATE_180 |
1357+ DRM_MODE_REFLECT_X |
1358+ DRM_MODE_REFLECT_Y );
1359+
13331360 return plane ;
13341361}
0 commit comments