OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // A class to emluate GLES2 over command buffers. | 5 // A class to emluate GLES2 over command buffers. |
6 | 6 |
7 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 8 #include <GLES2/gles2_command_buffer.h> |
| 9 #include "../client/mapped_memory.h" |
8 #include "../common/gles2_cmd_utils.h" | 10 #include "../common/gles2_cmd_utils.h" |
9 #include "../common/id_allocator.h" | 11 #include "../common/id_allocator.h" |
10 | 12 |
11 namespace gpu { | 13 namespace gpu { |
12 namespace gles2 { | 14 namespace gles2 { |
13 | 15 |
14 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. | 16 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. |
15 static GLuint ToGLuint(const void* ptr) { | 17 static GLuint ToGLuint(const void* ptr) { |
16 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); | 18 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); |
17 } | 19 } |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 bound_array_buffer_id_(0), | 415 bound_array_buffer_id_(0), |
414 bound_element_array_buffer_id_(0), | 416 bound_element_array_buffer_id_(0), |
415 client_side_array_id_(0), | 417 client_side_array_id_(0), |
416 client_side_element_array_id_(0), | 418 client_side_element_array_id_(0), |
417 #endif | 419 #endif |
418 error_bits_(0) { | 420 error_bits_(0) { |
419 // Allocate space for simple GL results. | 421 // Allocate space for simple GL results. |
420 result_buffer_ = transfer_buffer; | 422 result_buffer_ = transfer_buffer; |
421 result_shm_offset_ = 0; | 423 result_shm_offset_ = 0; |
422 | 424 |
| 425 mapped_memory_.reset(new MappedMemoryManager(helper_)); |
| 426 |
423 if (share_resources) { | 427 if (share_resources) { |
424 buffer_id_handler_.reset( | 428 buffer_id_handler_.reset( |
425 new SharedIdHandler(this, id_namespaces::kBuffers)); | 429 new SharedIdHandler(this, id_namespaces::kBuffers)); |
426 framebuffer_id_handler_.reset( | 430 framebuffer_id_handler_.reset( |
427 new SharedIdHandler(this, id_namespaces::kFramebuffers)); | 431 new SharedIdHandler(this, id_namespaces::kFramebuffers)); |
428 renderbuffer_id_handler_.reset( | 432 renderbuffer_id_handler_.reset( |
429 new SharedIdHandler(this, id_namespaces::kRenderbuffers)); | 433 new SharedIdHandler(this, id_namespaces::kRenderbuffers)); |
430 program_and_shader_id_handler_.reset( | 434 program_and_shader_id_handler_.reset( |
431 new SharedIdHandler(this, id_namespaces::kProgramsAndShaders)); | 435 new SharedIdHandler(this, id_namespaces::kProgramsAndShaders)); |
432 texture_id_handler_.reset( | 436 texture_id_handler_.reset( |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 SetBucketAsCString(kResultBucketId, feature); | 1459 SetBucketAsCString(kResultBucketId, feature); |
1456 helper_->CommandBufferEnable( | 1460 helper_->CommandBufferEnable( |
1457 kResultBucketId, result_shm_id(), result_shm_offset()); | 1461 kResultBucketId, result_shm_id(), result_shm_offset()); |
1458 WaitForCmd(); | 1462 WaitForCmd(); |
1459 helper_->SetBucketSize(kResultBucketId, 0); | 1463 helper_->SetBucketSize(kResultBucketId, 0); |
1460 return *result; | 1464 return *result; |
1461 } | 1465 } |
1462 | 1466 |
1463 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) | 1467 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) |
1464 | 1468 |
| 1469 void* GLES2Implementation::MapBufferSubData( |
| 1470 GLuint target, GLintptr offset, GLsizeiptr size, GLenum access) { |
| 1471 // NOTE: target is NOT checked because the service will check it |
| 1472 // and we don't know what targets are valid. |
| 1473 if (access != GL_WRITE_ONLY) { |
| 1474 SetGLError(GL_INVALID_ENUM, "MapBufferSubData: bad access mode"); |
| 1475 return NULL; |
| 1476 } |
| 1477 if (offset < 0 || size < 0) { |
| 1478 SetGLError(GL_INVALID_VALUE, "MapBufferSubData: bad range"); |
| 1479 return NULL; |
| 1480 } |
| 1481 int32 shm_id; |
| 1482 unsigned int shm_offset; |
| 1483 void* mem = mapped_memory_->Alloc(size, &shm_id, &shm_offset); |
| 1484 if (!mem) { |
| 1485 SetGLError(GL_OUT_OF_MEMORY, "MapBufferSubData: out of memory"); |
| 1486 return NULL; |
| 1487 } |
| 1488 |
| 1489 std::pair<MappedBufferMap::iterator, bool> result = |
| 1490 mapped_buffers_.insert(std::make_pair( |
| 1491 mem, |
| 1492 MappedBuffer( |
| 1493 access, shm_id, mem, shm_offset, target, offset, size))); |
| 1494 return mem; |
| 1495 } |
| 1496 |
| 1497 void GLES2Implementation::UnmapBufferSubData(const void* mem) { |
| 1498 MappedBufferMap::iterator it = mapped_buffers_.find(mem); |
| 1499 if (it == mapped_buffers_.end()) { |
| 1500 SetGLError(GL_INVALID_VALUE, "UnmapBufferSubData: buffer not mapped"); |
| 1501 return; |
| 1502 } |
| 1503 const MappedBuffer& mb = it->second; |
| 1504 helper_->BufferSubData( |
| 1505 mb.target, mb.offset, mb.size, mb.shm_id, mb.shm_offset); |
| 1506 mapped_memory_->FreePendingToken(mb.shm_memory, helper_->InsertToken()); |
| 1507 mapped_buffers_.erase(it); |
| 1508 } |
| 1509 |
| 1510 void* GLES2Implementation::MapTexSubImage2D( |
| 1511 GLenum target, |
| 1512 GLint level, |
| 1513 GLint xoffset, |
| 1514 GLint yoffset, |
| 1515 GLsizei width, |
| 1516 GLsizei height, |
| 1517 GLenum format, |
| 1518 GLenum type, |
| 1519 GLenum access) { |
| 1520 if (access != GL_WRITE_ONLY) { |
| 1521 SetGLError(GL_INVALID_ENUM, "MapTexSubImage2D: bad access mode"); |
| 1522 return NULL; |
| 1523 } |
| 1524 // NOTE: target is NOT checked because the service will check it |
| 1525 // and we don't know what targets are valid. |
| 1526 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0) { |
| 1527 SetGLError(GL_INVALID_VALUE, "MapTexSubImage2D: bad dimensions"); |
| 1528 return NULL; |
| 1529 } |
| 1530 uint32 size; |
| 1531 if (!GLES2Util::ComputeImageDataSize( |
| 1532 width, height, format, type, unpack_alignment_, &size)) { |
| 1533 SetGLError(GL_INVALID_VALUE, "MapTexSubImage2D: image size too large"); |
| 1534 return NULL; |
| 1535 } |
| 1536 int32 shm_id; |
| 1537 unsigned int shm_offset; |
| 1538 void* mem = mapped_memory_->Alloc(size, &shm_id, &shm_offset); |
| 1539 if (!mem) { |
| 1540 SetGLError(GL_OUT_OF_MEMORY, "MapTexSubImage2D: out of memory"); |
| 1541 return NULL; |
| 1542 } |
| 1543 |
| 1544 std::pair<MappedTextureMap::iterator, bool> result = |
| 1545 mapped_textures_.insert(std::make_pair( |
| 1546 mem, |
| 1547 MappedTexture( |
| 1548 access, shm_id, mem, shm_offset, |
| 1549 target, level, xoffset, yoffset, width, height, format, type))); |
| 1550 return mem; |
| 1551 } |
| 1552 |
| 1553 void GLES2Implementation::UnmapTexSubImage2D(const void* mem) { |
| 1554 MappedTextureMap::iterator it = mapped_textures_.find(mem); |
| 1555 if (it == mapped_textures_.end()) { |
| 1556 SetGLError(GL_INVALID_VALUE, "UnmapTexSubImage2D: texture not mapped"); |
| 1557 return; |
| 1558 } |
| 1559 const MappedTexture& mt = it->second; |
| 1560 helper_->TexSubImage2D( |
| 1561 mt.target, mt.level, mt.xoffset, mt.yoffset, mt.width, mt.height, |
| 1562 mt.format, mt.type, mt.shm_id, mt.shm_offset); |
| 1563 mapped_memory_->FreePendingToken(mt.shm_memory, helper_->InsertToken()); |
| 1564 mapped_textures_.erase(it); |
| 1565 } |
| 1566 |
1465 } // namespace gles2 | 1567 } // namespace gles2 |
1466 } // namespace gpu | 1568 } // namespace gpu |
OLD | NEW |