diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 22:58:58 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 22:58:58 +0000 |
commit | 9f427328e5f5794d29b4b4fbf2439f0ba86daa0e (patch) | |
tree | 8a45c0bddc83cab50a6cc5462f98890eaf750a73 /gpu | |
parent | 3fb28bac3a97af687de76d830d42fe974422f910 (diff) | |
download | chromium_src-9f427328e5f5794d29b4b4fbf2439f0ba86daa0e.zip chromium_src-9f427328e5f5794d29b4b4fbf2439f0ba86daa0e.tar.gz chromium_src-9f427328e5f5794d29b4b4fbf2439f0ba86daa0e.tar.bz2 |
Rearrange GLES2 files so they are easier to use
from native client and pepper.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/668205
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40956 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
35 files changed, 226 insertions, 676 deletions
@@ -1,6 +1,10 @@ include_rules = [ "+webkit/glue/plugins", "+third_party/npapi", + "+../command_buffer", + "+../client", + "+../common", + "+../service", # For gfx::PluginWindowHandle "+app/gfx", diff --git a/gpu/command_buffer/common/GLES2/gl2.h b/gpu/GLES2/gl2.h index 4ce0d7c..8e9b0e3 100644 --- a/gpu/command_buffer/common/GLES2/gl2.h +++ b/gpu/GLES2/gl2.h @@ -19,7 +19,7 @@ // macros. #if defined(__cplusplus) && defined(GLES2_INLINE_OPTIMIZATION) -#include "gpu/command_buffer/command_buffer/client/gles2_lib.h" +#include "../command_buffer/client/gles2_lib.h" #define GLES2_USE_CPP_BINDINGS #endif diff --git a/gpu/command_buffer/common/GLES2/gl2platform.h b/gpu/GLES2/gl2platform.h index 3e9036c..3e9036c 100644 --- a/gpu/command_buffer/common/GLES2/gl2platform.h +++ b/gpu/GLES2/gl2platform.h diff --git a/gpu/command_buffer/common/GLES2/gl2types.h b/gpu/GLES2/gl2types.h index 97fbe02..97fbe02 100644 --- a/gpu/command_buffer/common/GLES2/gl2types.h +++ b/gpu/GLES2/gl2types.h diff --git a/gpu/command_buffer/common/KHR/khrplatform.h b/gpu/KHR/khrplatform.h index 8341f71b..8341f71b 100644 --- a/gpu/command_buffer/common/KHR/khrplatform.h +++ b/gpu/KHR/khrplatform.h diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc index ed04e30..4f9d725 100644 --- a/gpu/command_buffer/client/cmd_buffer_helper.cc +++ b/gpu/command_buffer/client/cmd_buffer_helper.cc @@ -4,8 +4,8 @@ // This file contains the implementation of the command buffer helper class. -#include "gpu/command_buffer/client/cmd_buffer_helper.h" -#include "gpu/command_buffer/common/command_buffer.h" +#include "../client/cmd_buffer_helper.h" +#include "../common/command_buffer.h" namespace gpu { diff --git a/gpu/command_buffer/client/cmd_buffer_helper.h b/gpu/command_buffer/client/cmd_buffer_helper.h index c65a23a..62d689c 100644 --- a/gpu/command_buffer/client/cmd_buffer_helper.h +++ b/gpu/command_buffer/client/cmd_buffer_helper.h @@ -7,10 +7,10 @@ #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ -#include "gpu/command_buffer/common/logging.h" -#include "gpu/command_buffer/common/constants.h" -#include "gpu/command_buffer/common/cmd_buffer_common.h" -#include "gpu/command_buffer/common/command_buffer.h" +#include "../common/logging.h" +#include "../common/constants.h" +#include "../common/cmd_buffer_common.h" +#include "../common/command_buffer.h" namespace gpu { diff --git a/gpu/command_buffer/client/fenced_allocator.cc b/gpu/command_buffer/client/fenced_allocator.cc index 8cc6761..57a35fde 100644 --- a/gpu/command_buffer/client/fenced_allocator.cc +++ b/gpu/command_buffer/client/fenced_allocator.cc @@ -4,9 +4,9 @@ // This file contains the implementation of the FencedAllocator class. -#include "gpu/command_buffer/client/fenced_allocator.h" +#include "../client/fenced_allocator.h" #include <algorithm> -#include "gpu/command_buffer/client/cmd_buffer_helper.h" +#include "../client/cmd_buffer_helper.h" namespace gpu { diff --git a/gpu/command_buffer/client/fenced_allocator.h b/gpu/command_buffer/client/fenced_allocator.h index ab68c1a..8f69743 100644 --- a/gpu/command_buffer/client/fenced_allocator.h +++ b/gpu/command_buffer/client/fenced_allocator.h @@ -8,8 +8,7 @@ #define GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ #include <vector> -#include "base/basictypes.h" -#include "gpu/command_buffer/common/logging.h" +#include "../common/logging.h" namespace gpu { class CommandBufferHelper; diff --git a/gpu/command_buffer/client/gles2_c_lib.cc b/gpu/command_buffer/client/gles2_c_lib.cc index 305e93cc..74cc431 100644 --- a/gpu/command_buffer/client/gles2_c_lib.cc +++ b/gpu/command_buffer/client/gles2_c_lib.cc @@ -4,13 +4,13 @@ // These functions emluate GLES2 over command buffers for C. -#include "gpu/command_buffer/client/gles2_lib.h" +#include "../client/gles2_lib.h" extern "C" { // Include the auto-generated part of this file. We split this because it means // we can easily edit the non-auto generated parts right here in this file // instead of having to edit some template or the code generator. -#include "gpu/command_buffer/client/gles2_c_lib_autogen.h" +#include "../client/gles2_c_lib_autogen.h" } // extern "C" diff --git a/gpu/command_buffer/client/gles2_cmd_helper.cc b/gpu/command_buffer/client/gles2_cmd_helper.cc index a3d58d6..8f2bf45 100644 --- a/gpu/command_buffer/client/gles2_cmd_helper.cc +++ b/gpu/command_buffer/client/gles2_cmd_helper.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/client/gles2_cmd_helper.h" +#include "../client/gles2_cmd_helper.h" namespace gpu { diff --git a/gpu/command_buffer/client/gles2_cmd_helper.h b/gpu/command_buffer/client/gles2_cmd_helper.h index 015ce0e..a4f31aa 100644 --- a/gpu/command_buffer/client/gles2_cmd_helper.h +++ b/gpu/command_buffer/client/gles2_cmd_helper.h @@ -5,8 +5,8 @@ #ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_CMD_HELPER_H_ #define GPU_COMMAND_BUFFER_CLIENT_GLES2_CMD_HELPER_H_ -#include "gpu/command_buffer/client/cmd_buffer_helper.h" -#include "gpu/command_buffer/common/gles2_cmd_format.h" +#include "../client/cmd_buffer_helper.h" +#include "../common/gles2_cmd_format.h" namespace gpu { namespace gles2 { @@ -23,7 +23,7 @@ class GLES2CmdHelper : public CommandBufferHelper { // Include the auto-generated part of this class. We split this because it // means we can easily edit the non-auto generated parts right here in this // file instead of having to edit some template or the code generator. - #include "gpu/command_buffer/client/gles2_cmd_helper_autogen.h" + #include "../client/gles2_cmd_helper_autogen.h" // Helpers that could not be auto-generated. // TODO(gman): Auto generate these. diff --git a/gpu/command_buffer/client/gles2_demo_cc.cc b/gpu/command_buffer/client/gles2_demo_cc.cc index 43115ef..acb5be3 100644 --- a/gpu/command_buffer/client/gles2_demo_cc.cc +++ b/gpu/command_buffer/client/gles2_demo_cc.cc @@ -9,10 +9,13 @@ #include "gpu/command_buffer/common/logging.h" #include <math.h> -#include <GLES2/gl2.h> - #include <string> +// This is here so we have at least some idea that the inline path is working. +#define GLES2_INLINE_OPTIMIZATION +#include <GLES2/gl2.h> +#include "gpu/command_buffer/common/logging.h" + namespace { GLuint g_texture = 0; diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 8e212d6..f7bf3ad 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -4,8 +4,8 @@ // A class to emluate GLES2 over command buffers. -#include "gpu/command_buffer/client/gles2_implementation.h" -#include "gpu/command_buffer/common/gles2_cmd_utils.h" +#include "../client/gles2_implementation.h" +#include "../common/gles2_cmd_utils.h" namespace gpu { namespace gles2 { diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h index 339ed4b..bb69353 100644 --- a/gpu/command_buffer/client/gles2_implementation.h +++ b/gpu/command_buffer/client/gles2_implementation.h @@ -8,10 +8,10 @@ #include <map> #include <string> #include <vector> -#include "gpu/command_buffer/common/gles2_cmd_utils.h" -#include "gpu/command_buffer/client/gles2_cmd_helper.h" -#include "gpu/command_buffer/client/id_allocator.h" -#include "gpu/command_buffer/client/fenced_allocator.h" +#include "../common/gles2_cmd_utils.h" +#include "../client/gles2_cmd_helper.h" +#include "../client/id_allocator.h" +#include "../client/fenced_allocator.h" namespace gpu { namespace gles2 { @@ -41,7 +41,7 @@ class GLES2Implementation { // Include the auto-generated part of this class. We split this because // it means we can easily edit the non-auto generated parts right here in // this file instead of having to edit some template or the code generator. - #include "gpu/command_buffer/client/gles2_implementation_autogen.h" + #include "../client/gles2_implementation_autogen.h" private: // Makes a set of Ids for glGen___ functions. diff --git a/gpu/command_buffer/client/gles2_lib.cc b/gpu/command_buffer/client/gles2_lib.cc index 5753715..d80d4e1 100644 --- a/gpu/command_buffer/client/gles2_lib.cc +++ b/gpu/command_buffer/client/gles2_lib.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/client/gles2_lib.h" -#include "gpu/command_buffer/common/thread_local.h" +#include "../client/gles2_lib.h" +#include "../common/thread_local.h" namespace gles2 { namespace { diff --git a/gpu/command_buffer/client/gles2_lib.h b/gpu/command_buffer/client/gles2_lib.h index 2242cc8..799cd4e 100644 --- a/gpu/command_buffer/client/gles2_lib.h +++ b/gpu/command_buffer/client/gles2_lib.h @@ -7,7 +7,7 @@ #ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_LIB_H_ #define GPU_COMMAND_BUFFER_CLIENT_GLES2_LIB_H_ -#include "gpu/command_buffer/client/gles2_implementation.h" +#include "../client/gles2_implementation.h" namespace gles2 { diff --git a/gpu/command_buffer/client/id_allocator.cc b/gpu/command_buffer/client/id_allocator.cc index 64796e9..e6f9b6c 100644 --- a/gpu/command_buffer/client/id_allocator.cc +++ b/gpu/command_buffer/client/id_allocator.cc @@ -4,7 +4,8 @@ // This file contains the implementation of IdAllocator. -#include "gpu/command_buffer/client/id_allocator.h" +#include "../client/id_allocator.h" +#include "../common/logging.h" namespace gpu { diff --git a/gpu/command_buffer/client/id_allocator.h b/gpu/command_buffer/client/id_allocator.h index 2731366..8e1ccdb 100644 --- a/gpu/command_buffer/client/id_allocator.h +++ b/gpu/command_buffer/client/id_allocator.h @@ -8,12 +8,15 @@ #define GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ #include <vector> -#include "base/basictypes.h" -#include "gpu/command_buffer/common/types.h" -#include "gpu/command_buffer/common/resource.h" +#include "../common/types.h" namespace gpu { +// A resource ID, key to the resource maps. +typedef uint32 ResourceId; +// Invalid resource ID. +static const ResourceId kInvalidResource = 0xffffffffU; + // A class to manage the allocation of resource IDs. It uses a bitfield stored // into a vector of unsigned ints. class IdAllocator { diff --git a/gpu/command_buffer/common/cmd_buffer_common.cc b/gpu/command_buffer/common/cmd_buffer_common.cc index bf965cc..974bed9 100644 --- a/gpu/command_buffer/common/cmd_buffer_common.cc +++ b/gpu/command_buffer/common/cmd_buffer_common.cc @@ -5,7 +5,7 @@ // This file contains the binary format definition of the command buffer and // command buffer commands. -#include "gpu/command_buffer/common/cmd_buffer_common.h" +#include "../common/cmd_buffer_common.h" namespace gpu { #if !defined(OS_WIN) diff --git a/gpu/command_buffer/common/cmd_buffer_common.h b/gpu/command_buffer/common/cmd_buffer_common.h index 222b440..0ab81ed 100644 --- a/gpu/command_buffer/common/cmd_buffer_common.h +++ b/gpu/command_buffer/common/cmd_buffer_common.h @@ -7,10 +7,9 @@ #ifndef GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ #define GPU_COMMAND_BUFFER_COMMON_CMD_BUFFER_COMMON_H_ -#include "base/basictypes.h" -#include "gpu/command_buffer/common/types.h" -#include "gpu/command_buffer/common/bitfield_helpers.h" -#include "gpu/command_buffer/common/logging.h" +#include "../common/types.h" +#include "../common/bitfield_helpers.h" +#include "../common/logging.h" namespace gpu { diff --git a/gpu/command_buffer/common/command_buffer.h b/gpu/command_buffer/common/command_buffer.h index b14c35a5..106d9b3 100644 --- a/gpu/command_buffer/common/command_buffer.h +++ b/gpu/command_buffer/common/command_buffer.h @@ -5,9 +5,8 @@ #ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ -#include "base/basictypes.h" -#include "gpu/command_buffer/common/buffer.h" -#include "gpu/command_buffer/common/constants.h" +#include "../common/buffer.h" +#include "../common/constants.h" namespace gpu { diff --git a/gpu/command_buffer/common/command_buffer_mock.h b/gpu/command_buffer/common/command_buffer_mock.h index e65c090..eb78b83 100644 --- a/gpu/command_buffer/common/command_buffer_mock.h +++ b/gpu/command_buffer/common/command_buffer_mock.h @@ -5,7 +5,7 @@ #ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_MOCK_H_ #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_MOCK_H_ -#include "gpu/command_buffer/common/command_buffer.h" +#include "../common/command_buffer.h" #include "testing/gmock/include/gmock/gmock.h" namespace gpu { diff --git a/gpu/command_buffer/common/constants.h b/gpu/command_buffer/common/constants.h index 2359bea..e884e2f 100644 --- a/gpu/command_buffer/common/constants.h +++ b/gpu/command_buffer/common/constants.h @@ -5,7 +5,7 @@ #ifndef GPU_COMMAND_BUFFER_COMMON_CONSTANTS_H_ #define GPU_COMMAND_BUFFER_COMMON_CONSTANTS_H_ -#include "base/basictypes.h" +#include "../common/types.h" namespace gpu { diff --git a/gpu/command_buffer/common/gles2_cmd_format.cc b/gpu/command_buffer/common/gles2_cmd_format.cc index 48695e5..8151d8b 100644 --- a/gpu/command_buffer/common/gles2_cmd_format.cc +++ b/gpu/command_buffer/common/gles2_cmd_format.cc @@ -7,12 +7,12 @@ // We explicitly do NOT include gles2_cmd_format.h here because client side // and service side have different requirements. -#include "gpu/command_buffer/common/cmd_buffer_common.h" +#include "../common/cmd_buffer_common.h" namespace gpu { namespace gles2 { -#include "gpu/command_buffer/common/gles2_cmd_ids_autogen.h" +#include "../common/gles2_cmd_ids_autogen.h" const char* GetCommandName(CommandId id) { static const char* const names[] = { diff --git a/gpu/command_buffer/common/gles2_cmd_format.h b/gpu/command_buffer/common/gles2_cmd_format.h index 4f6f649..7660eb5 100644 --- a/gpu/command_buffer/common/gles2_cmd_format.h +++ b/gpu/command_buffer/common/gles2_cmd_format.h @@ -11,7 +11,7 @@ // the GL headers where as client side code includes the Chrome version. Also // the unit test code must include a mock GL header. #if defined(UNIT_TEST) -#include "gpu/command_buffer/service/gl_mock.h" +#include "../service/gl_mock.h" #elif defined(GLES2_GPU_SERVICE) #include <GL/glew.h> // NOLINT #if defined(OS_WIN) @@ -21,11 +21,10 @@ #include <GLES2/gl2types.h> // NOLINT #endif -#include "base/basictypes.h" -#include "gpu/command_buffer/common/types.h" -#include "gpu/command_buffer/common/bitfield_helpers.h" -#include "gpu/command_buffer/common/cmd_buffer_common.h" -#include "gpu/command_buffer/common/gles2_cmd_ids.h" +#include "../common/types.h" +#include "../common/bitfield_helpers.h" +#include "../common/cmd_buffer_common.h" +#include "../common/gles2_cmd_ids.h" namespace gpu { namespace gles2 { @@ -83,7 +82,7 @@ COMPILE_ASSERT(offsetof(SizedResult<int8>, size) == 0, COMPILE_ASSERT(offsetof(SizedResult<int8>, data) == 4, OffsetOf_SizedResult_data_not_4); -#include "gpu/command_buffer/common/gles2_cmd_format_autogen.h" +#include "../common/gles2_cmd_format_autogen.h" // These are hand written commands. // TODO(gman): Attempt to make these auto-generated. diff --git a/gpu/command_buffer/common/gles2_cmd_ids.h b/gpu/command_buffer/common/gles2_cmd_ids.h index b701c91..f5dfae3 100644 --- a/gpu/command_buffer/common/gles2_cmd_ids.h +++ b/gpu/command_buffer/common/gles2_cmd_ids.h @@ -7,12 +7,12 @@ #ifndef GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_IDS_H_ #define GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_IDS_H_ -#include "gpu/command_buffer/common/cmd_buffer_common.h" +#include "../common/cmd_buffer_common.h" namespace gpu { namespace gles2 { -#include "gpu/command_buffer/common/gles2_cmd_ids_autogen.h" +#include "../common/gles2_cmd_ids_autogen.h" const char* GetCommandName(CommandId command_id); diff --git a/gpu/command_buffer/common/gles2_cmd_utils.cc b/gpu/command_buffer/common/gles2_cmd_utils.cc index 7587dd8..3421fc4 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils.cc +++ b/gpu/command_buffer/common/gles2_cmd_utils.cc @@ -5,8 +5,8 @@ // This file is here so other GLES2 related files can have a common set of // includes where appropriate. -#include "gpu/command_buffer/common/gles2_cmd_utils.h" -#include "gpu/command_buffer/common/gles2_cmd_format.h" +#include "../common/gles2_cmd_utils.h" +#include "../common/gles2_cmd_format.h" namespace gpu { namespace gles2 { diff --git a/gpu/command_buffer/common/gles2_cmd_utils.h b/gpu/command_buffer/common/gles2_cmd_utils.h index 318d2d8..e9ad91a 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils.h +++ b/gpu/command_buffer/common/gles2_cmd_utils.h @@ -8,8 +8,7 @@ #ifndef GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ #define GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_UTILS_H_ -#include "base/basictypes.h" -#include "gpu/command_buffer/common/types.h" +#include "../common/types.h" namespace gpu { namespace gles2 { diff --git a/gpu/command_buffer/common/resource.cc b/gpu/command_buffer/common/resource.cc deleted file mode 100644 index ffcbb57..0000000 --- a/gpu/command_buffer/common/resource.cc +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2009 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. - -// This file contains the implementation of the helper functions for resources. - -#include "gpu/command_buffer/common/resource.h" - -namespace gpu { - -namespace texture { - -// Gets the number of bytes per block for a given format. -unsigned int GetBytesPerBlock(Format format) { - switch (format) { - case kXRGB8: - case kARGB8: - case kR32F: - return 4; - case kABGR16F: - return 8; - case kABGR32F: - return 16; - case kDXT1: - return 8; - case kUnknown: - default: - // TODO(petersont): Add DXT3/5 support. - LOG(FATAL) << "Invalid format"; - return 1; - } -} - -// Gets the width of a block for a given format. -unsigned int GetBlockSizeX(Format format) { - switch (format) { - case kXRGB8: - case kARGB8: - case kABGR16F: - case kR32F: - case kABGR32F: - return 1; - case kDXT1: - return 4; - case kUnknown: - default: - // TODO(petersont): Add DXT3/5 support. - LOG(FATAL) << "Invalid format"; - return 1; - } -} - -// Gets the height of a block for a given format. -unsigned int GetBlockSizeY(Format format) { - // NOTE: currently only supported formats use square blocks. - return GetBlockSizeX(format); -} - -} // namespace texture - -namespace effect_param { - -// Gets the size of the data of a given parameter type. -unsigned int GetDataSize(DataType type) { - switch (type) { - case kUnknown: - return 0; - case kFloat1: - return sizeof(float); // NOLINT - case kFloat2: - return sizeof(float) * 2; // NOLINT - case kFloat3: - return sizeof(float) * 3; // NOLINT - case kFloat4: - return sizeof(float) * 4; // NOLINT - case kMatrix4: - return sizeof(float) * 16; // NOLINT - case kInt: - return sizeof(int); // NOLINT - case kBool: - return sizeof(bool); // NOLINT - case kSampler: - return sizeof(ResourceId); // NOLINT - case kTexture: - return sizeof(ResourceId); // NOLINT - case kNumTypes: - case kMake32Bit: - default: - LOG(FATAL) << "Invalid type."; - return 0; - } -} - -} // namespace effect_param - -} // namespace gpu diff --git a/gpu/command_buffer/common/resource.h b/gpu/command_buffer/common/resource.h deleted file mode 100644 index f72395a..0000000 --- a/gpu/command_buffer/common/resource.h +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 2009 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. - -// This file contains definitions for resource flags, enums, and helper -// functions. - -#ifndef GPU_COMMAND_BUFFER_COMMON_RESOURCE_H_ -#define GPU_COMMAND_BUFFER_COMMON_RESOURCE_H_ - -#include <algorithm> -#include "base/basictypes.h" -#include "gpu/command_buffer/common/types.h" -#include "gpu/command_buffer/common/logging.h" - -namespace gpu { - -// A resource ID, key to the resource maps. -typedef uint32 ResourceId; -// Invalid resource ID. -static const ResourceId kInvalidResource = 0xffffffffU; - -namespace vertex_buffer { -// Vertex buffer flags. -enum Flags { - kNone = 0x00, - kDynamic = 0x01, // This vertex buffer is dynamic and is expected to have - // its data updated often. -}; -} // namespace vertex_buffer - -namespace index_buffer { -// Index buffer flags. -enum Flags { - kNone = 0x00, - kDynamic = 0x01, // This index buffer is dynamic and is expected to have - // its data updated often. - kIndex32Bit = 0x02, // Indices contained in this index buffer are 32 bits - // (unsigned int) instead of 16 bit (unsigned short). -}; -} // namespace index_buffer - -namespace vertex_struct { -// Semantics for input data. -enum Semantic { - kUnknownSemantic = -1, - kPosition = 0, - kNormal, - kColor, - kTexCoord, - kNumSemantics -}; - -// Input data types. -enum Type { - kFloat1, - kFloat2, - kFloat3, - kFloat4, - kUChar4N, - kNumTypes -}; -} // namespace vertex_struct - -namespace effect_param { -enum DataType { - kUnknown, // A parameter exists in the effect, but the type is not - // representable (e.g. MATRIX3x4). - kFloat1, - kFloat2, - kFloat3, - kFloat4, - kMatrix4, - kInt, - kBool, - kSampler, - kTexture, - kNumTypes, - kMake32Bit = 0x7fffffff, -}; -COMPILE_ASSERT(sizeof(DataType) == 4, DataType_should_be_32_bits); - -// Gets the size of the data of a particular type. -unsigned int GetDataSize(DataType type); - -// Structure describing a parameter, filled in by the -// GAPIInterface::GetParamDesc call. -struct Desc { - Uint32 size; // the total memory size needed for the complete - // description. - Uint32 name_offset; // the offset of the parameter name, relative to - // the beginning of the structure. May be 0 if the - // name doesn't fit into the memory buffer. - Uint32 name_size; // the size of the parameter name, including the - // terminating nul character. Will always be set - // even if the name doesn't fit into the buffer. - Uint32 semantic_offset; // the offset of the parameter semantic, relative - // to the beginning of the structure. May be 0 if - // the semantic doesn't fit into the memory - // buffer. - Uint32 semantic_size; // the size of the parameter semantic, including - // the terminating nul character. Will always be - // set even if the semantic doesn't fit into the - // buffer. - Uint32 num_elements; // the number of entries if the parameter is an array - // 0 otherwise. - DataType data_type; // the data type of the parameter. - Uint32 data_size; // the size of the parameter data, in bytes. -}; -} // namespace effect_param - -namespace effect_stream { -struct Desc { - Desc() - : semantic(vertex_struct::kUnknownSemantic), - semantic_index(0) {} - Desc(Uint32 semantic, Uint32 semantic_index) - : semantic(semantic), - semantic_index(semantic_index) {} - Uint32 semantic; // the semantic type - Uint32 semantic_index; -}; -} // namespace effect_stream - -namespace texture { -// Texture flags. -enum Flags { - kNone = 0x00, - kDynamic = 0x01, // This texture is dynamic and is expected to have - // its data updated often. -}; - -// Texel formats. -enum Format { - kUnknown, - kXRGB8, - kARGB8, - kABGR16F, - kR32F, - kABGR32F, - kDXT1 -}; - -// Texture type. -enum Type { - kTexture2d, - kTexture3d, - kTextureCube, -}; - -// Cube map face. -enum Face { - kFacePositiveX, - kFaceNegativeX, - kFacePositiveY, - kFaceNegativeY, - kFacePositiveZ, - kFaceNegativeZ, - kFaceNone = kFacePositiveX, // For non-cube maps. -}; - -// Gets the number of bytes per block for a given texture format. For most -// texture formats, a block is 1x1 texels, but DXT* formats have 4x4 blocks. -unsigned int GetBytesPerBlock(Format format); -// Gets the x dimension of a texel block for a given texture format. For most -// texture formats, a block is 1x1 texels, but DXT* formats have 4x4 blocks. -unsigned int GetBlockSizeX(Format format); -// Gets the y dimension of a texel block for a given texture format. For most -// texture formats, a block is 1x1 texels, but DXT* formats have 4x4 blocks. -unsigned int GetBlockSizeY(Format format); -// Gets the dimension of a mipmap level given the dimension of the base -// level. Every mipmap level is half the size of the previous level, rounding -// down. -inline unsigned int GetMipMapDimension(unsigned int base, - unsigned int level) { - DCHECK_GT(base, 0U); - return std::max(1U, base >> level); -} -} // namespace texture - -namespace sampler { -enum AddressingMode { - kWrap, - kMirrorRepeat, - kClampToEdge, - kClampToBorder, - kNumAddressingMode -}; - -enum FilteringMode { - kNone, - kPoint, - kLinear, - kNumFilteringMode -}; -} // namespace sampler - -} // namespace gpu - -#endif // GPU_COMMAND_BUFFER_COMMON_RESOURCE_H_ diff --git a/gpu/command_buffer/common/types.h b/gpu/command_buffer/common/types.h index a454b14..020612e 100644 --- a/gpu/command_buffer/common/types.h +++ b/gpu/command_buffer/common/types.h @@ -13,6 +13,163 @@ #endif #include <string> +#ifndef __native_client__ +#include "base/basictypes.h" +#else + +typedef signed char schar; +typedef signed char int8; +typedef short int16; +// TODO(mbelshe) Remove these type guards. These are +// temporary to avoid conflicts with npapi.h. +#ifndef _INT32 +#define _INT32 +typedef int int32; +#endif + +// The NSPR system headers define 64-bit as |long| when possible. In order to +// not have typedef mismatches, we do the same on LP64. +#if __LP64__ +typedef long int64; +#else +typedef long long int64; +#endif + +// NOTE: unsigned types are DANGEROUS in loops and other arithmetical +// places. Use the signed types unless your variable represents a bit +// pattern (eg a hash value) or you really need the extra bit. Do NOT +// use 'unsigned' to express "this value should always be positive"; +// use assertions for this. + +typedef unsigned char uint8; +typedef unsigned short uint16; +// TODO(mbelshe) Remove these type guards. These are +// temporary to avoid conflicts with npapi.h. +#ifndef _UINT32 +#define _UINT32 +typedef unsigned int uint32; +#endif + +// See the comment above about NSPR and 64-bit. +#if __LP64__ +typedef unsigned long uint64; +#else +typedef unsigned long long uint64; +#endif + +// A macro to disallow the copy constructor and operator= functions +// This should be used in the private: declarations for a class +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + +// An older, deprecated, politically incorrect name for the above. +#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName) + +// A macro to disallow all the implicit constructors, namely the +// default constructor, copy constructor and operator= functions. +// +// This should be used in the private: declarations for a class +// that wants to prevent anyone from instantiating it. This is +// especially useful for classes containing only static methods. +#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName(); \ + DISALLOW_COPY_AND_ASSIGN(TypeName) + +// The arraysize(arr) macro returns the # of elements in an array arr. +// The expression is a compile-time constant, and therefore can be +// used in defining new arrays, for example. If you use arraysize on +// a pointer by mistake, you will get a compile-time error. +// +// One caveat is that arraysize() doesn't accept any array of an +// anonymous type or a type defined inside a function. In these rare +// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is +// due to a limitation in C++'s template system. The limitation might +// eventually be removed, but it hasn't happened yet. + +// This template function declaration is used in defining arraysize. +// Note that the function doesn't need an implementation, as we only +// use its type. +template <typename T, size_t N> +char (&ArraySizeHelper(T (&array)[N]))[N]; + +// That gcc wants both of these prototypes seems mysterious. VC, for +// its part, can't decide which to use (another mystery). Matching of +// template overloads: the final frontier. +#ifndef _MSC_VER +template <typename T, size_t N> +char (&ArraySizeHelper(const T (&array)[N]))[N]; +#endif + +#define arraysize(array) (sizeof(ArraySizeHelper(array))) + +// The COMPILE_ASSERT macro can be used to verify that a compile time +// expression is true. For example, you could use it to verify the +// size of a static array: +// +// COMPILE_ASSERT(ARRAYSIZE_UNSAFE(content_type_names) == CONTENT_NUM_TYPES, +// content_type_names_incorrect_size); +// +// or to make sure a struct is smaller than a certain size: +// +// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); +// +// The second argument to the macro is the name of the variable. If +// the expression is false, most compilers will issue a warning/error +// containing the name of the variable. + +template <bool> +struct CompileAssert { +}; + +#undef COMPILE_ASSERT +#define COMPILE_ASSERT(expr, msg) \ + typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] + +// Implementation details of COMPILE_ASSERT: +// +// - COMPILE_ASSERT works by defining an array type that has -1 +// elements (and thus is invalid) when the expression is false. +// +// - The simpler definition +// +// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] +// +// does not work, as gcc supports variable-length arrays whose sizes +// are determined at run-time (this is gcc's extension and not part +// of the C++ standard). As a result, gcc fails to reject the +// following code with the simple definition: +// +// int foo; +// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is +// // not a compile-time constant. +// +// - By using the type CompileAssert<(bool(expr))>, we ensures that +// expr is a compile-time constant. (Template arguments must be +// determined at compile-time.) +// +// - The outter parentheses in CompileAssert<(bool(expr))> are necessary +// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written +// +// CompileAssert<bool(expr)> +// +// instead, these compilers will refuse to compile +// +// COMPILE_ASSERT(5 > 0, some_message); +// +// (They seem to think the ">" in "5 > 0" marks the end of the +// template argument list.) +// +// - The array size is (bool(expr) ? 1 : -1), instead of simply +// +// ((expr) ? 1 : -1). +// +// This is to avoid running into a bug in MS VC 7.1, which +// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. + + +#endif + namespace gpu { #if defined(COMPILER_MSVC) typedef short Int16; @@ -27,6 +184,7 @@ typedef uint32_t Uint32; #endif typedef std::string String; + } // namespace gpu #endif // GPU_COMMAND_BUFFER_COMMON_TYPES_H_ diff --git a/gpu/command_buffer/service/resource.cc b/gpu/command_buffer/service/resource.cc deleted file mode 100644 index 05bf49c..0000000 --- a/gpu/command_buffer/service/resource.cc +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2009 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. - -// This file contains the implementation of ResourceMapBase. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/resource.h" - -namespace gpu { - -// Assigns a resource to a resource ID, by setting it at the right location -// into the list, resizing the list if necessary, and destroying an existing -// resource if one existed already. -void ResourceMapBase::Assign(ResourceId id, Resource *resource) { - if (id >= resources_.size()) { - resources_.resize(id + 1, NULL); - } else { - Resource *&entry = resources_[id]; - if (entry) { - delete entry; - entry = NULL; - } - } - DCHECK(resources_[id] == NULL); - resources_[id] = resource; -} - -// Destroys a resource contained in the map, setting its entry to NULL. If -// necessary, this will trim the list. -bool ResourceMapBase::Destroy(ResourceId id) { - if (id >= resources_.size()) { - return false; - } - Resource *&entry = resources_[id]; - if (entry) { - delete entry; - entry = NULL; - - // Removing the last element, we can trim the list. - // TODO: this may not be optimal to do every time. Investigate if it - // becomes an issue, and add a threshold before we resize. - if (id == resources_.size() - 1) { - size_t last_valid = resources_.max_size(); - for (unsigned int i = id; i < resources_.size(); --i) { - if (resources_[i]) { - last_valid = i; - break; - } - } - if (last_valid == resources_.max_size()) { - resources_.clear(); - } else { - resources_.resize(last_valid + 1); - } - } - return true; - } - return false; -} - -// Goes over all non-NULL entries in the list, destroying them, then clears the -// list. -void ResourceMapBase::DestroyAllResources() { - for (Container::iterator i = resources_.begin(); i != resources_.end(); ++i) { - if (*i) { - delete *i; - } - } - resources_.clear(); -} - -} // namespace gpu diff --git a/gpu/command_buffer/service/resource.h b/gpu/command_buffer/service/resource.h deleted file mode 100644 index 90bcb0f..0000000 --- a/gpu/command_buffer/service/resource.h +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright (c) 2009 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. - -// This file contains the definition for resource classes and the resource map. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_RESOURCE_H_ -#define GPU_COMMAND_BUFFER_SERVICE_RESOURCE_H_ - -#include <vector> -#include "base/scoped_ptr.h" -#include "gpu/command_buffer/common/resource.h" - -namespace gpu { - -// Base class for resources, just providing a common Destroy function. -class Resource { - public: - Resource() {} - virtual ~Resource() {} - private: - DISALLOW_COPY_AND_ASSIGN(Resource); -}; - -// VertexBuffer class, representing a vertex buffer resource. -class VertexBuffer: public Resource { - public: - VertexBuffer(unsigned int size, unsigned int flags) - : size_(size), - flags_(flags) {} - virtual ~VertexBuffer() {} - - // Returns the vertex buffer flags. - unsigned int flags() const { return flags_; } - // Sets the vertex buffer flags. - void set_flags(unsigned int flags) { flags_ = flags; } - // Returns the vertex buffer size. - unsigned int size() const { return size_; } - // Sets the vertex buffer size. - void set_size(unsigned int size) { size_ = size; } - protected: - unsigned int size_; - unsigned int flags_; - private: - DISALLOW_COPY_AND_ASSIGN(VertexBuffer); -}; - -// IndexBuffer class, representing an index buffer resource. -class IndexBuffer: public Resource { - public: - IndexBuffer(unsigned int size, unsigned int flags) - : size_(size), - flags_(flags) {} - virtual ~IndexBuffer() {} - - // Returns the index buffer flags. - unsigned int flags() const { return flags_; } - // Sets the index buffer flags. - void set_flags(unsigned int flags) { flags_ = flags; } - // Returns the index buffer size. - unsigned int size() const { return size_; } - // Sets the index buffer size. - void set_size(unsigned int size) { size_ = size; } - protected: - unsigned int size_; - unsigned int flags_; - private: - DISALLOW_COPY_AND_ASSIGN(IndexBuffer); -}; - -// VertexStruct class, representing a vertex struct resource. -class VertexStruct: public Resource { - public: - // The representation of an input data stream. - struct Element { - ResourceId vertex_buffer; - unsigned int offset; - unsigned int stride; - vertex_struct::Type type; - vertex_struct::Semantic semantic; - unsigned int semantic_index; - }; - - explicit VertexStruct(unsigned int count) - : count_(count), - elements_(new Element[count]) { - memset(elements_.get(), 0, count * sizeof(Element)); // NOLINT - } - - // Returns the number of inputs in this struct. - unsigned int count() const { return count_; } - // Returns an element by index. - Element &GetElement(unsigned int i) { - DCHECK_GT(count_, i); - return elements_[i]; - } - protected: - unsigned int count_; - scoped_array<Element> elements_; - private: - DISALLOW_COPY_AND_ASSIGN(VertexStruct); -}; - -// Effect class, representing an effect. -class Effect: public Resource { - public: - Effect() {} - private: - DISALLOW_COPY_AND_ASSIGN(Effect); -}; - -// EffectParam class, representing an effect parameter. -class EffectParam: public Resource { - public: - explicit EffectParam(effect_param::DataType data_type) - : data_type_(data_type) { - } - - // Gets the data type of this parameter. - effect_param::DataType data_type() const { return data_type_; } - private: - effect_param::DataType data_type_; - DISALLOW_COPY_AND_ASSIGN(EffectParam); -}; - -// Texture class, representing a texture resource. -class Texture: public Resource { - public: - Texture(texture::Type type, - unsigned int levels, - texture::Format format, - bool enable_render_surfaces, - unsigned int flags) - : type_(type), - levels_(levels), - format_(format), - render_surfaces_enabled_(enable_render_surfaces), - flags_(flags) {} - virtual ~Texture() {} - - // Returns the type of the texture. - texture::Type type() const { return type_; } - // Returns the texture flags. - unsigned int flags() const { return flags_; } - // Returns the texture format. - texture::Format format() const { return format_; } - // Returns whether the texture supports render surfaces - bool render_surfaces_enabled() const { return render_surfaces_enabled_; } - // Returns the number of mipmap levels in the texture. - unsigned int levels() const { return levels_; } - private: - texture::Type type_; - unsigned int levels_; - texture::Format format_; - bool render_surfaces_enabled_; - unsigned int flags_; - DISALLOW_COPY_AND_ASSIGN(Texture); -}; - -// RenderSurface class, representing a render surface/target -class RenderSurface: public Resource { - public: - RenderSurface() {} - private: - DISALLOW_COPY_AND_ASSIGN(RenderSurface); -}; - -// RenderSurface class, representing a render surface/target -class RenderDepthStencilSurface: public Resource { - public: - RenderDepthStencilSurface() {} - private: - DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurface); -}; - - -// Texture class, representing a sampler resource. -class Sampler: public Resource { - public: - Sampler() {} - private: - DISALLOW_COPY_AND_ASSIGN(Sampler); -}; - -// Base of ResourceMap. Contains most of the implementation of ResourceMap, to -// avoid template bloat. -class ResourceMapBase { - public: - ResourceMapBase() : resources_() {} - ~ResourceMapBase() {} - - // Assigns a resource to a resource ID. Assigning a resource to an ID that - // already has an existing resource will destroy that existing resource. The - // map takes ownership of the resource. - void Assign(ResourceId id, Resource* resource); - // Destroys a resource. - bool Destroy(ResourceId id); - // Destroy all resources. - void DestroyAllResources(); - // Gets a resource by ID. - Resource *Get(ResourceId id) { - return (id < resources_.size()) ? resources_[id] : NULL; - } - private: - typedef std::vector<Resource *> Container; - Container resources_; -}; - -// Resource Map class, allowing resource ID <-> Resource association. This is a -// dense map, optimized for retrieval (O(1)). -template<class T> class ResourceMap { - public: - ResourceMap() : container_() {} - ~ResourceMap() {} - - // Assigns a resource to a resource ID. Assigning a resource to an ID that - // already has an existing resource will destroy that existing resource. The - // map takes ownership of the resource. - void Assign(ResourceId id, T* resource) { - container_.Assign(id, resource); - } - // Destroys a resource. - bool Destroy(ResourceId id) { - return container_.Destroy(id); - } - // Destroy all resources. - void DestroyAllResources() { - return container_.DestroyAllResources(); - } - // Gets a resource by ID. - T *Get(ResourceId id) { - return static_cast<T*>(container_.Get(id)); - } - private: - ResourceMapBase container_; -}; - -} // namespace gpu - -#endif // GPU_COMMAND_BUFFER_SERVICE_RESOURCE_H_ diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 81685c6..22cb17c 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -94,12 +94,12 @@ 'target_name': 'command_buffer_common', 'type': 'static_library', 'include_dirs': [ - 'command_buffer/common', + '.', '..', ], 'all_dependent_settings': { 'include_dirs': [ - 'command_buffer/common', + '.', '..', ], }, @@ -123,8 +123,6 @@ 'command_buffer/common/gles2_cmd_utils.h', 'command_buffer/common/logging.h', 'command_buffer/common/mocks.h', - 'command_buffer/common/resource.cc', - 'command_buffer/common/resource.h', 'command_buffer/common/thread_local.h', 'command_buffer/common/types.h', ], @@ -152,7 +150,7 @@ 'all_dependent_settings': { 'include_dirs': [ # For GLES2/gl2.h - 'command_buffer/common', + '.', ], }, 'sources': [ @@ -192,7 +190,7 @@ 'target_name': 'command_buffer_common_unittests', 'type': 'none', 'include_dirs': [ - 'command_buffer/common', + '.', ], 'dependencies': [ 'gles2_lib', @@ -260,8 +258,6 @@ 'command_buffer/service/mocks.h', 'command_buffer/service/precompile.cc', 'command_buffer/service/precompile.h', - 'command_buffer/service/resource.cc', - 'command_buffer/service/resource.h', ], 'conditions': [ ['OS == "linux"', @@ -327,7 +323,6 @@ 'command_buffer/service/cmd_parser_test.cc', 'command_buffer/service/common_decoder_unittest.cc', 'command_buffer/service/gpu_processor_unittest.cc', - 'command_buffer/service/resource_test.cc', 'command_buffer/service/gl_interface.h', 'command_buffer/service/gl_interface.cc', 'command_buffer/service/gl_mock.h', |