Skip to content

Commit

Permalink
Remove Mojo GLES2 API
Browse files Browse the repository at this point in the history
BUG=586390
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2007813003
Cr-Commit-Position: refs/heads/master@{#395895}
  • Loading branch information
phuang authored and Commit bot committed May 25, 2016
1 parent 6d43c19 commit 2da58dd
Show file tree
Hide file tree
Showing 26 changed files with 32 additions and 1,620 deletions.
1 change: 0 additions & 1 deletion WATCHLISTS
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@
},
'mus': {
'filepath': 'components/mus/'\
'|mojo/gles2/'\
'|mojo/gpu/',
},
'nacl': {
Expand Down
1 change: 0 additions & 1 deletion components/bitmap_uploader/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ component("bitmap_uploader") {
"//components/mus/public/interfaces",
"//gpu",
"//mojo/converters/surfaces",
"//mojo/gles2",
"//mojo/public/c/system:for_component",
"//services/shell/public/cpp",
"//services/shell/public/interfaces",
Expand Down
64 changes: 22 additions & 42 deletions components/bitmap_uploader/bitmap_uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@

#include "base/bind.h"
#include "base/callback.h"
#include "components/mus/public/cpp/gles2_context.h"
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/cpp/window_surface.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "mojo/converters/surfaces/surfaces_type_converters.h"
#include "mojo/converters/surfaces/surfaces_utils.h"
#include "mojo/public/c/gles2/chromium_extension.h"
#include "mojo/public/c/gles2/gles2.h"
#include "services/shell/public/cpp/connector.h"

namespace bitmap_uploader {
namespace {

const uint32_t g_transparent_color = 0x00000000;

void LostContext(void*) {
// TODO(fsamuel): Figure out if there's something useful to do here.
}

} // namespace

const char kBitmapUploaderForAcceleratedWidget[] =
Expand All @@ -42,7 +37,6 @@ BitmapUploader::BitmapUploader(mus::Window* window)
id_namespace_(0u) {}

BitmapUploader::~BitmapUploader() {
MojoGLES2DestroyContext(gles2_context_);
}

void BitmapUploader::Init(shell::Connector* connector) {
Expand All @@ -53,10 +47,9 @@ void BitmapUploader::Init(shell::Connector* connector) {
connector->ConnectToInterface("mojo:mus", &gpu_service_);
mus::mojom::CommandBufferPtr gles2_client;
gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client));
gles2_context_ = MojoGLES2CreateContext(
gles2_client.PassInterface().PassHandle().release().value(), nullptr,
&LostContext, nullptr);
MojoGLES2MakeCurrent(gles2_context_);
gles2_context_.reset(new mus::GLES2Context(
std::vector<int32_t>(), gles2_client.PassInterface().PassHandle()));
DCHECK(gles2_context_->Initialize());
}

// Sets the color which is RGBA.
Expand Down Expand Up @@ -103,31 +96,25 @@ void BitmapUploader::Upload() {
pass->shared_quad_states.push_back(
mojo::CreateDefaultSQS(bounds.size()));

MojoGLES2MakeCurrent(gles2_context_);
if (bitmap_.get()) {
gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
mojo::Size bitmap_size;
bitmap_size.width = width_;
bitmap_size.height = height_;
GLuint texture_id = BindTextureForSize(bitmap_size);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
bitmap_size.width,
bitmap_size.height,
TextureFormat(),
GL_UNSIGNED_BYTE,
&((*bitmap_)[0]));
gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width,
bitmap_size.height, TextureFormat(), GL_UNSIGNED_BYTE,
&((*bitmap_)[0]));

gpu::Mailbox mailbox;
glGenMailboxCHROMIUM(mailbox.name);
glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
gl->GenMailboxCHROMIUM(mailbox.name);
gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);

const GLuint64 fence_sync = glInsertFenceSyncCHROMIUM();
glShallowFlushCHROMIUM();
const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM();
gl->ShallowFlushCHROMIUM();

gpu::SyncToken sync_token;
glGenSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData());

