Commit ffef6296 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone/x11] Made the platform returning if transparent color would work.

The Textfield::WriteDragDataForView sets transparent background color
for the drag image, which is not always supported on X11 (depends on
whether the compositing manager is available), but Ozone/X11 didn't
check that and always used the transparent color.

This CL adds a new method in the Ozone platform that returns whether
transparent color could be used.

Bug: 1085700
Change-Id: I2c812086993fc825bb8f7bc0d416b7aa4ab44d89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2323293Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMaksim Sisov (GMT+3) <msisov@igalia.com>
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/master@{#796738}
parent 1281b53e
......@@ -46,4 +46,8 @@ void ChoosePlatformCustomAlphaAndBufferSize(EGLint* alpha_size,
}
}
bool IsTransparentBackgroundSupported() {
return ui::XVisualManager::GetInstance()->ArgbVisualAvailable();
}
} // namespace ui
......@@ -19,6 +19,9 @@ void GetPlatformExtraDisplayAttribs(EGLenum platform_type,
void ChoosePlatformCustomAlphaAndBufferSize(EGLint* alpha_size,
EGLint* buffer_size);
// Returns whether transparent background is suppored.
bool IsTransparentBackgroundSupported();
} // namespace ui
#endif // UI_BASE_X_X11_GL_EGL_UTILITY_H_
\ No newline at end of file
#endif // UI_BASE_X_X11_GL_EGL_UTILITY_H_
......@@ -22,4 +22,8 @@ void GLEGLUtilityX11::ChooseEGLAlphaAndBufferSize(EGLint* alpha_size,
ChoosePlatformCustomAlphaAndBufferSize(alpha_size, buffer_size);
}
bool GLEGLUtilityX11::IsTransparentBackgroundSupported() const {
return ui::IsTransparentBackgroundSupported();
}
} // namespace ui
......@@ -23,6 +23,7 @@ class GLEGLUtilityX11 : public PlatformGLEGLUtility {
std::vector<EGLAttrib>* display_attributes) override;
void ChooseEGLAlphaAndBufferSize(EGLint* alpha_size,
EGLint* buffer_size) override;
bool IsTransparentBackgroundSupported() const override;
};
} // namespace ui
......
......@@ -27,6 +27,10 @@ class COMPONENT_EXPORT(OZONE_BASE) PlatformGLEGLUtility {
// Chooses alpha and buffer size values.
virtual void ChooseEGLAlphaAndBufferSize(EGLint* alpha_size,
EGLint* buffer_size) = 0;
// Returns whether the platform supports setting transparent background for
// windows.
virtual bool IsTransparentBackgroundSupported() const = 0;
};
} // namespace ui
......
......@@ -71,7 +71,6 @@
#endif
#if defined(USE_X11)
#include "ui/base/ui_base_features.h"
#include "ui/base/x/x11_util.h" // nogncheck
#endif
......@@ -85,6 +84,12 @@
#include "ui/base/cocoa/secure_password_input.h"
#endif
#if defined(USE_OZONE)
#include "ui/base/ui_base_features.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/platform_gl_egl_utility.h"
#endif
namespace views {
namespace {
......@@ -274,6 +279,24 @@ bool IsValidCharToInsert(const base::char16& ch) {
return (ch >= 0x20 && ch < 0x7F) || ch > 0x9F;
}
bool CanUseTransparentBackgroundForDragImage() {
#if defined(USE_OZONE)
if (::features::IsUsingOzonePlatform()) {
const auto* const egl_utility =
ui::OzonePlatform::GetInstance()->GetPlatformGLEGLUtility();
return egl_utility ? egl_utility->IsTransparentBackgroundSupported()
: false;
}
#endif
#if defined(USE_X11)
// Fallback on the background color if the system doesn't support compositing.
return ui::XVisualManager::GetInstance()->ArgbVisualAvailable();
#else
// Other platforms allow this.
return true;
#endif
}
} // namespace
// static
......@@ -1264,13 +1287,9 @@ void Textfield::WriteDragDataForView(View* sender,
SkBitmap bitmap;
float raster_scale = ScaleFactorForDragFromWidget(GetWidget());
SkColor color = SK_ColorTRANSPARENT;
#if defined(USE_X11)
// Fallback on the background color if the system doesn't support compositing.
if (!::features::IsUsingOzonePlatform() &&
!ui::XVisualManager::GetInstance()->ArgbVisualAvailable())
color = GetBackgroundColor();
#endif
SkColor color = CanUseTransparentBackgroundForDragImage()
? SK_ColorTRANSPARENT
: GetBackgroundColor();
label.Paint(PaintInfo::CreateRootPaintInfo(
ui::CanvasPainter(&bitmap, label.size(), raster_scale, color,
GetWidget()->GetCompositor()->is_pixel_canvas())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment