Update //mojo/gpu to 68d50d71c802b3f56aa535d9403e20804b11ef52

This commit is contained in:
Adam Barth 2016-01-27 22:11:30 -08:00
parent 8d7a4bb3f8
commit e7119fb4fa
12 changed files with 45 additions and 636 deletions

View File

@ -12,10 +12,10 @@ source_set("gpu") {
"gl_context_owner.h",
"gl_texture.cc",
"gl_texture.h",
"texture_cache.cc",
"texture_cache.h",
"texture_uploader.cc",
"texture_uploader.h",
]
public_deps = [
"//mojo/public/c/gpu",
]
deps = [
@ -33,30 +33,5 @@ source_set("gpu") {
"//mojo/services/geometry/cpp",
"//mojo/services/geometry/interfaces",
"//mojo/services/gpu/interfaces",
"//mojo/services/surfaces/cpp",
"//mojo/services/surfaces/interfaces",
"//mojo/services/surfaces/interfaces:surface_id",
]
}
mojo_native_application("apptests") {
output_name = "texture_apptests"
testonly = true
sources = [
"texture_cache_unittest.cc",
"texture_uploader_unittest.cc",
]
deps = [
":gpu",
"//base",
"//mojo/application",
"//mojo/application:test_support",
"//mojo/public/cpp/bindings:callback",
"//mojo/services/geometry/interfaces",
"//mojo/services/surfaces/interfaces:surface_id",
"//testing/gtest",
]
}

View File

