| Index: ash/surfaces/test_surface_overlay_view.cc
|
| diff --git a/ash/surfaces/test_surface_overlay_view.cc b/ash/surfaces/test_surface_overlay_view.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..359dad8a968ae638d5a40271706ee3a3f3da0ccf
|
| --- /dev/null
|
| +++ b/ash/surfaces/test_surface_overlay_view.cc
|
| @@ -0,0 +1,189 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ash/surfaces/test_surface_overlay_view.h"
|
| +
|
| +#include <GLES2/gl2.h>
|
| +#include <GLES2/gl2ext.h>
|
| +#include <GLES2/gl2extchromium.h>
|
| +
|
| +#include "ash/shell.h"
|
| +#include "ash/shell_window_ids.h"
|
| +#include "cc/output/context_provider.h"
|
| +#include "gpu/command_buffer/client/gles2_interface.h"
|
| +#include "gpu/command_buffer/common/mailbox.h"
|
| +#include "ui/aura/env.h"
|
| +#include "ui/compositor/layer.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/gpu_memory_buffer.h"
|
| +
|
| +namespace ash {
|
| +namespace {
|
| +
|
| +GLenum GLInternalFormat(gfx::BufferFormat format) {
|
| + const GLenum kGLInternalFormats[] = {
|
| + GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, // ATC
|
| + GL_COMPRESSED_RGB_S3TC_DXT1_EXT, // ATCIA
|
| + GL_COMPRESSED_RGB_S3TC_DXT1_EXT, // DXT1
|
| + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, // DXT5
|
| + GL_ETC1_RGB8_OES, // ETC1
|
| + GL_R8_EXT, // R_8
|
| + GL_RGBA, // RGBA_4444
|
| + GL_RGBA, // RGBA_8888
|
| + GL_RGB, // RGBX_8888
|
| + GL_RGBA, // RGBA_8888
|
| + GL_BGRA_EXT, // BGRA_8888
|
| + GL_RGB_YUV_420_CHROMIUM, // YUV_420
|
| + GL_RGB_YCBCR_422_CHROMIUM, // YUV_420_BIPLANAR
|
| + };
|
| + static_assert(arraysize(kGLInternalFormats) ==
|
| + (static_cast<int>(gfx::BufferFormat::LAST) + 1),
|
| + "BufferFormat::LAST must be last value of kGLInternalFormats");
|
| +
|
| + DCHECK(format <= gfx::BufferFormat::LAST);
|
| + return kGLInternalFormats[static_cast<int>(format)];
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TestSurfaceOverlayView::TestSurfaceOverlayView()
|
| + : test_surface_layer_(new ui::Layer(ui::LAYER_TEXTURED)),
|
| + weak_ptr_factory_(this) {
|
| + Shell::GetInstance()->surface_controller()->AddObserver(this);
|
| +}
|
| +
|
| +TestSurfaceOverlayView::~TestSurfaceOverlayView() {
|
| + Shell::GetInstance()->surface_controller()->RemoveObserver(this);
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::OnKeyEvent(ui::KeyEvent* event) {
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::OnMouseEvent(ui::MouseEvent* event) {
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::OnScrollEvent(ui::ScrollEvent* event) {
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::OnGestureEvent(ui::GestureEvent* event) {
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::OnPaint(gfx::Canvas* canvas) {
|
| + canvas->FillRect(GetLocalBounds(), SK_ColorGRAY);
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::WindowClosing() {
|
| + Cancel();
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::Cancel() {
|
| + Shell::GetInstance()->overlay_filter()->Deactivate(this);
|
| + views::Widget* widget = GetWidget();
|
| + if (widget)
|
| + widget->Close();
|
| +}
|
| +
|
| +bool TestSurfaceOverlayView::IsCancelingKeyEvent(ui::KeyEvent* event) {
|
| + if (event->type() != ui::ET_KEY_PRESSED)
|
| + return false;
|
| +
|
| + // Ignore the caps lock state.
|
| + const int flags = (event->flags() & ~ui::EF_CAPS_LOCK_DOWN);
|
| +
|
| + // Keys to invoke hide (Ctrl+Alt+A).
|
| + return event->key_code() == ui::VKEY_A &&
|
| + flags == (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN);
|
| +}
|
| +
|
| +aura::Window* TestSurfaceOverlayView::GetWindow() {
|
| + return GetWidget()->GetNativeWindow();
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::OnTestSurfaceGpuMemoryBufferChanged() {
|
| + gfx::GpuMemoryBuffer* gpu_memory_buffer =
|
| + Shell::GetInstance()
|
| + ->surface_controller()
|
| + ->GetTestSurfaceGpuMemoryBuffer();
|
| + if (!gpu_memory_buffer) {
|
| + test_surface_layer_->SetVisible(false);
|
| + return;
|
| + }
|
| +
|
| + ui::ContextFactory* context_factory =
|
| + aura::Env::GetInstance()->context_factory();
|
| + scoped_refptr<cc::ContextProvider> context_provider =
|
| + context_factory->SharedMainThreadContextProvider();
|
| + gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL();
|
| +
|
| + gfx::BufferFormat format = gpu_memory_buffer->GetFormat();
|
| + gfx::Size size = gpu_memory_buffer->GetSize();
|
| +
|
| + GLenum texture_target =
|
| + context_factory->GetImageTextureTarget(format, gfx::BufferUsage::SCANOUT);
|
| +
|
| + unsigned texture_id = 0;
|
| + gles2->GenTextures(1, &texture_id);
|
| + gles2->ActiveTexture(GL_TEXTURE0);
|
| + gles2->BindTexture(texture_target, texture_id);
|
| + gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
| + gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
| + gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
| + gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
| + unsigned image_id = gles2->CreateImageCHROMIUM(
|
| + gpu_memory_buffer->AsClientBuffer(), size.width(), size.height(),
|
| + GLInternalFormat(format));
|
| + gles2->BindTexImage2DCHROMIUM(texture_target, image_id);
|
| + uint32 sync_point = gles2->InsertSyncPointCHROMIUM();
|
| +
|
| + gpu::Mailbox mailbox;
|
| + gles2->GenMailboxCHROMIUM(mailbox.name);
|
| + gles2->ProduceTextureCHROMIUM(texture_target, mailbox.name);
|
| + cc::TextureMailbox texture_mailbox(mailbox, texture_target, sync_point);
|
| + test_surface_layer_->SetTextureMailbox(
|
| + texture_mailbox, cc::SingleReleaseCallback::Create(
|
| + base::Bind(&TestSurfaceOverlayView::TextureReleased,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + context_provider, texture_id, image_id)),
|
| + size);
|
| + test_surface_layer_->SetVisible(true);
|
| + test_surface_layer_->SetBounds(gfx::Rect(size));
|
| + test_surface_layer_->SchedulePaint(gfx::Rect(size));
|
| +}
|
| +
|
| +void TestSurfaceOverlayView::TextureReleased(
|
| + scoped_refptr<cc::ContextProvider> context_provider,
|
| + unsigned texture_id,
|
| + unsigned image_id,
|
| + uint32 sync_point,
|
| + bool is_lost) {
|
| + gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL();
|
| + gles2->WaitSyncPointCHROMIUM(sync_point);
|
| + gles2->DeleteTextures(1, &texture_id);
|
| + gles2->DestroyImageCHROMIUM(image_id);
|
| +}
|
| +
|
| +// static
|
| +void TestSurfaceOverlayView::Show() {
|
| + if (Shell::GetInstance()->overlay_filter()->IsActive())
|
| + return;
|
| +
|
| + TestSurfaceOverlayView* view = new TestSurfaceOverlayView;
|
| + views::Widget::InitParams params(
|
| + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
|
| + params.bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();
|
| + params.show_state = ui::SHOW_STATE_FULLSCREEN;
|
| + params.parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
|
| + kShellWindowId_OverlayContainer);
|
| + views::Widget* widget = new views::Widget;
|
| + widget->Init(params);
|
| + widget->SetContentsView(view);
|
| + widget->Show();
|
| + widget->GetNativeView()->SetName("TestSurfaceOverlayView");
|
| + widget->GetNativeView()->Focus();
|
| +
|
| + Shell::GetInstance()->overlay_filter()->Activate(view);
|
| +}
|
| +
|
| +} // namespace ash
|
|
|