mus::mojom::TransferableResourcePtr resource =
mus::mojom::TransferableResource::New();
Expand Down Expand Up @@ -213,20 +200,14 @@ void BitmapUploader::Upload() {
}

uint32_t BitmapUploader::BindTextureForSize(const mojo::Size size) {
gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
// TODO(jamesr): Recycle textures.
GLuint texture = 0u;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D,
0,
TextureFormat(),
size.width,
size.height,
0,
TextureFormat(),
GL_UNSIGNED_BYTE,
0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl->GenTextures(1, &texture);
gl->BindTexture(GL_TEXTURE_2D, texture);
gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width, size.height, 0,
TextureFormat(), GL_UNSIGNED_BYTE, 0);
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
return texture;
}

Expand All @@ -239,17 +220,16 @@ void BitmapUploader::SetIdNamespace(uint32_t id_namespace) {
void BitmapUploader::OnResourcesReturned(
mus::WindowSurface* surface,
mojo::Array<mus::mojom::ReturnedResourcePtr> resources) {
MojoGLES2MakeCurrent(gles2_context_);
gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
// TODO(jamesr): Recycle.
for (size_t i = 0; i < resources.size(); ++i) {
mus::mojom::ReturnedResourcePtr resource = std::move(resources[i]);
DCHECK_EQ(1, resource->count);
glWaitSyncTokenCHROMIUM(
resource->sync_token.GetConstData());
gl->WaitSyncTokenCHROMIUM(resource->sync_token.GetConstData());
uint32_t texture_id = resource_to_texture_id_map_[resource->id];
DCHECK_NE(0u, texture_id);
resource_to_texture_id_map_.erase(resource->id);
glDeleteTextures(1, &texture_id);
gl->DeleteTextures(1, &texture_id);
}
}

Expand Down
7 changes: 5 additions & 2 deletions components/bitmap_uploader/bitmap_uploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
#include "components/mus/public/interfaces/gpu.mojom.h"
#include "gpu/GLES2/gl2chromium.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "mojo/public/c/gles2/gles2.h"

namespace mus {
class GLES2Context;
}

namespace shell {
class Connector;
Expand Down Expand Up @@ -72,7 +75,7 @@ class BITMAP_UPLOADER_EXPORT BitmapUploader
mus::Window* window_;
mus::mojom::GpuPtr gpu_service_;
std::unique_ptr<mus::WindowSurface> surface_;
MojoGLES2Context gles2_context_;
std::unique_ptr<mus::GLES2Context> gles2_context_;

mojo::Size size_;
uint32_t color_;
Expand Down
1 change: 0 additions & 1 deletion components/mus/public/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ source_set("cpp") {
"//mojo/converters/geometry",
"//mojo/converters/input_events",
"//mojo/converters/surfaces",
"//mojo/public/c/gles2:gles2",
"//mojo/public/cpp/bindings:bindings",
"//mojo/public/cpp/system",
"//services/shell/public/cpp",
Expand Down
5 changes: 0 additions & 5 deletions components/mus/public/cpp/context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ class ContextProvider : public cc::ContextProvider {
~ContextProvider() override;

private:
static void ContextLostThunk(void* closure) {
static_cast<ContextProvider*>(closure)->ContextLost();
}
void ContextLost();

mojo::ScopedMessagePipeHandle command_buffer_handle_;
std::unique_ptr<GLES2Context> context_;

Expand Down
13 changes: 2 additions & 11 deletions components/mus/public/cpp/gles2_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#include "base/macros.h"
#include "components/mus/public/cpp/lib/command_buffer_client_impl.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "mojo/public/c/gles2/gles2.h"

struct MojoGLES2ContextPrivate {};

namespace gpu {
class TransferBuffer;
Expand All @@ -27,12 +24,10 @@ class GLES2Implementation;

namespace mus {

class GLES2Context : public MojoGLES2ContextPrivate {
class GLES2Context {
public:
explicit GLES2Context(const std::vector<int32_t>& attribs,
mojo::ScopedMessagePipeHandle command_buffer_handle,
MojoGLES2ContextLost lost_callback,
void* closure);
mojo::ScopedMessagePipeHandle command_buffer_handle);
virtual ~GLES2Context();
bool Initialize();

Expand All @@ -42,14 +37,10 @@ class GLES2Context : public MojoGLES2ContextPrivate {
gpu::ContextSupport* context_support() const { return implementation_.get(); }

private:
void OnLostContext();

CommandBufferClientImpl command_buffer_;
std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_;
std::unique_ptr<gpu::TransferBuffer> transfer_buffer_;
std::unique_ptr<gpu::gles2::GLES2Implementation> implementation_;
MojoGLES2ContextLost lost_callback_;
void* closure_;

DISALLOW_COPY_AND_ASSIGN(GLES2Context);
};
Expand Down
1 change: 0 additions & 1 deletion components/mus/public/cpp/lib/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
include_rules = [
"+mojo/gles2",
"+mojo/gpu"
]
6 changes: 1 addition & 5 deletions components/mus/public/cpp/lib/context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ ContextProvider::ContextProvider(
}

bool ContextProvider::BindToCurrentThread() {
DCHECK(command_buffer_handle_.is_valid());
std::unique_ptr<GLES2Context> context(new GLES2Context(
std::vector<int32_t>(), std::move(command_buffer_handle_),
&ContextLostThunk, this));
std::vector<int32_t>(), std::move(command_buffer_handle_)));
if (context->Initialize())
context_ = std::move(context);
return !!context_;
Expand Down Expand Up @@ -60,6 +58,4 @@ base::Lock* ContextProvider::GetLock() {
ContextProvider::~ContextProvider() {
}

void ContextProvider::ContextLost() {}

} // namespace mus
14 changes: 2 additions & 12 deletions components/mus/public/cpp/lib/gles2_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
namespace mus {

GLES2Context::GLES2Context(const std::vector<int32_t>& attribs,
mojo::ScopedMessagePipeHandle command_buffer_handle,
MojoGLES2ContextLost lost_callback,
void* closure)
: command_buffer_(attribs, std::move(command_buffer_handle)),
lost_callback_(lost_callback),
closure_(closure) {}
mojo::ScopedMessagePipeHandle command_buffer_handle)
: command_buffer_(attribs, std::move(command_buffer_handle)) {}

GLES2Context::~GLES2Context() {}

Expand Down Expand Up @@ -53,13 +49,7 @@ bool GLES2Context::Initialize() {
default_limits.max_transfer_buffer_size,
default_limits.mapped_memory_reclaim_limit))
return false;
implementation_->SetLostContextCallback(
base::Bind(&GLES2Context::OnLostContext, base::Unretained(this)));
return true;
}

void GLES2Context::OnLostContext() {
lost_callback_(closure_);
}

} // namespace mus
1 change: 0 additions & 1 deletion components/mus/public/cpp/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ test("mus_public_unittests") {
"//mojo/converters/geometry",
"//mojo/converters/input_events",
"//mojo/edk/system",
"//mojo/gles2",
"//mojo/public/cpp/system",
"//services/shell/public/cpp",
"//testing/gtest",
Expand Down
1 change: 0 additions & 1 deletion components/mus/ws/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ test("mus_ws_unittests") {
"//mojo/converters/geometry",
"//mojo/converters/input_events",
"//mojo/converters/transform",
"//mojo/gles2",
"//mojo/public/cpp/bindings:bindings",
"//services/shell/public/cpp:shell_test_support",
"//services/shell/public/cpp:sources",
Expand Down
Loading

0 comments on commit 2da58dd

Please sign in to comment.