summaryrefslogtreecommitdiff
path: root/chromium/gpu/command_buffer/client/gles2_implementation.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/gpu/command_buffer/client/gles2_implementation.cc')
-rw-r--r--chromium/gpu/command_buffer/client/gles2_implementation.cc178
1 files changed, 135 insertions, 43 deletions
diff --git a/chromium/gpu/command_buffer/client/gles2_implementation.cc b/chromium/gpu/command_buffer/client/gles2_implementation.cc
index 0bee1ed5c4d..b0efc3769da 100644
--- a/chromium/gpu/command_buffer/client/gles2_implementation.cc
+++ b/chromium/gpu/command_buffer/client/gles2_implementation.cc
@@ -22,6 +22,7 @@
#include "gpu/command_buffer/client/transfer_buffer.h"
#include "gpu/command_buffer/client/vertex_array_object_manager.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
+#include "gpu/command_buffer/common/gpu_control.h"
#include "gpu/command_buffer/common/trace_event.h"
#include "ui/gfx/gpu_memory_buffer.h"
@@ -71,13 +72,13 @@ GLES2Implementation::GLStaticState::IntState::IntState()
GLES2Implementation::SingleThreadChecker::SingleThreadChecker(
GLES2Implementation* gles2_implementation)
: gles2_implementation_(gles2_implementation) {
- GPU_CHECK_EQ(0, gles2_implementation_->use_count_);
+ CHECK_EQ(0, gles2_implementation_->use_count_);
++gles2_implementation_->use_count_;
}
GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() {
--gles2_implementation_->use_count_;
- GPU_CHECK_EQ(0, gles2_implementation_->use_count_);
+ CHECK_EQ(0, gles2_implementation_->use_count_);
}
GLES2Implementation::GLES2Implementation(
@@ -85,6 +86,7 @@ GLES2Implementation::GLES2Implementation(
ShareGroup* share_group,
TransferBufferInterface* transfer_buffer,
bool bind_generates_resource,
+ bool free_everything_when_invisible,
GpuControl* gpu_control)
: helper_(helper),
transfer_buffer_(transfer_buffer),
@@ -110,9 +112,14 @@ GLES2Implementation::GLES2Implementation(
use_count_(0),
current_query_(NULL),
error_message_callback_(NULL),
- gpu_control_(gpu_control) {
- GPU_DCHECK(helper);
- GPU_DCHECK(transfer_buffer);
+ gpu_control_(gpu_control),
+ surface_visible_(true),
+ free_everything_when_invisible_(free_everything_when_invisible),
+ capabilities_(gpu_control->GetCapabilities()),
+ weak_ptr_factory_(this) {
+ DCHECK(helper);
+ DCHECK(transfer_buffer);
+ DCHECK(gpu_control);
char temp[128];
sprintf(temp, "%p", static_cast<void*>(this));
@@ -134,9 +141,9 @@ bool GLES2Implementation::Initialize(
unsigned int min_transfer_buffer_size,
unsigned int max_transfer_buffer_size,
unsigned int mapped_memory_limit) {
- GPU_DCHECK_GE(starting_transfer_buffer_size, min_transfer_buffer_size);
- GPU_DCHECK_LE(starting_transfer_buffer_size, max_transfer_buffer_size);
- GPU_DCHECK_GE(min_transfer_buffer_size, kStartingOffset);
+ DCHECK_GE(starting_transfer_buffer_size, min_transfer_buffer_size);
+ DCHECK_LE(starting_transfer_buffer_size, max_transfer_buffer_size);
+ DCHECK_GE(min_transfer_buffer_size, kStartingOffset);
if (!transfer_buffer_->Initialize(
starting_transfer_buffer_size,
@@ -307,6 +314,46 @@ void GLES2Implementation::FreeEverything() {
helper_->FreeRingBuffer();
}
+void GLES2Implementation::RunIfContextNotLost(const base::Closure& callback) {
+ if (!helper_->IsContextLost())
+ callback.Run();
+}
+
+void GLES2Implementation::SignalSyncPoint(uint32 sync_point,
+ const base::Closure& callback) {
+ gpu_control_->SignalSyncPoint(
+ sync_point,
+ base::Bind(&GLES2Implementation::RunIfContextNotLost,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+}
+
+void GLES2Implementation::SignalQuery(uint32 query,
+ const base::Closure& callback) {
+ // Flush previously entered commands to ensure ordering with any
+ // glBeginQueryEXT() calls that may have been put into the context.
+ ShallowFlushCHROMIUM();
+ gpu_control_->SignalQuery(
+ query,
+ base::Bind(&GLES2Implementation::RunIfContextNotLost,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+}
+
+void GLES2Implementation::SetSurfaceVisible(bool visible) {
+ // TODO(piman): This probably should be ShallowFlushCHROMIUM().
+ Flush();
+ surface_visible_ = visible;
+ gpu_control_->SetSurfaceVisible(visible);
+ if (!visible)
+ FreeEverything();
+}
+
+void GLES2Implementation::SendManagedMemoryStats(
+ const ManagedMemoryStats& stats) {
+ gpu_control_->SendManagedMemoryStats(stats);
+}
+
void GLES2Implementation::WaitForCmd() {
TRACE_EVENT0("gpu", "GLES2::WaitForCmd");
helper_->CommandBufferHelper::Finish();
@@ -413,7 +460,7 @@ GLenum GLES2Implementation::GetGLError() {
#if defined(GL_CLIENT_FAIL_GL_ERRORS)
void GLES2Implementation::FailGLError(GLenum error) {
if (error != GL_NO_ERROR) {
- GPU_NOTREACHED() << "Error";
+ NOTREACHED() << "Error";
}
}
// NOTE: Calling GetGLError overwrites data in the result buffer.
@@ -449,7 +496,7 @@ void GLES2Implementation::SetGLErrorInvalidEnum(
bool GLES2Implementation::GetBucketContents(uint32 bucket_id,
std::vector<int8>* data) {
TRACE_EVENT0("gpu", "GLES2::GetBucketContents");
- GPU_DCHECK(data);
+ DCHECK(data);
const uint32 kStartSize = 32 * 1024;
ScopedTransferBufferPtr buffer(kStartSize, helper_, transfer_buffer_);
if (!buffer.valid()) {
@@ -495,7 +542,7 @@ bool GLES2Implementation::GetBucketContents(uint32 bucket_id,
void GLES2Implementation::SetBucketContents(
uint32 bucket_id, const void* data, size_t size) {
- GPU_DCHECK(data);
+ DCHECK(data);
helper_->SetBucketSize(bucket_id, size);
if (size > 0u) {
uint32 offset = 0;
@@ -527,7 +574,7 @@ void GLES2Implementation::SetBucketAsCString(
bool GLES2Implementation::GetBucketAsString(
uint32 bucket_id, std::string* str) {
- GPU_DCHECK(str);
+ DCHECK(str);
std::vector<int8> data;
// NOTE: strings are passed NULL terminated. That means the empty
// string will have a size of 1 and no-string will have a size of 0
@@ -664,6 +711,13 @@ bool GLES2Implementation::GetHelper(GLenum pname, GLint* params) {
return true;
}
return false;
+ case GL_TEXTURE_BINDING_EXTERNAL_OES:
+ if (share_group_->bind_generates_resource()) {
+ *params =
+ texture_units_[active_texture_unit_].bound_texture_external_oes;
+ return true;
+ }
+ return false;
case GL_FRAMEBUFFER_BINDING:
if (share_group_->bind_generates_resource()) {
*params = bound_framebuffer_;
@@ -793,6 +847,8 @@ void GLES2Implementation::Flush() {
// Flush our command buffer
// (tell the service to execute up to the flush cmd.)
helper_->CommandBufferHelper::Flush();
+ if (!surface_visible_ && free_everything_when_invisible_)
+ FreeEverything();
}
void GLES2Implementation::ShallowFlushCHROMIUM() {
@@ -801,11 +857,14 @@ void GLES2Implementation::ShallowFlushCHROMIUM() {
// Flush our command buffer
// (tell the service to execute up to the flush cmd.)
helper_->CommandBufferHelper::Flush();
+ // TODO(piman): Add the FreeEverything() logic here.
}
void GLES2Implementation::Finish() {
GPU_CLIENT_SINGLE_THREAD_CHECK();
FinishHelper();
+ if (!surface_visible_ && free_everything_when_invisible_)
+ FreeEverything();
}
void GLES2Implementation::ShallowFinishCHROMIUM() {
@@ -821,7 +880,7 @@ bool GLES2Implementation::MustBeContextLost() {
WaitForCmd();
context_lost = helper_->IsContextLost();
}
- GPU_CHECK(context_lost);
+ CHECK(context_lost);
return context_lost;
}
@@ -1005,7 +1064,7 @@ bool GLES2Implementation::DeleteProgramHelper(GLuint program) {
void GLES2Implementation::DeleteProgramStub(
GLsizei n, const GLuint* programs) {
- GPU_DCHECK_EQ(1, n);
+ DCHECK_EQ(1, n);
share_group_->program_info_manager()->DeleteInfo(programs[0]);
helper_->DeleteProgram(programs[0]);
}
@@ -1023,7 +1082,7 @@ bool GLES2Implementation::DeleteShaderHelper(GLuint shader) {
void GLES2Implementation::DeleteShaderStub(
GLsizei n, const GLuint* shaders) {
- GPU_DCHECK_EQ(1, n);
+ DCHECK_EQ(1, n);
share_group_->program_info_manager()->DeleteInfo(shaders[0]);
helper_->DeleteShader(shaders[0]);
}
@@ -1298,7 +1357,7 @@ void GLES2Implementation::ShaderSource(
}
}
- GPU_DCHECK_EQ(total_size, offset);
+ DCHECK_EQ(total_size, offset);
helper_->ShaderSourceBucket(shader, kResultBucketId);
helper_->SetBucketSize(kResultBucketId, 0);
@@ -1329,7 +1388,7 @@ void GLES2Implementation::BufferDataHelper(
// Create new buffer.
buffer = buffer_tracker_->CreateBuffer(buffer_id, size);
- GPU_DCHECK(buffer);
+ DCHECK(buffer);
if (buffer->address() && data)
memcpy(buffer->address(), data, size);
return;
@@ -1421,8 +1480,8 @@ void GLES2Implementation::BufferSubDataHelper(
void GLES2Implementation::BufferSubDataHelperImpl(
GLenum target, GLintptr offset, GLsizeiptr size, const void* data,
ScopedTransferBufferPtr* buffer) {
- GPU_DCHECK(buffer);
- GPU_DCHECK_GT(size, 0);
+ DCHECK(buffer);
+ DCHECK_GT(size, 0);
const int8* source = static_cast<const int8*>(data);
while (size) {
@@ -1802,7 +1861,7 @@ void GLES2Implementation::TexSubImage2D(
static GLint ComputeNumRowsThatFitInBuffer(
GLsizeiptr padded_row_size, GLsizeiptr unpadded_row_size,
unsigned int size) {
- GPU_DCHECK_GE(unpadded_row_size, 0);
+ DCHECK_GE(unpadded_row_size, 0);
if (padded_row_size == 0) {
return 1;
}
@@ -1815,10 +1874,10 @@ void GLES2Implementation::TexSubImage2DImpl(
GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size,
const void* pixels, uint32 pixels_padded_row_size, GLboolean internal,
ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size) {
- GPU_DCHECK(buffer);
- GPU_DCHECK_GE(level, 0);
- GPU_DCHECK_GT(height, 0);
- GPU_DCHECK_GT(width, 0);
+ DCHECK(buffer);
+ DCHECK_GE(level, 0);
+ DCHECK_GT(height, 0);
+ DCHECK_GT(width, 0);
const int8* source = reinterpret_cast<const int8*>(pixels);
GLint original_yoffset = yoffset;
@@ -2087,10 +2146,8 @@ const GLubyte* GLES2Implementation::GetStringHelper(GLenum name) {
case GL_EXTENSIONS:
str += std::string(str.empty() ? "" : " ") +
"GL_CHROMIUM_flipy "
- "GL_CHROMIUM_map_sub "
- "GL_CHROMIUM_shallow_flush "
"GL_EXT_unpack_subimage";
- if (gpu_control_ != NULL) {
+ if (capabilities_.map_image) {
// The first space character is intentional.
str += " GL_CHROMIUM_map_image";
}
@@ -2107,7 +2164,7 @@ const GLubyte* GLES2Implementation::GetStringHelper(GLenum name) {
std::set<std::string> strings;
std::pair<GLStringMap::iterator, bool> insert_result =
gl_strings_.insert(std::make_pair(name, strings));
- GPU_DCHECK(insert_result.second);
+ DCHECK(insert_result.second);
it = insert_result.first;
}
std::set<std::string>& string_set = it->second;
@@ -2117,7 +2174,7 @@ const GLubyte* GLES2Implementation::GetStringHelper(GLenum name) {
} else {
std::pair<std::set<std::string>::const_iterator, bool> insert_result =
string_set.insert(str);
- GPU_DCHECK(insert_result.second);
+ DCHECK(insert_result.second);
result = insert_result.first->c_str();
}
}
@@ -2457,6 +2514,12 @@ bool GLES2Implementation::BindTextureHelper(GLenum target, GLuint texture) {
changed = true;
}
break;
+ case GL_TEXTURE_EXTERNAL_OES:
+ if (unit.bound_texture_external_oes != texture) {
+ unit.bound_texture_external_oes = texture;
+ changed = true;
+ }
+ break;
default:
changed = true;
break;
@@ -2584,6 +2647,9 @@ void GLES2Implementation::DeleteTexturesHelper(
if (textures[ii] == unit.bound_texture_cube_map) {
unit.bound_texture_cube_map = 0;
}
+ if (textures[ii] == unit.bound_texture_external_oes) {
+ unit.bound_texture_external_oes = 0;
+ }
}
}
}
@@ -2709,6 +2775,32 @@ void GLES2Implementation::GetVertexAttribiv(
CheckGLError();
}
+void GLES2Implementation::Swap() {
+ SwapBuffers();
+ gpu_control_->Echo(
+ base::Bind(&GLES2Implementation::OnSwapBuffersComplete,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void GLES2Implementation::PartialSwapBuffers(gfx::Rect sub_buffer) {
+ PostSubBufferCHROMIUM(sub_buffer.x(),
+ sub_buffer.y(),
+ sub_buffer.width(),
+ sub_buffer.height());
+ gpu_control_->Echo(base::Bind(&GLES2Implementation::OnSwapBuffersComplete,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void GLES2Implementation::SetSwapBuffersCompleteCallback(
+ const base::Closure& swap_buffers_complete_callback) {
+ swap_buffers_complete_callback_ = swap_buffers_complete_callback;
+}
+
+void GLES2Implementation::OnSwapBuffersComplete() {
+ if (!swap_buffers_complete_callback_.is_null())
+ swap_buffers_complete_callback_.Run();
+}
+
GLboolean GLES2Implementation::EnableFeatureCHROMIUM(
const char* feature) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
@@ -2760,7 +2852,7 @@ void* GLES2Implementation::MapBufferSubDataCHROMIUM(
mem,
MappedBuffer(
access, shm_id, mem, shm_offset, target, offset, size)));
- GPU_DCHECK(result.second);
+ DCHECK(result.second);
GPU_CLIENT_LOG(" returned " << mem);
return mem;
}
@@ -2834,7 +2926,7 @@ void* GLES2Implementation::MapTexSubImage2DCHROMIUM(
MappedTexture(
access, shm_id, mem, shm_offset,
target, level, xoffset, yoffset, width, height, format, type)));
- GPU_DCHECK(result.second);
+ DCHECK(result.second);
GPU_CLIENT_LOG(" returned " << mem);
return mem;
}
@@ -2890,7 +2982,7 @@ const GLchar* GLES2Implementation::GetRequestableExtensionsCHROMIUM() {
} else {
std::pair<std::set<std::string>::const_iterator, bool> insert_result =
requestable_extensions_set_.insert(str);
- GPU_DCHECK(insert_result.second);
+ DCHECK(insert_result.second);
result = insert_result.first->c_str();
}
}
@@ -3072,7 +3164,7 @@ void GLES2Implementation::GetAllShaderPrecisionFormatsOnCompleted(
void GLES2Implementation::GetProgramInfoCHROMIUMHelper(
GLuint program, std::vector<int8>* result) {
- GPU_DCHECK(result);
+ DCHECK(result);
// Clear the bucket so if the command fails nothing will be in it.
helper_->SetBucketSize(kResultBucketId, 0);
helper_->GetProgramInfoCHROMIUM(program, kResultBucketId);
@@ -3093,7 +3185,7 @@ void GLES2Implementation::GetProgramInfoCHROMIUM(
}
// Make sure they've set size to 0 else the value will be undefined on
// lost context.
- GPU_DCHECK(*size == 0);
+ DCHECK(*size == 0);
std::vector<int8> result;
GetProgramInfoCHROMIUMHelper(program, &result);
if (result.empty()) {
@@ -3309,7 +3401,7 @@ void GLES2Implementation::GetQueryObjectuivEXT(
if (!query->CheckResultsAvailable(helper_)) {
// TODO(gman): Speed this up.
WaitForCmd();
- GPU_CHECK(query->CheckResultsAvailable(helper_));
+ CHECK(query->CheckResultsAvailable(helper_));
}
}
*params = query->GetResult();
@@ -3398,13 +3490,12 @@ void GLES2Implementation::GenMailboxCHROMIUM(
<< static_cast<const void*>(mailbox) << ")");
TRACE_EVENT0("gpu", "GLES2::GenMailboxCHROMIUM");
- helper_->GenMailboxCHROMIUM(kResultBucketId);
-
- std::vector<GLbyte> result;
- GetBucketContents(kResultBucketId, &result);
-
- std::copy(result.begin(), result.end(), mailbox);
- CheckGLError();
+ std::vector<gpu::Mailbox> names;
+ if (!gpu_control_->GenerateMailboxNames(1, &names)) {
+ SetGLError(GL_OUT_OF_MEMORY, "glGenMailboxCHROMIUM", "Generate failed.");
+ return;
+ }
+ memcpy(mailbox, names[0].name, GL_MAILBOX_SIZE_CHROMIUM);
}
void GLES2Implementation::PushGroupMarkerEXT(
@@ -3659,7 +3750,8 @@ void GLES2Implementation::WaitAsyncTexImage2DCHROMIUM(GLenum target) {
GLuint GLES2Implementation::InsertSyncPointCHROMIUM() {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM");
- return helper_->InsertSyncPointCHROMIUM();
+ helper_->CommandBufferHelper::Flush();
+ return gpu_control_->InsertSyncPoint();
}
GLuint GLES2Implementation::CreateImageCHROMIUMHelper(