Commit 99835f16 authored by Drew Davenport's avatar Drew Davenport Committed by Commit Bot

Clear fast_ink GpuMemoryBuffer

The buffer contents may be uninitialized on some platforms. Ensure that
it is cleared before being displayed.

Change-Id: I55007e0728852d38911515019a2a7a3640ef613c
Bug: b:168735625
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2413179
Commit-Queue: Drew Davenport <ddavenport@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813182}
parent 7c508364
......@@ -10,6 +10,7 @@
#include <memory>
#include "ash/public/cpp/ash_switches.h"
#include "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
#include "cc/base/math_util.h"
......@@ -257,6 +258,21 @@ FastInkHost::FastInkHost(aura::Window* host_window,
gpu::kNullSurfaceHandle);
LOG_IF(ERROR, !gpu_memory_buffer_) << "Failed to create GPU memory buffer";
if (ash::switches::ShouldClearFastInkBuffer()) {
bool map_result = gpu_memory_buffer_->Map();
LOG_IF(ERROR, !map_result) << "Failed to map gpu buffer";
uint8_t* memory = static_cast<uint8_t*>(gpu_memory_buffer_->memory(0));
if (memory != nullptr) {
gfx::Size size = gpu_memory_buffer_->GetSize();
int stride = gpu_memory_buffer_->stride(0);
// Clear the buffer before usage, since it may be uninitialized.
// (http://b/168735625)
for (int i = 0; i < size.height(); ++i)
memset(memory + i * stride, 0, size.width() * 4);
}
gpu_memory_buffer_->Unmap();
}
frame_sink_holder_ = std::make_unique<LayerTreeFrameSinkHolder>(
this, host_window_->CreateLayerTreeFrameSink());
}
......
......@@ -20,6 +20,10 @@ constexpr base::TimeDelta kAshContextualNudgesMaxInterval =
namespace ash {
namespace switches {
// Clear the fast ink buffer upon creation. This is needed on some devices that
// do not zero out new buffers.
const char kAshClearFastInkBuffer[] = "ash-clear-fast-ink-buffer";
// Force the pointer (cursor) position to be kept inside root windows.
const char kAshConstrainPointerToRoot[] = "ash-constrain-pointer-to-root";
......@@ -166,5 +170,10 @@ bool IsUsingShelfAutoDim() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableDimShelf);
}
bool ShouldClearFastInkBuffer() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
kAshClearFastInkBuffer);
}
} // namespace switches
} // namespace ash
......@@ -18,6 +18,7 @@ namespace switches {
// Please keep alphabetized.
// TODO(sky): fix order!
ASH_PUBLIC_EXPORT extern const char kAshClearFastInkBuffer[];
ASH_PUBLIC_EXPORT extern const char kAshConstrainPointerToRoot[];
ASH_PUBLIC_EXPORT extern const char kAshContextualNudgesInterval[];
ASH_PUBLIC_EXPORT extern const char kAshContextualNudgesResetShownCount[];
......@@ -50,6 +51,7 @@ ASH_PUBLIC_EXPORT extern const char kTouchscreenUsableWhileScreenOff[];
ASH_PUBLIC_EXPORT base::Optional<base::TimeDelta> ContextualNudgesInterval();
ASH_PUBLIC_EXPORT bool ContextualNudgesResetShownCount();
ASH_PUBLIC_EXPORT bool IsUsingShelfAutoDim();
ASH_PUBLIC_EXPORT bool ShouldClearFastInkBuffer();
} // namespace switches
} // namespace ash
......
......@@ -152,6 +152,7 @@ void DeriveCommandLine(const GURL& start_url,
::switches::kDisableWebRtcHWDecoding,
::switches::kDisableWebRtcHWEncoding,
::switches::kOzonePlatform,
ash::switches::kAshClearFastInkBuffer,
ash::switches::kAshEnableTabletMode,
ash::switches::kAshEnableWaylandServer,
ash::switches::kAshForceEnableStylusTools,
......
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