@ -5,26 +5,19 @@
#include "mojo/gpu/gl_context.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/public/interfaces/application/application_connector.mojom.h"
#include "mojo/services/gpu/interfaces/gpu.mojom.h"
namespace mojo {
GLContext::Observer::~Observer() {
}
GLContext::Observer::~Observer() {}
GLContext::GLContext(Shell* shell) : weak_factory_(this) {
ServiceProviderPtr native_viewport;
shell->ConnectToApplication("mojo:native_viewport_service",
GetProxy(&native_viewport), nullptr);
GpuPtr gpu_service;
ConnectToService(native_viewport.get(), &gpu_service);
CommandBufferPtr command_buffer;
gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer));
context_ = MGLCreateContext(MGL_API_VERSION_GLES2,
GLContext::GLContext(CommandBufferPtr command_buffer) : weak_factory_(this) {
context_ = MGLCreateContext(
MGL_API_VERSION_GLES2,
command_buffer.PassInterface().PassHandle().release().value(),
MGL_NO_CONTEXT,
&ContextLostThunk, this, Environment::GetDefaultAsyncWaiter());
MGL_NO_CONTEXT, &ContextLostThunk, this,
Environment::GetDefaultAsyncWaiter());
DCHECK(context_ != MGL_NO_CONTEXT);
}
@ -32,8 +25,21 @@ GLContext::~GLContext() {
MGLDestroyContext(context_);
}
base::WeakPtr<GLContext> GLContext::Create(Shell* shell) {
return (new GLContext(shell))->weak_factory_.GetWeakPtr();
base::WeakPtr<GLContext> GLContext::CreateOffscreen(
ApplicationConnector* connector) {
ServiceProviderPtr native_viewport;
connector->ConnectToApplication("mojo:native_viewport_service",
GetProxy(&native_viewport), nullptr);
GpuPtr gpu_service;
ConnectToService(native_viewport.get(), &gpu_service);
CommandBufferPtr command_buffer;
gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer));
return CreateFromCommandBuffer(command_buffer.Pass());
}
base::WeakPtr<GLContext> GLContext::CreateFromCommandBuffer(
CommandBufferPtr command_buffer) {
return (new GLContext(command_buffer.Pass()))->weak_factory_.GetWeakPtr();
}
void GLContext::MakeCurrent() {

View File

@ -9,8 +9,12 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "mojo/public/c/gpu/MGL/mgl.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
namespace mojo {
class ApplicationConnector;
class CommandBuffer;
using CommandBufferPtr = InterfacePtr<CommandBuffer>;
class Shell;
class GLContext {
@ -23,7 +27,13 @@ class GLContext {
virtual ~Observer();
};
static base::WeakPtr<GLContext> Create(Shell* shell);
// Creates an offscreen GL context.
static base::WeakPtr<GLContext> CreateOffscreen(
ApplicationConnector* connector);
// Creates a GL context from a command buffer.
static base::WeakPtr<GLContext> CreateFromCommandBuffer(
CommandBufferPtr command_buffer);
void MakeCurrent();
bool IsCurrent();
@ -33,7 +43,7 @@ class GLContext {
void RemoveObserver(Observer* observer);
private:
explicit GLContext(Shell* shell);
explicit GLContext(CommandBufferPtr command_buffer);
~GLContext();
static void ContextLostThunk(void* self);

View File

@ -8,9 +8,8 @@
namespace mojo {
GLContextOwner::GLContextOwner(mojo::Shell* shell)
: context_(mojo::GLContext::Create(shell)) {
}
GLContextOwner::GLContextOwner(ApplicationConnector* connector)
: context_(GLContext::CreateOffscreen(connector)) {}
GLContextOwner::~GLContextOwner() {
context_->Destroy();

View File

@ -9,11 +9,13 @@
namespace mojo {
class GLContext;
class ApplicationConnector;
class Shell;
class GLContextOwner {
public:
explicit GLContextOwner(mojo::Shell* shell);
explicit GLContextOwner(ApplicationConnector* connector);
~GLContextOwner();
const base::WeakPtr<mojo::GLContext>& context() const { return context_; }

View File

@ -4,7 +4,7 @@
#include "mojo/gpu/gl_texture.h"
#include "mojo/public/c/gpu/GLES2/gl2.h"
#include <GLES2/gl2.h>
namespace mojo {
@ -17,6 +17,7 @@ GLTexture::GLTexture(base::WeakPtr<GLContext> context, mojo::Size size)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width, size_.height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
}
GLTexture::~GLTexture() {

View File

@ -1,108 +0,0 @@
// 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.
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#include <GLES2/gl2extmojo.h>
#include "mojo/gpu/gl_context.h"
#include "mojo/gpu/gl_texture.h"
#include "mojo/gpu/texture_cache.h"
#include "mojo/services/geometry/interfaces/geometry.mojom.h"
namespace mojo {
TextureCache::TextureInfo::TextureInfo() : texture_(), resource_id_(0u) {
}
TextureCache::TextureInfo::TextureInfo(scoped_ptr<mojo::GLTexture> texture,
uint32_t resource_id)
: texture_(texture.Pass()), resource_id_(resource_id) {
}
TextureCache::TextureInfo::~TextureInfo() {
}
TextureCache::TextureCache(base::WeakPtr<mojo::GLContext> gl_context,
mojo::ResourceReturnerPtr* out_resource_returner)
: gl_context_(gl_context), returner_binding_(this), next_resource_id_(0u) {
if (out_resource_returner) {
returner_binding_.Bind(GetProxy(out_resource_returner));
}
}
TextureCache::~TextureCache() {
}
scoped_ptr<TextureCache::TextureInfo> TextureCache::GetTexture(
const mojo::Size& requested_size) {
// Sift through our available textures to find one the correct size. If one
// exists use it. As we find textures of the wrong size, clean them up.
while (!available_textures_.empty()) {
// Get the next available texture's resource id.
uint32_t available_resource_id = available_textures_.front();
available_textures_.pop_front();
// Get the texture information from the texture map.
auto texture_iterator =
resource_to_texture_map_.find(available_resource_id);
mojo::Size texture_size = texture_iterator->second->size();
scoped_ptr<TextureInfo> texture_info(new TextureInfo(
texture_iterator->second.Pass(), texture_iterator->first));
resource_to_texture_map_.erase(texture_iterator);
// Get the sync point from the sync point map.
auto sync_point_iterator =
resource_to_sync_point_map_.find(available_resource_id);
int sync_point = sync_point_iterator->second;
resource_to_sync_point_map_.erase(sync_point_iterator);
// If the texture is the right size, use it.
if (texture_size.width == requested_size.width &&
texture_size.height == requested_size.height) {
glWaitSyncPointCHROMIUM(sync_point);
return texture_info.Pass();
}
}
// If our context is invalid return an empty scoped ptr.
if (!gl_context_) {
return scoped_ptr<TextureInfo>();
}
// We couldn't find an existing texture to reuse, create a new one!
scoped_ptr<mojo::GLTexture> new_texture(
new mojo::GLTexture(gl_context_, requested_size));
next_resource_id_++;
scoped_ptr<TextureInfo> texture_info(
new TextureInfo(new_texture.Pass(), next_resource_id_));
return texture_info.Pass();
}
void TextureCache::NotifyPendingResourceReturn(
uint32_t resource_id,
scoped_ptr<mojo::GLTexture> texture) {
resource_to_texture_map_[resource_id] = texture.Pass();
}
// mojo::ResourceReturner
void TextureCache::ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) {
if (!gl_context_) {
return;
}
gl_context_->MakeCurrent();
for (size_t i = 0u; i < resources.size(); ++i) {
mojo::ReturnedResourcePtr resource = resources[i].Pass();
DCHECK_EQ(1, resource->count);
auto it = resource_to_texture_map_.find(resource->id);
// Ignore the returned resource if we haven't been notified of its pending
// return.
if (it != resource_to_texture_map_.end()) {
available_textures_.push_back(resource->id);
resource_to_sync_point_map_[resource->id] = resource->sync_point;
}
}
}
} // namespace mojo

View File

@ -1,80 +0,0 @@
// 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.
#ifndef MOJO_GPU_TEXTURE_CACHE_H_
#define MOJO_GPU_TEXTURE_CACHE_H_
#include <GLES2/gl2.h>
#include <deque>
#include <map>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/services/surfaces/interfaces/surfaces.mojom.h"
namespace mojo {
class GLContext;
class GLTexture;
class Size;
// Represents a cache of textures which can be drawn to and submitted to a
// surface.
// Each |texture| in the cache has an associated |resource_id| which must be
// used when the texture is submitted to a surface via a
// TransferableResourcePtr. This class must also be hooked up to the surface as
// a ResourceReturner such that the resources are properly marked as available
// to be used again.
class TextureCache : public mojo::ResourceReturner {
public:
class TextureInfo {
public:
TextureInfo();
TextureInfo(scoped_ptr<mojo::GLTexture> texture, uint32_t resource_id);
~TextureInfo();
scoped_ptr<mojo::GLTexture> Texture() { return texture_.Pass(); }
uint32_t ResourceId() { return resource_id_; }
private:
scoped_ptr<mojo::GLTexture> texture_;
uint32_t resource_id_;
DISALLOW_COPY_AND_ASSIGN(TextureInfo);
};
// Returns the ResourceReturner to be given to the surface the textures will
// be uploaded to via |out_resource_returner|.
TextureCache(base::WeakPtr<mojo::GLContext> gl_context,
mojo::ResourceReturnerPtr* out_resource_returner);
~TextureCache() override;
// Returns a texture for the given size. If no texture is available the
// scoped_ptr will be empty.
scoped_ptr<TextureInfo> GetTexture(const mojo::Size& requested_size);
// Notifies the TextureCache to expect the given resource to be returned
// shortly.
void NotifyPendingResourceReturn(uint32_t resource_id,
scoped_ptr<mojo::GLTexture> texture);
private:
// mojo::ResourceReturner
void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) override;
base::WeakPtr<mojo::GLContext> gl_context_;
mojo::Binding<mojo::ResourceReturner> returner_binding_;
std::deque<uint32_t> available_textures_;
std::map<uint32_t, scoped_ptr<mojo::GLTexture>> resource_to_texture_map_;
std::map<uint32_t, GLuint> resource_to_sync_point_map_;
uint32_t next_resource_id_;
DISALLOW_COPY_AND_ASSIGN(TextureCache);
};
} // namespace mojo
#endif // MOJO_GPU_TEXTURE_CACHE_H_

View File

@ -1,208 +0,0 @@
// 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 "mojo/gpu/texture_cache.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "mojo/gpu/gl_context.h"
#include "mojo/gpu/gl_texture.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_test_base.h"
#include "mojo/services/geometry/public/interfaces/geometry.mojom.h"
#include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
static const base::TimeDelta kDefaultMessageDelay =
base::TimeDelta::FromMilliseconds(20);
class TextureCacheTest : public mojo::test::ApplicationTestBase {
public:
TextureCacheTest() : weak_factory_(this) {}
~TextureCacheTest() override {}
void SetUp() override {
mojo::test::ApplicationTestBase::SetUp();
gl_context_ = mojo::GLContext::Create(application_impl()->shell());
quit_message_loop_callback_ = base::Bind(
&TextureCacheTest::QuitMessageLoopCallback, weak_factory_.GetWeakPtr());
}
void QuitMessageLoopCallback() { base::MessageLoop::current()->Quit(); }
void KickMessageLoop() {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, quit_message_loop_callback_, kDefaultMessageDelay);
base::MessageLoop::current()->Run();
}
protected:
base::WeakPtr<mojo::GLContext> gl_context_;
base::Closure quit_message_loop_callback_;
base::WeakPtrFactory<TextureCacheTest> weak_factory_;
private:
DISALLOW_COPY_AND_ASSIGN(TextureCacheTest);
};
TEST_F(TextureCacheTest, GetTextureOnce) {
mojo::TextureCache texture_cache(gl_context_, nullptr);
mojo::Size size;
size.width = 100;
size.height = 100;
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info(
texture_cache.GetTexture(size).Pass());
EXPECT_NE(texture_info->Texture().get(), nullptr);
}
TEST_F(TextureCacheTest, GetTextureTwice) {
mojo::TextureCache texture_cache(gl_context_, nullptr);
mojo::Size size;
size.width = 100;
size.height = 100;
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info_1(
texture_cache.GetTexture(size).Pass());
scoped_ptr<mojo::GLTexture> texture_1(texture_info_1->Texture().Pass());
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info_2(
texture_cache.GetTexture(size).Pass());
scoped_ptr<mojo::GLTexture> texture_2(texture_info_2->Texture().Pass());
EXPECT_NE(texture_1.get(), nullptr);
EXPECT_NE(texture_2.get(), nullptr);
EXPECT_NE(texture_1.get(), texture_2.get());
EXPECT_NE(texture_info_1->ResourceId(), texture_info_2->ResourceId());
}
TEST_F(TextureCacheTest, GetTextureAfterReturnSameSize) {
mojo::ResourceReturnerPtr resource_returner;
mojo::TextureCache texture_cache(gl_context_, &resource_returner);
mojo::Size size;
size.width = 100;
size.height = 100;
// get a texture
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info_1(
texture_cache.GetTexture(size).Pass());
scoped_ptr<mojo::GLTexture> texture(texture_info_1->Texture().Pass());
mojo::GLTexture* texture_ptr = texture.get();
EXPECT_NE(texture_ptr, nullptr);
mojo::Array<mojo::ReturnedResourcePtr> resources;
mojo::ReturnedResourcePtr returnedResource = mojo::ReturnedResource::New();
returnedResource->id = texture_info_1->ResourceId();
returnedResource->sync_point = 0u;
returnedResource->count = 1u;
returnedResource->lost = false;
resources.push_back(returnedResource.Pass());
// return the texture via resource id
texture_cache.NotifyPendingResourceReturn(texture_info_1->ResourceId(),
texture.Pass());
resource_returner->ReturnResources(resources.Pass());
KickMessageLoop();
// get a texture of the same size - it should be the same one as before
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info_2(
texture_cache.GetTexture(size).Pass());
scoped_ptr<mojo::GLTexture> texture_2(texture_info_2->Texture().Pass());
EXPECT_NE(texture_2.get(), nullptr);
EXPECT_EQ(size.width, texture_2->size().width);
EXPECT_EQ(size.height, texture_2->size().height);
EXPECT_EQ(texture_info_1->ResourceId(), texture_info_2->ResourceId());
}
TEST_F(TextureCacheTest, GetTextureAfterReturnDifferentSize) {
mojo::ResourceReturnerPtr resource_returner;
mojo::TextureCache texture_cache(gl_context_, &resource_returner);
mojo::Size size;
size.width = 100;
size.height = 100;
// get a texture
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info_1(
texture_cache.GetTexture(size).Pass());
scoped_ptr<mojo::GLTexture> texture(texture_info_1->Texture().Pass());
mojo::GLTexture* texture_ptr = texture.get();
EXPECT_NE(texture_ptr, nullptr);
mojo::Array<mojo::ReturnedResourcePtr> resources;
mojo::ReturnedResourcePtr returnedResource = mojo::ReturnedResource::New();
returnedResource->id = texture_info_1->ResourceId();
returnedResource->sync_point = 0u;
returnedResource->count = 1u;
returnedResource->lost = false;
resources.push_back(returnedResource.Pass());
// return the texture via resource id
texture_cache.NotifyPendingResourceReturn(texture_info_1->ResourceId(),
texture.Pass());
resource_returner->ReturnResources(resources.Pass());
KickMessageLoop();
mojo::Size different_size;
different_size.width = size.width - 1;
different_size.height = size.height - 1;
// get a texture of the different size - it should not be the same one as
// before
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info_2(
texture_cache.GetTexture(different_size).Pass());
scoped_ptr<mojo::GLTexture> texture_2(texture_info_2->Texture().Pass());
EXPECT_NE(texture_2.get(), nullptr);
EXPECT_NE(size.width, texture_2->size().width);
EXPECT_NE(size.height, texture_2->size().height);
EXPECT_EQ(different_size.width, texture_2->size().width);
EXPECT_EQ(different_size.height, texture_2->size().height);
EXPECT_NE(texture_info_1->ResourceId(), texture_info_2->ResourceId());
}
TEST_F(TextureCacheTest, GetTextureReleasedGlContext) {
gl_context_.reset();
mojo::TextureCache texture_cache(gl_context_, nullptr);
mojo::Size size;
size.width = 100;
size.height = 100;
EXPECT_EQ(texture_cache.GetTexture(size).get(), nullptr);
}
TEST_F(TextureCacheTest, ReturnResourcesReleasedGlContext) {
mojo::ResourceReturnerPtr resource_returner;
mojo::TextureCache texture_cache(gl_context_, &resource_returner);
mojo::Size size;
size.width = 100;
size.height = 100;
// get a texture
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info(
texture_cache.GetTexture(size).Pass());
scoped_ptr<mojo::GLTexture> texture(texture_info->Texture().Pass());
mojo::GLTexture* texture_ptr = texture.get();
EXPECT_NE(texture_ptr, nullptr);
gl_context_.reset();
mojo::Array<mojo::ReturnedResourcePtr> resources;
mojo::ReturnedResourcePtr returnedResource = mojo::ReturnedResource::New();
returnedResource->id = texture_info->ResourceId();
returnedResource->sync_point = 0u;
returnedResource->count = 1u;
returnedResource->lost = false;
resources.push_back(returnedResource.Pass());
// return the texture via resource id
texture_cache.NotifyPendingResourceReturn(texture_info->ResourceId(),
texture.Pass());
resource_returner->ReturnResources(resources.Pass());
KickMessageLoop();
}
} // namespace

View File

@ -1,94 +0,0 @@
// 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 "mojo/gpu/texture_uploader.h"
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#include <GLES2/gl2.h>
#include <GLES2/gl2extmojo.h>
#include "mojo/services/geometry/cpp/geometry_util.h"
#include "mojo/services/surfaces/cpp/surfaces_utils.h"
namespace mojo {
mojo::FramePtr TextureUploader::GetUploadFrame(
base::WeakPtr<mojo::GLContext> context,
uint32_t resource_id,
const scoped_ptr<mojo::GLTexture>& texture) {
if (!context) {
return mojo::FramePtr();
}
mojo::Size size = texture->size();
mojo::FramePtr frame = mojo::Frame::New();
frame->resources.resize(0u);
mojo::Rect bounds;
bounds.width = size.width;
bounds.height = size.height;
mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds);
pass->quads.resize(0u);
pass->shared_quad_states.push_back(mojo::CreateDefaultSQS(size));
context->MakeCurrent();
glBindTexture(GL_TEXTURE_2D, texture->texture_id());
GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM];
glGenMailboxCHROMIUM(mailbox);
glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox);
GLuint sync_point = glInsertSyncPointCHROMIUM();
mojo::TransferableResourcePtr resource = mojo::TransferableResource::New();
resource->id = resource_id;
resource->format = mojo::ResourceFormat::RGBA_8888;
resource->filter = GL_LINEAR;
resource->size = size.Clone();
mojo::MailboxHolderPtr mailbox_holder = mojo::MailboxHolder::New();
mailbox_holder->mailbox = mojo::Mailbox::New();
for (int i = 0; i < GL_MAILBOX_SIZE_CHROMIUM; ++i)
mailbox_holder->mailbox->name.push_back(mailbox[i]);
mailbox_holder->texture_target = GL_TEXTURE_2D;
mailbox_holder->sync_point = sync_point;
resource->mailbox_holder = mailbox_holder.Pass();
resource->is_repeated = false;
resource->is_software = false;
mojo::QuadPtr quad = mojo::Quad::New();
quad->material = mojo::Material::TEXTURE_CONTENT;
mojo::RectPtr rect = mojo::Rect::New();
rect->width = size.width;
rect->height = size.height;
quad->rect = rect.Clone();
quad->opaque_rect = rect.Clone();
quad->visible_rect = rect.Clone();
quad->needs_blending = true;
quad->shared_quad_state_index = 0u;
mojo::TextureQuadStatePtr texture_state = mojo::TextureQuadState::New();
texture_state->resource_id = resource->id;
texture_state->premultiplied_alpha = true;
texture_state->uv_top_left = mojo::PointF::New();
texture_state->uv_bottom_right = mojo::PointF::New();
texture_state->uv_bottom_right->x = 1.f;
texture_state->uv_bottom_right->y = 1.f;
texture_state->background_color = mojo::Color::New();
texture_state->background_color->rgba = 0;
for (int i = 0; i < 4; ++i)
texture_state->vertex_opacity.push_back(1.f);
texture_state->flipped = false;
frame->resources.push_back(resource.Pass());
quad->texture_quad_state = texture_state.Pass();
pass->quads.push_back(quad.Pass());
frame->passes.push_back(pass.Pass());
return frame.Pass();
}
} // namespace mojo

View File

@ -1,34 +0,0 @@
// 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.
#ifndef MOJO_GPU_TEXTURE_UPLOADER_H_
#define MOJO_GPU_TEXTURE_UPLOADER_H_
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/gpu/gl_context.h"
#include "mojo/gpu/gl_texture.h"
#include "mojo/services/surfaces/interfaces/surfaces.mojom.h"
namespace mojo {
// Utility class for uploading textures to a surface.
class TextureUploader {
public:
// Gets a FramePtr for uploading to a to a SurfacePtr using |texture| as a
// transferable resource with id |resource_id|.
static mojo::FramePtr GetUploadFrame(
base::WeakPtr<mojo::GLContext> context,
uint32_t resource_id,
const scoped_ptr<mojo::GLTexture>& texture);
private:
TextureUploader();
~TextureUploader();
DISALLOW_COPY_AND_ASSIGN(TextureUploader);
};
} // namespace mojo
#endif // MOJO_GPU_TEXTURE_UPLOADER_H_

View File

@ -1,60 +0,0 @@
// 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 "mojo/gpu/texture_uploader.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "mojo/gpu/texture_cache.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_test_base.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class TextureUploaderTest : public mojo::test::ApplicationTestBase {
public:
TextureUploaderTest() : surface_id_(1u), weak_factory_(this) {}
~TextureUploaderTest() override {}
void SetUp() override {
mojo::test::ApplicationTestBase::SetUp();
mojo::ServiceProviderPtr surfaces_service_provider;
application_impl()->shell()->ConnectToApplication(
"mojo:surfaces_service", mojo::GetProxy(&surfaces_service_provider),
nullptr);
mojo::ConnectToService(surfaces_service_provider.get(), &surface_);
gl_context_ = mojo::GLContext::Create(application_impl()->shell());
surface_->CreateSurface(surface_id_);
texture_cache_.reset(new mojo::TextureCache(gl_context_, nullptr));
}
void OnFrameCompleteExit() { base::MessageLoop::current()->Quit(); }
protected:
uint32_t surface_id_;
base::WeakPtr<mojo::GLContext> gl_context_;
scoped_ptr<mojo::TextureCache> texture_cache_;
mojo::SurfacePtr surface_;
base::WeakPtrFactory<TextureUploaderTest> weak_factory_;
private:
DISALLOW_COPY_AND_ASSIGN(TextureUploaderTest);
};
TEST_F(TextureUploaderTest, Base) {
mojo::Size size;
size.width = 100;
size.height = 100;
scoped_ptr<mojo::TextureCache::TextureInfo> texture_info(
texture_cache_->GetTexture(size).Pass());
mojo::FramePtr frame = mojo::TextureUploader::GetUploadFrame(
gl_context_, texture_info->ResourceId(), texture_info->Texture());
EXPECT_FALSE(frame.is_null());
}
} // namespace