diff options
author | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-21 23:33:17 +0000 |
---|---|---|
committer | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-21 23:33:17 +0000 |
commit | 1b2bfdd574d9c4e21251ec2214e41d8905da4541 (patch) | |
tree | 125a1781c38b840effa24926a16f9599c0631281 /o3d | |
parent | c7cc3f559ecc96849168432c7d3abcca4eeebb4f (diff) | |
download | chromium_src-1b2bfdd574d9c4e21251ec2214e41d8905da4541.zip chromium_src-1b2bfdd574d9c4e21251ec2214e41d8905da4541.tar.gz chromium_src-1b2bfdd574d9c4e21251ec2214e41d8905da4541.tar.bz2 |
This fixes a number of things that are warnings in the Mac compiler.
It fixes at least two real bugs, one in the tar generator, and one
in stream_bank.h.
Review URL: http://codereview.chromium.org/159168
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
45 files changed, 616 insertions, 582 deletions
diff --git a/o3d/base/cross/bits.h b/o3d/base/cross/bits.h index ffb3ccb..7be7b73 100644 --- a/o3d/base/cross/bits.h +++ b/o3d/base/cross/bits.h @@ -55,7 +55,7 @@ static inline int Log2Floor(unsigned int n) { log += shift; } } - DCHECK_EQ(value, 1); + DCHECK_EQ(value, 1u); return log; } diff --git a/o3d/core/cross/bitmap.cc b/o3d/core/cross/bitmap.cc index 320d3e1..98863cf 100644 --- a/o3d/core/cross/bitmap.cc +++ b/o3d/core/cross/bitmap.cc @@ -615,7 +615,7 @@ static void FilterTexel(unsigned int x, } for (unsigned int c = 0; c < components; ++c) { uint64 value = accum[c] / (src_height * src_width); - DCHECK_LE(value, 255); + DCHECK_LE(value, 255u); dst_data[(y * dst_width + x) * components + c] = static_cast<unsigned char>(value); } diff --git a/o3d/core/cross/bitmap.h b/o3d/core/cross/bitmap.h index 60ebb4a..8100b86 100644 --- a/o3d/core/cross/bitmap.h +++ b/o3d/core/cross/bitmap.h @@ -1,439 +1,439 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file contains the declaration of Bitmap helper class that can load
-// raw 24- and 32-bit bitmaps from popular image formats. The Bitmap class
-// also interprets the file format to record the correct OpenGL buffer format.
-//
-// Trying to keep this class independent from the OpenGL API in case they
-// need retargeting later on.
-
-#ifndef O3D_CORE_CROSS_BITMAP_H_
-#define O3D_CORE_CROSS_BITMAP_H_
-
-#include <stdlib.h>
-
-#include "base/cross/bits.h"
-#include "core/cross/types.h"
-#include "core/cross/texture.h"
-
-class FilePath;
-
-namespace o3d {
-
-class MemoryReadStream;
-class RawData;
-class Pack;
-
-// Bitmap provides an API for basic image operations on bitmap images,
-// including scale and crop. The contents of bitmap can be created from
-// a RawData object via LoadFromRawData(), and also can be transfered
-// to mip of a Texure2D or a specific face of TextureCUBE via methods
-// in Texture.
-
-class Bitmap : public ParamObject {
- public:
- typedef SmartPointer<Bitmap> Ref;
-
- explicit Bitmap(ServiceLocator* service_locator);
- virtual ~Bitmap() {}
-
- // We will fail to load images that are bigger than 4kx4k to avoid security
- // risks. GPUs don't usually support bigger sizes anyway.
- // The biggest bitmap buffer size with these dimensions is:
- // 4k x 4k x 4xsizeof(float) x6 x4/3 (x6 for cube maps, x4/3 for mipmaps)
- // That makes 2GB, representable in an unsigned int, so we will avoid wraps.
- static const unsigned int kMaxImageDimension = 4096;
- enum ImageFileType {
- UNKNOWN,
- TGA,
- JPEG,
- PNG,
- DDS,
- };
-
- static bool CheckImageDimensions(unsigned int width, unsigned int height) {
- return width > 0 && height > 0 &&
- width <= kMaxImageDimension && height < kMaxImageDimension;
- }
-
- // Creates a copy of a bitmap, copying the pixels as well.
- // Parameters:
- // source: the source bitmap.
- void CopyDeepFrom(const Bitmap &source) {
- Allocate(source.format_, source.width_, source.height_,
- source.num_mipmaps_, source.is_cubemap_);
- memcpy(image_data(), source.image_data(), GetTotalSize());
- }
-
- // Sets the bitmap parameters from another bitmap, stealing the pixel buffer
- // from the source bitmap.
- // Parameters:
- // source: the source bitmap.
- void SetFrom(Bitmap *source) {
- image_data_.reset();
- format_ = source->format_;
- width_ = source->width_;
- height_ = source->height_;
- num_mipmaps_ = source->num_mipmaps_;
- is_cubemap_ = source->is_cubemap_;
- image_data_.swap(source->image_data_);
- }
-
- // Allocates an uninitialized bitmap with specified parameters.
- // Parameters:
- // format: the format of the pixels.
- // width: the width of the base image.
- // height: the height of the base image.
- // num_mipmaps: the number of mip-maps.
- // cube_map: true if creating a cube map.
- void Allocate(Texture::Format format,
- unsigned int width,
- unsigned int height,
- unsigned int num_mipmaps,
- bool cube_map);
-
- // Allocates a bitmap with initialized parameters.
- // data is zero-initialized
- void AllocateData() {
- image_data_.reset(new unsigned char[GetTotalSize()]);
- memset(image_data_.get(), 0, GetTotalSize());
- }
-
- // Frees the data owned by the bitmap.
- void FreeData() {
- image_data_.reset(NULL);
- }
-
- // Gets the total size of the bitmap data, counting all faces and mip levels.
- unsigned int GetTotalSize() {
- return (is_cubemap_ ? 6 : 1) *
- GetMipChainSize(width_, height_, format_, num_mipmaps_);
- }
-
- // Computes the number of bytes of a texture pixel buffer.
- static unsigned int GetBufferSize(unsigned int width,
- unsigned int height,
- Texture::Format format);
-
- // Gets the image data for a given mip-map level and cube map face.
- // Parameters:
- // level: mip level to get.
- // face: face of cube to get. This parameter is ignored if
- // this bitmap is not a cube map.
- unsigned char *GetMipData(unsigned int level,
- TextureCUBE::CubeFace face) const;
-
- unsigned char *image_data() const { return image_data_.get(); }
- Texture::Format format() const { return format_; }
- unsigned int width() const { return width_; }
- unsigned int height() const { return height_; }
- unsigned int num_mipmaps() const { return num_mipmaps_; }
- bool is_cubemap() const { return is_cubemap_; }
-
- // Returns whether or not the dimensions of the bitmap are power-of-two.
- bool IsPOT() const {
- return ((width_ & (width_ - 1)) == 0) && ((height_ & (height_ - 1)) == 0);
- }
-
- void set_format(Texture::Format format) { format_ = format; }
- void set_width(unsigned int n) { width_ = n; }
- void set_height(unsigned int n) { height_ = n; }
- void set_num_mipmaps(unsigned int n) { num_mipmaps_ = n; }
- void set_is_cubemap(bool is_cubemap) { is_cubemap_ = is_cubemap; }
-
- // Loads a bitmap from a file.
- // Parameters:
- // filename: the name of the file to load.
- // file_type: the type of file to load. If UNKNOWN, the file type will be
- // determined from the filename extension, and if it is not a
- // known extension, all the loaders will be tried.
- // generate_mipmaps: whether or not to generate all the mip-map levels.
- bool LoadFromFile(const FilePath &filepath,
- ImageFileType file_type,
- bool generate_mipmaps);
-
- // Loads a bitmap from a RawData object.
- // Parameters:
- // raw_data: contains the bitmap data in one of the known formats
- // file_type: the format of the bitmap data. If UNKNOWN, the file type
- // will be determined from the extension from raw_data's uri
- // and if it is not a known extension, all the loaders will
- // be tried.
- // generate_mipmaps: whether or not to generate all the mip-map levels.
- bool LoadFromRawData(RawData *raw_data,
- ImageFileType file_type,
- bool generate_mipmaps);
-
- // Loads a bitmap from a MemoryReadStream.
- // Parameters:
- // stream: a stream for the bitmap data in one of the known formats
- // filename: a filename (or uri) of the original bitmap data
- // (may be an empty string)
- // file_type: the format of the bitmap data. If UNKNOWN, the file type
- // will be determined from the extension of |filename|
- // and if it is not a known extension, all the loaders
- // will be tried.
- // generate_mipmaps: whether or not to generate all the mip-map levels.
- bool LoadFromStream(MemoryReadStream *stream,
- const String &filename,
- ImageFileType file_type,
- bool generate_mipmaps);
-
- bool LoadFromPNGStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- bool LoadFromTGAStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- bool LoadFromDDSStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- bool LoadFromJPEGStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- // Saves to a PNG file. The image must be of the ARGB8 format, be a 2D image
- // with no mip-maps (only the base level).
- // Parameters:
- // filename: the name of the file to into.
- // Returns:
- // true if successful.
- bool SaveToPNGFile(const char* filename);
-
- // Checks that the alpha channel for the entire bitmap is 1.0
- bool CheckAlphaIsOne() const;
-
- // Copy pixels from source bitmap. Scales if the width and height of source
- // and dest do not match.
- // Parameters:
- // source_img: source bitmap which would be drawn.
- // source_x: x-coordinate of the starting pixel in the source image.
- // source_x: y-coordinate of the starting pixel in the source image.
- // source_width: width of the source image to draw.
- // source_height: Height of the source image to draw.
- // dest_x: x-coordinate of the starting pixel in the dest image.
- // dest_y: y-coordinate of the starting pixel in the dest image.
- // dest_width: width of the dest image to draw.
- // dest_height: height of the dest image to draw.
- void DrawImage(Bitmap* source_img, int source_x, int source_y,
- int source_width, int source_height,
- int dest_x, int dest_y,
- int dest_width, int dest_height);
-
- // Crop part of an image from src, scale it to an arbitrary size
- // and paste in dest image. Utility function for all DrawImage
- // function in bitmap and textures. Scale operation is based on
- // bilinear interpolation.
- // Note: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // src: source image which would be copied from.
- // src_x: x-coordinate of the starting pixel in the src image.
- // src_y: y-coordinate of the starting pixel in the src image.
- // src_width: width of the part in src image to be croped.
- // src_height: height of the part in src image to be croped.
- // src_img_width: width of the src image.
- // src_img_height: height of the src image.
- // dest: dest image which would be copied to.
- // dest_x: x-coordinate of the starting pixel in the dest image.
- // dest_y: y-coordinate of the starting pixel in the dest image.
- // dest_width: width of the part in dest image to be pasted to.
- // dest_height: height of the part in dest image to be pasted to.
- // dest_img_width: width of the dest image.
- // dest_img_height: height of the src image.
- // component: size of each pixel in terms of array element.
- // Returns:
- // true if crop and scale succeeds.
- static void BilinearInterpolateScale(const uint8* src,
- int src_x, int src_y,
- int src_width, int src_height,
- int src_img_width, int src_img_height,
- uint8* dest,
- int dest_x, int dest_y,
- int dest_width, int dest_height,
- int dest_img_width, int dest_img_height,
- int component);
-
- // Detects the type of image file based on the filename.
- static ImageFileType GetFileTypeFromFilename(const char *filename);
- // Detects the type of image file based on the mime-type.
- static ImageFileType GetFileTypeFromMimeType(const char *mime_type);
-
- // Adds filler alpha byte (0xff) after every pixel. Assumes buffer was
- // allocated with enough storage)
- // can convert RGB -> RGBA, BGR -> BGRA, etc.
- static void XYZToXYZA(unsigned char *image_data, int pixel_count);
-
- // Swaps Red and Blue components in the image.
- static void RGBAToBGRA(unsigned char *image_data, int pixel_count);
-
- // Gets the number of mip-maps required for a full chain starting at
- // width x height.
- static unsigned int GetMipMapCount(unsigned int width, unsigned int height) {
- return 1 + base::bits::Log2Floor(std::max(width, height));
- }
-
- // Gets the smallest power-of-two value that is at least as high as
- // dimension. This is the POT dimension used in ScaleUpToPOT.
- static unsigned int GetPOTSize(unsigned int dimension) {
- return 1 << base::bits::Log2Ceiling(dimension);
- }
-
- // Gets the size of the buffer containing a mip-map chain, given its base
- // width, height, format and number of mip-map levels.
- static unsigned int GetMipChainSize(unsigned int base_width,
- unsigned int base_height,
- Texture::Format format,
- unsigned int num_mipmaps);
-
- // Generates mip-map levels for a single image, using the data from the base
- // level.
- // NOTE: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // base_width: the width of the base image.
- // base_height: the height of the base image.
- // format: the format of the data.
- // num_mipmaps: the number of mipmaps to generate.
- // data: the data containing the base image, and enough space for the
- // mip-maps.
- static bool GenerateMipmaps(unsigned int base_width,
- unsigned int base_height,
- Texture::Format format,
- unsigned int num_mipmaps,
- unsigned char *data);
-
- // Scales an image up to power-of-two textures, using point filtering.
- // NOTE: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // width: the non-power-of-two width of the original image.
- // height: the non-power-of-two height of the original image.
- // format: the format of the data.
- // src: the data containing the source data of the original image.
- // dst: a buffer with enough space for the power-of-two version. Pixels are
- // written from the end to the beginning so dst can be the same buffer as
- // src.
- static bool ScaleUpToPOT(unsigned int width,
- unsigned int height,
- Texture::Format format,
- const unsigned char *src,
- unsigned char *dst);
-
- // Scales an image to an arbitrary size, using point filtering.
- // NOTE: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // src_width: the width of the original image.
- // src_height: the height of the original image.
- // format: the format of the data.
- // src: the data containing the source data of the original image.
- // dst_width: the width of the target image.
- // dst_height: the height of the target image.
- // dst: a buffer with enough space for the target version. Pixels are
- // written from the end to the beginning so dst can be the same buffer as
- // src if the transformation is an upscaling.
- static bool Scale(unsigned int src_width,
- unsigned int src_height,
- Texture::Format format,
- const unsigned char *src,
- unsigned int dst_width,
- unsigned int dst_height,
- unsigned char *dst);
-
- // adjust start points and boundaries when using DrawImage data
- // in bitmap and textures.
- // Parameters:
- // src_x: x-coordinate of the starting pixel in the source image.
- // src_y: y-coordinate of the starting pixel in the source image.
- // src_width: width of the source image to draw.
- // src_height: height of the source image to draw.
- // src_bmp_width: original width of source bitmap.
- // src_bmp_height: original height of source bitmap.
- // dest_x: x-coordinate of the starting pixel in the dest image.
- // dest_y: y-coordinate of the starting pixel in the dest image.
- // dest_width: width of the dest image to draw.
- // dest_height: height of the dest image to draw.
- // dest_bmp_width: original width of dest bitmap.
- // dest_bmp_height: original height of dest bitmap.
- // Returns:
- // false if src or dest rectangle is out of boundaries.
- static bool AdjustDrawImageBoundary(int* src_x, int* src_y,
- int* src_width, int* src_height,
- int src_bmp_width, int src_bmp_height,
- int* dest_x, int* dest_y,
- int* dest_width, int* dest_height,
- int dest_bmp_width, int dest_bmp_height);
-
- private:
- friend class IClassManager;
- static ObjectBase::Ref Create(ServiceLocator* service_locator);
-
- // pointer to the raw bitmap data
- scoped_array<uint8> image_data_;
- // format of the texture this is meant to represent.
- Texture::Format format_;
- // width of the bitmap in pixels.
- unsigned int width_;
- // height of the bitmap in pixels.
- unsigned int height_;
- // number of mipmap levels in this texture.
- unsigned int num_mipmaps_;
- // is this cube-map data
- bool is_cubemap_;
-
- // utility function used in AdjustDrawImageBoundary.
- // It adjusts start point and related measures
- // for a specific dimension.
- // Parameter:
- // src_a: the coordinate which is negative.
- // dest_a: same coordinate in the other image.
- // src_length: length measure of source image to draw.
- // dest_length: length measure of dest image to draw.
- // src_bmp_length: length measure of src image.
- // Returns:
- // true if adjust is successful.
- static bool AdjustDrawImageBoundHelper(int* src_a, int* dest_a,
- int* src_length, int* dest_length,
- int src_bmp_length);
-
- O3D_DECL_CLASS(Bitmap, ParamObject);
- DISALLOW_COPY_AND_ASSIGN(Bitmap);
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_BITMAP_H_
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains the declaration of Bitmap helper class that can load +// raw 24- and 32-bit bitmaps from popular image formats. The Bitmap class +// also interprets the file format to record the correct OpenGL buffer format. +// +// Trying to keep this class independent from the OpenGL API in case they +// need retargeting later on. + +#ifndef O3D_CORE_CROSS_BITMAP_H_ +#define O3D_CORE_CROSS_BITMAP_H_ + +#include <stdlib.h> + +#include "base/cross/bits.h" +#include "core/cross/types.h" +#include "core/cross/texture.h" + +class FilePath; + +namespace o3d { + +class MemoryReadStream; +class RawData; +class Pack; + +// Bitmap provides an API for basic image operations on bitmap images, +// including scale and crop. The contents of bitmap can be created from +// a RawData object via LoadFromRawData(), and also can be transfered +// to mip of a Texure2D or a specific face of TextureCUBE via methods +// in Texture. + +class Bitmap : public ParamObject { + public: + typedef SmartPointer<Bitmap> Ref; + + explicit Bitmap(ServiceLocator* service_locator); + virtual ~Bitmap() {} + + // We will fail to load images that are bigger than 4kx4k to avoid security + // risks. GPUs don't usually support bigger sizes anyway. + // The biggest bitmap buffer size with these dimensions is: + // 4k x 4k x 4xsizeof(float) x6 x4/3 (x6 for cube maps, x4/3 for mipmaps) + // That makes 2GB, representable in an unsigned int, so we will avoid wraps. + static const unsigned int kMaxImageDimension = 4096; + enum ImageFileType { + UNKNOWN, + TGA, + JPEG, + PNG, + DDS, + }; + + static bool CheckImageDimensions(unsigned int width, unsigned int height) { + return width > 0 && height > 0 && + width <= kMaxImageDimension && height < kMaxImageDimension; + } + + // Creates a copy of a bitmap, copying the pixels as well. + // Parameters: + // source: the source bitmap. + void CopyDeepFrom(const Bitmap &source) { + Allocate(source.format_, source.width_, source.height_, + source.num_mipmaps_, source.is_cubemap_); + memcpy(image_data(), source.image_data(), GetTotalSize()); + } + + // Sets the bitmap parameters from another bitmap, stealing the pixel buffer + // from the source bitmap. + // Parameters: + // source: the source bitmap. + void SetFrom(Bitmap *source) { + image_data_.reset(); + format_ = source->format_; + width_ = source->width_; + height_ = source->height_; + num_mipmaps_ = source->num_mipmaps_; + is_cubemap_ = source->is_cubemap_; + image_data_.swap(source->image_data_); + } + + // Allocates an uninitialized bitmap with specified parameters. + // Parameters: + // format: the format of the pixels. + // width: the width of the base image. + // height: the height of the base image. + // num_mipmaps: the number of mip-maps. + // cube_map: true if creating a cube map. + void Allocate(Texture::Format format, + unsigned int width, + unsigned int height, + unsigned int num_mipmaps, + bool cube_map); + + // Allocates a bitmap with initialized parameters. + // data is zero-initialized + void AllocateData() { + image_data_.reset(new unsigned char[GetTotalSize()]); + memset(image_data_.get(), 0, GetTotalSize()); + } + + // Frees the data owned by the bitmap. + void FreeData() { + image_data_.reset(NULL); + } + + // Gets the total size of the bitmap data, counting all faces and mip levels. + unsigned int GetTotalSize() { + return (is_cubemap_ ? 6 : 1) * + GetMipChainSize(width_, height_, format_, num_mipmaps_); + } + + // Computes the number of bytes of a texture pixel buffer. + static unsigned int GetBufferSize(unsigned int width, + unsigned int height, + Texture::Format format); + + // Gets the image data for a given mip-map level and cube map face. + // Parameters: + // level: mip level to get. + // face: face of cube to get. This parameter is ignored if + // this bitmap is not a cube map. + unsigned char *GetMipData(unsigned int level, + TextureCUBE::CubeFace face) const; + + unsigned char *image_data() const { return image_data_.get(); } + Texture::Format format() const { return format_; } + unsigned int width() const { return width_; } + unsigned int height() const { return height_; } + unsigned int num_mipmaps() const { return num_mipmaps_; } + bool is_cubemap() const { return is_cubemap_; } + + // Returns whether or not the dimensions of the bitmap are power-of-two. + bool IsPOT() const { + return ((width_ & (width_ - 1)) == 0) && ((height_ & (height_ - 1)) == 0); + } + + void set_format(Texture::Format format) { format_ = format; } + void set_width(unsigned int n) { width_ = n; } + void set_height(unsigned int n) { height_ = n; } + void set_num_mipmaps(unsigned int n) { num_mipmaps_ = n; } + void set_is_cubemap(bool is_cubemap) { is_cubemap_ = is_cubemap; } + + // Loads a bitmap from a file. + // Parameters: + // filename: the name of the file to load. + // file_type: the type of file to load. If UNKNOWN, the file type will be + // determined from the filename extension, and if it is not a + // known extension, all the loaders will be tried. + // generate_mipmaps: whether or not to generate all the mip-map levels. + bool LoadFromFile(const FilePath &filepath, + ImageFileType file_type, + bool generate_mipmaps); + + // Loads a bitmap from a RawData object. + // Parameters: + // raw_data: contains the bitmap data in one of the known formats + // file_type: the format of the bitmap data. If UNKNOWN, the file type + // will be determined from the extension from raw_data's uri + // and if it is not a known extension, all the loaders will + // be tried. + // generate_mipmaps: whether or not to generate all the mip-map levels. + bool LoadFromRawData(RawData *raw_data, + ImageFileType file_type, + bool generate_mipmaps); + + // Loads a bitmap from a MemoryReadStream. + // Parameters: + // stream: a stream for the bitmap data in one of the known formats + // filename: a filename (or uri) of the original bitmap data + // (may be an empty string) + // file_type: the format of the bitmap data. If UNKNOWN, the file type + // will be determined from the extension of |filename| + // and if it is not a known extension, all the loaders + // will be tried. + // generate_mipmaps: whether or not to generate all the mip-map levels. + bool LoadFromStream(MemoryReadStream *stream, + const String &filename, + ImageFileType file_type, + bool generate_mipmaps); + + bool LoadFromPNGStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + bool LoadFromTGAStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + bool LoadFromDDSStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + bool LoadFromJPEGStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + // Saves to a PNG file. The image must be of the ARGB8 format, be a 2D image + // with no mip-maps (only the base level). + // Parameters: + // filename: the name of the file to into. + // Returns: + // true if successful. + bool SaveToPNGFile(const char* filename); + + // Checks that the alpha channel for the entire bitmap is 1.0 + bool CheckAlphaIsOne() const; + + // Copy pixels from source bitmap. Scales if the width and height of source + // and dest do not match. + // Parameters: + // source_img: source bitmap which would be drawn. + // source_x: x-coordinate of the starting pixel in the source image. + // source_x: y-coordinate of the starting pixel in the source image. + // source_width: width of the source image to draw. + // source_height: Height of the source image to draw. + // dest_x: x-coordinate of the starting pixel in the dest image. + // dest_y: y-coordinate of the starting pixel in the dest image. + // dest_width: width of the dest image to draw. + // dest_height: height of the dest image to draw. + void DrawImage(Bitmap* source_img, int source_x, int source_y, + int source_width, int source_height, + int dest_x, int dest_y, + int dest_width, int dest_height); + + // Crop part of an image from src, scale it to an arbitrary size + // and paste in dest image. Utility function for all DrawImage + // function in bitmap and textures. Scale operation is based on + // bilinear interpolation. + // Note: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // src: source image which would be copied from. + // src_x: x-coordinate of the starting pixel in the src image. + // src_y: y-coordinate of the starting pixel in the src image. + // src_width: width of the part in src image to be croped. + // src_height: height of the part in src image to be croped. + // src_img_width: width of the src image. + // src_img_height: height of the src image. + // dest: dest image which would be copied to. + // dest_x: x-coordinate of the starting pixel in the dest image. + // dest_y: y-coordinate of the starting pixel in the dest image. + // dest_width: width of the part in dest image to be pasted to. + // dest_height: height of the part in dest image to be pasted to. + // dest_img_width: width of the dest image. + // dest_img_height: height of the src image. + // component: size of each pixel in terms of array element. + // Returns: + // true if crop and scale succeeds. + static void BilinearInterpolateScale(const uint8* src, + int src_x, int src_y, + int src_width, int src_height, + int src_img_width, int src_img_height, + uint8* dest, + int dest_x, int dest_y, + int dest_width, int dest_height, + int dest_img_width, int dest_img_height, + int component); + + // Detects the type of image file based on the filename. + static ImageFileType GetFileTypeFromFilename(const char *filename); + // Detects the type of image file based on the mime-type. + static ImageFileType GetFileTypeFromMimeType(const char *mime_type); + + // Adds filler alpha byte (0xff) after every pixel. Assumes buffer was + // allocated with enough storage) + // can convert RGB -> RGBA, BGR -> BGRA, etc. + static void XYZToXYZA(unsigned char *image_data, int pixel_count); + + // Swaps Red and Blue components in the image. + static void RGBAToBGRA(unsigned char *image_data, int pixel_count); + + // Gets the number of mip-maps required for a full chain starting at + // width x height. + static unsigned int GetMipMapCount(unsigned int width, unsigned int height) { + return 1 + base::bits::Log2Floor(std::max(width, height)); + } + + // Gets the smallest power-of-two value that is at least as high as + // dimension. This is the POT dimension used in ScaleUpToPOT. + static unsigned int GetPOTSize(unsigned int dimension) { + return 1 << base::bits::Log2Ceiling(dimension); + } + + // Gets the size of the buffer containing a mip-map chain, given its base + // width, height, format and number of mip-map levels. + static unsigned int GetMipChainSize(unsigned int base_width, + unsigned int base_height, + Texture::Format format, + unsigned int num_mipmaps); + + // Generates mip-map levels for a single image, using the data from the base + // level. + // NOTE: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // base_width: the width of the base image. + // base_height: the height of the base image. + // format: the format of the data. + // num_mipmaps: the number of mipmaps to generate. + // data: the data containing the base image, and enough space for the + // mip-maps. + static bool GenerateMipmaps(unsigned int base_width, + unsigned int base_height, + Texture::Format format, + unsigned int num_mipmaps, + unsigned char *data); + + // Scales an image up to power-of-two textures, using point filtering. + // NOTE: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // width: the non-power-of-two width of the original image. + // height: the non-power-of-two height of the original image. + // format: the format of the data. + // src: the data containing the source data of the original image. + // dst: a buffer with enough space for the power-of-two version. Pixels are + // written from the end to the beginning so dst can be the same buffer as + // src. + static bool ScaleUpToPOT(unsigned int width, + unsigned int height, + Texture::Format format, + const unsigned char *src, + unsigned char *dst); + + // Scales an image to an arbitrary size, using point filtering. + // NOTE: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // src_width: the width of the original image. + // src_height: the height of the original image. + // format: the format of the data. + // src: the data containing the source data of the original image. + // dst_width: the width of the target image. + // dst_height: the height of the target image. + // dst: a buffer with enough space for the target version. Pixels are + // written from the end to the beginning so dst can be the same buffer as + // src if the transformation is an upscaling. + static bool Scale(unsigned int src_width, + unsigned int src_height, + Texture::Format format, + const unsigned char *src, + unsigned int dst_width, + unsigned int dst_height, + unsigned char *dst); + + // adjust start points and boundaries when using DrawImage data + // in bitmap and textures. + // Parameters: + // src_x: x-coordinate of the starting pixel in the source image. + // src_y: y-coordinate of the starting pixel in the source image. + // src_width: width of the source image to draw. + // src_height: height of the source image to draw. + // src_bmp_width: original width of source bitmap. + // src_bmp_height: original height of source bitmap. + // dest_x: x-coordinate of the starting pixel in the dest image. + // dest_y: y-coordinate of the starting pixel in the dest image. + // dest_width: width of the dest image to draw. + // dest_height: height of the dest image to draw. + // dest_bmp_width: original width of dest bitmap. + // dest_bmp_height: original height of dest bitmap. + // Returns: + // false if src or dest rectangle is out of boundaries. + static bool AdjustDrawImageBoundary(int* src_x, int* src_y, + int* src_width, int* src_height, + int src_bmp_width, int src_bmp_height, + int* dest_x, int* dest_y, + int* dest_width, int* dest_height, + int dest_bmp_width, int dest_bmp_height); + + private: + friend class IClassManager; + static ObjectBase::Ref Create(ServiceLocator* service_locator); + + // pointer to the raw bitmap data + scoped_array<uint8> image_data_; + // format of the texture this is meant to represent. + Texture::Format format_; + // width of the bitmap in pixels. + int width_; + // height of the bitmap in pixels. + int height_; + // number of mipmap levels in this texture. + unsigned int num_mipmaps_; + // is this cube-map data + bool is_cubemap_; + + // utility function used in AdjustDrawImageBoundary. + // It adjusts start point and related measures + // for a specific dimension. + // Parameter: + // src_a: the coordinate which is negative. + // dest_a: same coordinate in the other image. + // src_length: length measure of source image to draw. + // dest_length: length measure of dest image to draw. + // src_bmp_length: length measure of src image. + // Returns: + // true if adjust is successful. + static bool AdjustDrawImageBoundHelper(int* src_a, int* dest_a, + int* src_length, int* dest_length, + int src_bmp_length); + + O3D_DECL_CLASS(Bitmap, ParamObject); + DISALLOW_COPY_AND_ASSIGN(Bitmap); +}; + +} // namespace o3d + +#endif // O3D_CORE_CROSS_BITMAP_H_ diff --git a/o3d/core/cross/bitmap_dds.cc b/o3d/core/cross/bitmap_dds.cc index eea1934..a4f9491 100644 --- a/o3d/core/cross/bitmap_dds.cc +++ b/o3d/core/cross/bitmap_dds.cc @@ -176,7 +176,7 @@ static void FlipDXTCImage(unsigned int width, unsigned char *data) { DCHECK(Bitmap::CheckImageDimensions(width, height)); // Height must be a power-of-two. - DCHECK_EQ(height & (height - 1), 0); + DCHECK_EQ(height & (height - 1), 0u); FlipBlockFunction full_block_function = NULL; FlipBlockFunction half_block_function = NULL; unsigned int block_bytes = 0; @@ -341,7 +341,7 @@ bool Bitmap::LoadFromDDSStream(MemoryReadStream *stream, // The size of the buffer needed to hold four-component per pixel // image data, including MIPMaps - int components_per_pixel = 0; + unsigned int components_per_pixel = 0; bool add_filler_alpha = false; bool rgb_to_bgr = false; @@ -478,10 +478,10 @@ bool Bitmap::LoadFromDDSStream(MemoryReadStream *stream, unsigned char *data = image_data.get() + face_size * face; // convert to four components per pixel if necessary if (add_filler_alpha) { - DCHECK_EQ(components_per_pixel, 3); + DCHECK_EQ(components_per_pixel, 3u); XYZToXYZA(data, pixel_count); } else { - DCHECK_EQ(components_per_pixel, 4); + DCHECK_EQ(components_per_pixel, 4u); } if (rgb_to_bgr) RGBAToBGRA(data, pixel_count); diff --git a/o3d/core/cross/bitmap_png.cc b/o3d/core/cross/bitmap_png.cc index ea8a9ac..38f5afe 100644 --- a/o3d/core/cross/bitmap_png.cc +++ b/o3d/core/cross/bitmap_png.cc @@ -199,7 +199,7 @@ bool Bitmap::LoadFromPNGStream(MemoryReadStream *stream, // Turn on interlace handling. REQURIED if you are not using // png_read_image(). To see how to handle interlacing passes, // see the png_read_row() method below: - int png_number_passes = png_set_interlace_handling(png_ptr); + png_set_interlace_handling(png_ptr); // Execute any setup steps for each Transform, i.e. to gamma correct and // add the background to the palette and update info structure. REQUIRED @@ -299,7 +299,7 @@ bool Bitmap::SaveToPNGFile(const char* filename) { } scoped_array<png_bytep> row_pointers(new png_bytep[height_]); - for (unsigned int i = 0; i < height_; ++i) { + for (int i = 0; i < height_; ++i) { row_pointers[height_-1-i] = image_data_.get() + i * width_ * 4; } diff --git a/o3d/core/cross/bounding_box.h b/o3d/core/cross/bounding_box.h index 8ce0c28..d83feb7 100644 --- a/o3d/core/cross/bounding_box.h +++ b/o3d/core/cross/bounding_box.h @@ -50,7 +50,7 @@ class RayIntersectionInfo; class BoundingBox { public: // Constructs an uninitialized BoundingBox marking it as non valid. - BoundingBox() : min_extent_(0, 0, 0), max_extent_(0, 0, 0), valid_(false) { } + BoundingBox() : valid_(false), min_extent_(0, 0, 0), max_extent_(0, 0, 0) { } // Constructs a BoundingBox. // Parameters: diff --git a/o3d/core/cross/buffer.cc b/o3d/core/cross/buffer.cc index 7d4ced1..ba2eb0a 100644 --- a/o3d/core/cross/buffer.cc +++ b/o3d/core/cross/buffer.cc @@ -100,11 +100,11 @@ static FieldCreator g_creators[] = { Buffer::Buffer(ServiceLocator* service_locator) : NamedObject(service_locator), features_(service_locator->GetService<Features>()), - access_mode_(NONE), field_change_count_(0), total_components_(0), stride_(0), num_elements_(0), + access_mode_(NONE), lock_count_(0) { } @@ -474,7 +474,7 @@ bool Buffer::Set(o3d::RawData *raw_data, // Lock before reading in all the fields to avoid locking/unlocking // for each field which would be slower o3d::BufferLockHelper helper(this); - void *buffer_data = helper.GetData(o3d::Buffer::WRITE_ONLY); + helper.GetData(o3d::Buffer::WRITE_ONLY); // Read each field for (int32 ff = 0; ff < num_fields; ++ff) { diff --git a/o3d/core/cross/canvas_paint.cc b/o3d/core/cross/canvas_paint.cc index 3e37877..e5ad327 100644 --- a/o3d/core/cross/canvas_paint.cc +++ b/o3d/core/cross/canvas_paint.cc @@ -95,7 +95,7 @@ class StrokeDrawLooper : public SkDrawLooper { }; StrokeDrawLooper::StrokeDrawLooper(SkScalar radius, SkColor color) - : fColor(color), fRadius(radius) { + : fRadius(radius), fColor(color) { } void StrokeDrawLooper::init(SkCanvas* canvas, SkPaint* paint) { @@ -175,17 +175,17 @@ CanvasPaint::CanvasPaint(ServiceLocator* service_locator) : ParamObject(service_locator), shader_(NULL), needs_update_(true), - color_(Float4(0, 0, 0, 1)), text_align_(LEFT), + color_(Float4(0, 0, 0, 1)), text_size_(10), + text_typeface_(""), + text_style_(NORMAL), + outline_radius_(0), + outline_color_(Float4(0, 0, 0, 1)), shadow_radius_(0), - shadow_color_(Float4(0, 0, 0, 1)), shadow_offset_x_(0), shadow_offset_y_(0), - outline_radius_(0), - outline_color_(Float4(0, 0, 0, 1)), - text_style_(NORMAL), - text_typeface_("") { + shadow_color_(Float4(0, 0, 0, 1)) { sk_paint_.setAntiAlias(true); } diff --git a/o3d/core/cross/client.cc b/o3d/core/cross/client.cc index e0fec9e..b6b103c 100644 --- a/o3d/core/cross/client.cc +++ b/o3d/core/cross/client.cc @@ -70,20 +70,20 @@ namespace o3d { Client::Client(ServiceLocator* service_locator) : service_locator_(service_locator), object_manager_(service_locator), - profiler_(service_locator), error_status_(service_locator), draw_list_manager_(service_locator), counter_manager_(service_locator), transformation_context_(service_locator), semantic_manager_(service_locator), - rendering_(false), - render_tree_called_(false), + profiler_(service_locator), renderer_(service_locator), evaluation_counter_(service_locator), - event_manager_(), - root_(NULL), + rendering_(false), + render_tree_called_(false), render_mode_(RENDERMODE_CONTINUOUS), + event_manager_(), last_tick_time_(0), + root_(NULL), #ifdef OS_WIN calls_(0), #endif diff --git a/o3d/core/cross/display_mode.h b/o3d/core/cross/display_mode.h index 722463a..e663803 100644 --- a/o3d/core/cross/display_mode.h +++ b/o3d/core/cross/display_mode.h @@ -46,11 +46,11 @@ namespace o3d { class DisplayMode { public: DisplayMode() - : valid_(false), - width_(0), + : width_(0), height_(0), refresh_rate_(0), - id_(-1) { // Since this is platform-specific, -1 may well be valid. + id_(-1), // Since this is platform-specific, -1 may well be valid. + valid_(false) { } void Set(int w, int h, int r, int i) { width_ = w; diff --git a/o3d/core/cross/gl/buffer_gl.cc b/o3d/core/cross/gl/buffer_gl.cc index fd65306..916fd245 100644 --- a/o3d/core/cross/gl/buffer_gl.cc +++ b/o3d/core/cross/gl/buffer_gl.cc @@ -57,6 +57,8 @@ GLenum BufferAccessModeToGLenum(Buffer::AccessMode access_mode) { return GL_WRITE_ONLY_ARB; case Buffer::READ_WRITE: return GL_READ_WRITE_ARB; + case Buffer::NONE: + break; } DCHECK(false); return GL_READ_WRITE_ARB; diff --git a/o3d/core/cross/gl/param_cache_gl.cc b/o3d/core/cross/gl/param_cache_gl.cc index c950f3f..28941a5 100644 --- a/o3d/core/cross/gl/param_cache_gl.cc +++ b/o3d/core/cross/gl/param_cache_gl.cc @@ -326,7 +326,6 @@ class EffectParamArraySamplerHandlerGL : public EffectParamHandlerGL { for (int i = 0; i < size; ++i) { Param* untyped_element = param->GetUntypedParam(i); if (untyped_element->IsA(ParamSampler::GetApparentClass())) { - CGparameter cg_element = cgGetArrayParameter(cg_param, i); ParamSampler* element = down_cast<ParamSampler*>(untyped_element); SamplerGL* sampler_gl = down_cast<SamplerGL*>(element->value()); if (!sampler_gl) { @@ -458,6 +457,8 @@ static EffectParamHandlerGL::Ref GetHandlerFromParamAndCgType( handler = EffectParamHandlerGL::Ref( new EffectParamArraySamplerHandlerGL(param_param_array)); break; + default: + break; } } else if (param->IsA(ParamMatrix4::GetApparentClass())) { if (cg_type == CG_FLOAT4x4) { diff --git a/o3d/core/cross/gl/primitive_gl.cc b/o3d/core/cross/gl/primitive_gl.cc index 99d637f..8207792 100644 --- a/o3d/core/cross/gl/primitive_gl.cc +++ b/o3d/core/cross/gl/primitive_gl.cc @@ -250,7 +250,7 @@ void PrimitiveGL::Render(Renderer* renderer, } } if (draw) { - DCHECK_NE(gl_primitive_type, GL_NONE); + DCHECK_NE(gl_primitive_type, static_cast<unsigned int>(GL_NONE)); renderer->AddPrimitivesRendered(number_primitives_); if (indexed()) glDrawElements(gl_primitive_type, diff --git a/o3d/core/cross/gl/renderer_gl.cc b/o3d/core/cross/gl/renderer_gl.cc index dbd34fd..b7197b5 100644 --- a/o3d/core/cross/gl/renderer_gl.cc +++ b/o3d/core/cross/gl/renderer_gl.cc @@ -528,19 +528,19 @@ RendererGL* RendererGL::CreateDefault(ServiceLocator* service_locator) { RendererGL::RendererGL(ServiceLocator* service_locator) : Renderer(service_locator), semantic_manager_(service_locator), -#ifdef OS_MACOSX - mac_agl_context_(0), - mac_cgl_context_(0), -#endif #ifdef OS_WIN gl_context_(NULL), #endif + fullscreen_(0), #ifdef OS_LINUX display_(NULL), window_(0), context_(0), #endif - fullscreen_(0), +#ifdef OS_MACOSX + mac_agl_context_(0), + mac_cgl_context_(0), +#endif render_surface_framebuffer_(0), cg_context_(NULL), alpha_function_ref_changed_(true), diff --git a/o3d/core/cross/gl/sampler_gl.cc b/o3d/core/cross/gl/sampler_gl.cc index 389602f..c64569c 100644 --- a/o3d/core/cross/gl/sampler_gl.cc +++ b/o3d/core/cross/gl/sampler_gl.cc @@ -96,6 +96,8 @@ unsigned int GLMinFilter(Sampler::FilterType o3d_filter, else if (mip_filter == Sampler::LINEAR) return GL_LINEAR_MIPMAP_LINEAR; } + DCHECK(false); + return GL_NONE; } unsigned int GLMagFilter(Sampler::FilterType o3d_filter) { diff --git a/o3d/core/cross/gl/texture_gl.cc b/o3d/core/cross/gl/texture_gl.cc index d4b767f..3238208 100644 --- a/o3d/core/cross/gl/texture_gl.cc +++ b/o3d/core/cross/gl/texture_gl.cc @@ -135,6 +135,8 @@ static GLenum GLFormatFromO3DFormat(Texture::Format format, return 0; } } + case Texture::UNKNOWN_FORMAT: + break; } // failed to find a matching format LOG(ERROR) << "Unrecognized Texture format type."; @@ -269,8 +271,8 @@ Texture2DGL::Texture2DGL(ServiceLocator* service_locator, renderer_(static_cast<RendererGL*>( service_locator->GetService<Renderer>())), gl_texture_(texture), - has_levels_(0), - backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))), + has_levels_(0) { DLOG(INFO) << "Texture2DGL Construct from GLint"; DCHECK_NE(format(), Texture::UNKNOWN_FORMAT); } @@ -355,10 +357,10 @@ Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, } void Texture2DGL::UpdateBackedMipLevel(unsigned int level) { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); DCHECK(backing_bitmap_->image_data()); - DCHECK_EQ(backing_bitmap_->width(), width()); - DCHECK_EQ(backing_bitmap_->height(), height()); + DCHECK_EQ(backing_bitmap_->width(), static_cast<unsigned int>(width())); + DCHECK_EQ(backing_bitmap_->height(), static_cast<unsigned int>(height())); DCHECK_EQ(backing_bitmap_->format(), format()); DCHECK(HasLevel(level)); glBindTexture(GL_TEXTURE_2D, gl_texture_); @@ -394,7 +396,7 @@ bool Texture2DGL::Lock(int level, void** data) { return false; } if (!backing_bitmap_->image_data()) { - DCHECK_EQ(has_levels_, 0); + DCHECK_EQ(has_levels_, 0u); backing_bitmap_->Allocate(format(), width(), height(), levels(), false); } *data = backing_bitmap_->GetMipData(level, TextureCUBE::FACE_POSITIVE_X); @@ -605,11 +607,12 @@ TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, void TextureCUBEGL::UpdateBackedMipLevel(unsigned int level, TextureCUBE::CubeFace face) { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); DCHECK(backing_bitmap_->image_data()); DCHECK(backing_bitmap_->is_cubemap()); - DCHECK_EQ(backing_bitmap_->width(), edge_length()); - DCHECK_EQ(backing_bitmap_->height(), edge_length()); + DCHECK_EQ(backing_bitmap_->width(), static_cast<unsigned int>(edge_length())); + DCHECK_EQ(backing_bitmap_->height(), + static_cast<unsigned int>(edge_length())); DCHECK_EQ(backing_bitmap_->format(), format()); DCHECK(HasLevel(level, face)); glBindTexture(GL_TEXTURE_2D, gl_texture_); @@ -672,7 +675,7 @@ bool TextureCUBEGL::Lock(CubeFace face, int level, void** data) { } if (!backing_bitmap_->image_data()) { for (unsigned int i = 0; i < 6; ++i) { - DCHECK_EQ(has_levels_[i], 0); + DCHECK_EQ(has_levels_[i], 0u); } backing_bitmap_->Allocate(format(), edge_length(), edge_length(), levels(), true); diff --git a/o3d/core/cross/gl/texture_gl.h b/o3d/core/cross/gl/texture_gl.h index cb76660..a647d47 100644 --- a/o3d/core/cross/gl/texture_gl.h +++ b/o3d/core/cross/gl/texture_gl.h @@ -119,7 +119,7 @@ class Texture2DGL : public Texture2D { // Returns true if the backing bitmap has the data for the level. bool HasLevel(unsigned int level) const { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); return (has_levels_ & (1 << level)) != 0; } @@ -196,7 +196,7 @@ class TextureCUBEGL : public TextureCUBE { // Returns true if the backing bitmap has the data for the level. bool HasLevel(unsigned int level, CubeFace face) const { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); return (has_levels_[face] & (1 << level)) != 0; } diff --git a/o3d/core/cross/gl/utils_gl.cc b/o3d/core/cross/gl/utils_gl.cc index f37a8c8..46b5a71c 100644 --- a/o3d/core/cross/gl/utils_gl.cc +++ b/o3d/core/cross/gl/utils_gl.cc @@ -194,7 +194,7 @@ Stream::Semantic GLVertexAttributeToStream(const unsigned int attr, // // TODO: make this a runtime provided value discovered during // Renderer creation. - const int kMaxAttrIndex = 15; + const unsigned int kMaxAttrIndex = 15u; if (attr > kMaxAttrIndex) { //TODO: Figure out how to get errors out of here to the client. DLOG(ERROR) << "Invalid vertex attribute index."; diff --git a/o3d/core/cross/message_queue.cc b/o3d/core/cross/message_queue.cc index b36d1e9..17e981d 100644 --- a/o3d/core/cross/message_queue.cc +++ b/o3d/core/cross/message_queue.cc @@ -296,7 +296,7 @@ bool MessageQueue::ReceiveMessageFromSocket(nacl::Handle socket, #endif // Valid messages must always contain at least the ID of the message - if (message_length >= sizeof(*message_id)) { + if (message_length >= static_cast<int>(sizeof(*message_id))) { // Check if the incoming message requires more space than we have // currently allocated. if (header->flags & nacl::kMessageTruncated) { diff --git a/o3d/core/cross/pack.cc b/o3d/core/cross/pack.cc index 87c64be8..dee5b87 100644 --- a/o3d/core/cross/pack.cc +++ b/o3d/core/cross/pack.cc @@ -168,8 +168,8 @@ Texture* Pack::CreateTextureFromBitmap(Bitmap *bitmap, const String& uri) { return NULL; } - if (bitmap->width() > Texture::MAX_DIMENSION || - bitmap->height() > Texture::MAX_DIMENSION) { + if (bitmap->width() > static_cast<unsigned int>(Texture::MAX_DIMENSION) || + bitmap->height() > static_cast<unsigned int>(Texture::MAX_DIMENSION)) { O3D_ERROR(service_locator()) << "Texture (uri='" << uri << "', size=" << bitmap->width() << "x" << bitmap->height() @@ -281,8 +281,8 @@ Texture2D* Pack::CreateTexture2D(int width, } if (enable_render_surfaces) { - if (Bitmap::GetPOTSize(width) != width || - Bitmap::GetPOTSize(height) != height) { + if (Bitmap::GetPOTSize(width) != static_cast<unsigned int>(width) || + Bitmap::GetPOTSize(height) != static_cast<unsigned int>(height)) { O3D_ERROR(service_locator()) << "Textures with RenderSurfaces enabled must have power-of-two " "dimensions."; @@ -322,7 +322,8 @@ TextureCUBE* Pack::CreateTextureCUBE(int edge_length, if (enable_render_surfaces) { - if (Bitmap::GetPOTSize(edge_length) != edge_length) { + if (Bitmap::GetPOTSize(edge_length) != + static_cast<unsigned int>(edge_length)) { O3D_ERROR(service_locator()) << "Textures with RenderSurfaces enabled must have power-of-two " "dimensions."; @@ -358,8 +359,8 @@ RenderDepthStencilSurface* Pack::CreateDepthStencilSurface(int width, return NULL; } - if (Bitmap::GetPOTSize(width) != width || - Bitmap::GetPOTSize(height) != height) { + if (Bitmap::GetPOTSize(width) != static_cast<unsigned int>(width) || + Bitmap::GetPOTSize(height) != static_cast<unsigned int>(height)) { O3D_ERROR(service_locator()) << "Depth-stencil RenderSurfaces must have power-of-two dimensions."; return NULL; diff --git a/o3d/core/cross/renderer.cc b/o3d/core/cross/renderer.cc index 86407e6..fe80a1a 100644 --- a/o3d/core/cross/renderer.cc +++ b/o3d/core/cross/renderer.cc @@ -93,10 +93,7 @@ bool IsSupportedTextureFormat(Texture::Format format, } // anonymous namespace Renderer::Renderer(ServiceLocator* service_locator) - : service_locator_(service_locator), - service_(service_locator, this), - features_(service_locator), - supports_npot_(false), + : supports_npot_(false), clear_client_(true), need_to_render_(true), current_render_surface_(NULL), @@ -108,12 +105,15 @@ Renderer::Renderer(ServiceLocator* service_locator) draw_elements_culled_(0), draw_elements_rendered_(0), primitives_rendered_(0), + viewport_(0.0f, 0.0f, 1.0f, 1.0f), + depth_range_(0.0f, 1.0f), + service_locator_(service_locator), + service_(service_locator, this), + features_(service_locator), width_(0), height_(0), render_width_(0), render_height_(0), - viewport_(0.0f, 0.0f, 1.0f, 1.0f), - depth_range_(0.0f, 1.0f), dest_x_offset_(0), dest_y_offset_(0) { } @@ -391,7 +391,7 @@ void Renderer::SetInitialStates() { it != state_handler_map_.end(); ++it) { StateHandler *state_handler = it->second; ParamVector& param_stack = state_param_stacks_[state_handler->index()]; - DCHECK_EQ(param_stack.size(), 1); + DCHECK_EQ(param_stack.size(), 1u); state_handler->SetState(this, param_stack[0]); } } @@ -539,7 +539,7 @@ void Renderer::AddDefaultStates() { } void Renderer::RemoveDefaultStates() { - DCHECK_EQ(state_stack_.size(), 1); + DCHECK_EQ(state_stack_.size(), 1u); DCHECK(state_stack_[0] == default_state_); state_stack_.clear(); const NamedParamRefMap& param_map = default_state_->params(); @@ -551,7 +551,7 @@ void Renderer::RemoveDefaultStates() { const StateHandler* state_handler = GetStateHandler(param); DCHECK(state_handler); ParamVector& param_stack = state_param_stacks_[state_handler->index()]; - DCHECK_EQ(param_stack.size(), 1); + DCHECK_EQ(param_stack.size(), 1u); DCHECK(param_stack[0] == param); param_stack.clear(); } diff --git a/o3d/core/cross/shape.cc b/o3d/core/cross/shape.cc index 0d3711d..d4822e4 100644 --- a/o3d/core/cross/shape.cc +++ b/o3d/core/cross/shape.cc @@ -78,7 +78,7 @@ ElementArray Shape::GetElements() const { void Shape::SetElements(const ElementArray& elements) { elements_.resize(elements.size()); - for (int i = 0; i != elements.size(); ++i) { + for (unsigned int i = 0; i != elements.size(); ++i) { elements_[i] = Element::Ref(elements[i]); } } diff --git a/o3d/core/cross/skin.cc b/o3d/core/cross/skin.cc index 7a29109..507ae09 100644 --- a/o3d/core/cross/skin.cc +++ b/o3d/core/cross/skin.cc @@ -48,10 +48,10 @@ const char *Skin::kSerializationID = "SKIN"; Skin::Skin(ServiceLocator* service_locator) : NamedObject(service_locator), - weak_pointer_manager_(this), highest_matrix_index_(0), highest_influences_(0), - info_valid_(false) { + info_valid_(false), + weak_pointer_manager_(this) { } const Skin::Influences* Skin::GetVertexInfluences(unsigned vertex_index) const { @@ -114,12 +114,12 @@ ObjectBase::Ref Skin::Create(ServiceLocator* service_locator) { } SkinEval::StreamInfo::StreamInfo() - : data_(NULL), - buffer_(NULL), - values_(NULL), - stride_(0), - compute_function_(NULL), - copy_function_(NULL) { + : compute_function_(NULL), + copy_function_(NULL), + data_(NULL), + buffer_(NULL), + values_(NULL), + stride_(0) { } namespace { diff --git a/o3d/core/cross/stream_bank.h b/o3d/core/cross/stream_bank.h index 8e1df1a..4d9af76 100644 --- a/o3d/core/cross/stream_bank.h +++ b/o3d/core/cross/stream_bank.h @@ -143,7 +143,7 @@ class StreamBank : public NamedObject { } virtual void OnAfterUnbindInput(Param* old_source) { - master_->number_binds_; + --master_->number_binds_; } private: diff --git a/o3d/core/cross/texture.cc b/o3d/core/cross/texture.cc index 88897c3..0cc784f 100644 --- a/o3d/core/cross/texture.cc +++ b/o3d/core/cross/texture.cc @@ -96,8 +96,8 @@ void Texture2D::DrawImage(Bitmap* src_img, int dst_width, int dst_height, int dest_mip) { DCHECK(src_img->image_data()); - int mip_width = std::max(1, width() >> dest_mip); - int mip_height = std::max(1, height() >> dest_mip); + unsigned int mip_width = std::max(1, width() >> dest_mip); + unsigned int mip_height = std::max(1, height() >> dest_mip); // Clip source and destination rectangles to // source and destination bitmaps. @@ -123,8 +123,10 @@ void Texture2D::DrawImage(Bitmap* src_img, // the entire bitmap on dest image, just perform memcpy. if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && src_img->width() == mip_width && src_img->height() == mip_height && - src_width == src_img->width() && src_height == src_img->height() && - dst_width == mip_width && dst_height == mip_height) { + static_cast<unsigned int>(src_width) == src_img->width() && + static_cast<unsigned int>(src_height) == src_img->height() && + static_cast<unsigned int>(dst_width) == mip_width && + static_cast<unsigned int>(dst_height) == mip_height) { void* data = NULL; if (!Lock(dest_mip, &data)) return; @@ -248,7 +250,7 @@ void TextureCUBE::DrawImage(Bitmap* src_img, CubeFace dest_face, int dest_mip) { DCHECK(src_img->image_data()); - int mip_length = std::max(1, edge_length() >> dest_mip); + unsigned int mip_length = std::max(1, edge_length() >> dest_mip); // Clip source and destination rectangles to // source and destination bitmaps. @@ -274,8 +276,10 @@ void TextureCUBE::DrawImage(Bitmap* src_img, // the entire bitmap on dest image, just perform memcpy. if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && src_img->width() == mip_length && src_img->height() == mip_length && - src_width == src_img->width() && src_height == src_img->height() && - dst_width == mip_length && dst_height == mip_length) { + static_cast<unsigned int>(src_width) == src_img->width() && + static_cast<unsigned int>(src_height) == src_img->height() && + static_cast<unsigned int>(dst_width) == mip_length && + static_cast<unsigned int>(dst_height) == mip_length) { // get mip data by lock method. void* data = NULL; if (!Lock(dest_face, dest_mip, &data)) diff --git a/o3d/core/cross/transform.cc b/o3d/core/cross/transform.cc index 31fb5f0..2157a26 100644 --- a/o3d/core/cross/transform.cc +++ b/o3d/core/cross/transform.cc @@ -320,7 +320,7 @@ ShapeArray Transform::GetShapes() const { void Transform::SetShapes(const ShapeArray& shapes) { shape_array_.resize(shapes.size()); - for (int i = 0; i != shapes.size(); ++i) { + for (unsigned int i = 0; i != shapes.size(); ++i) { shape_array_[i] = Shape::Ref(shapes[i]); } } diff --git a/o3d/import/cross/collada.cc b/o3d/import/cross/collada.cc index c9a6537a..fa06c70 100644 --- a/o3d/import/cross/collada.cc +++ b/o3d/import/cross/collada.cc @@ -165,10 +165,10 @@ Collada::Collada(Pack* pack, const Options& options) dummy_effect_(NULL), dummy_material_(NULL), instance_root_(NULL), + collada_zip_archive_(NULL), cull_enabled_(false), cull_front_(false), front_cw_(false), - collada_zip_archive_(NULL), unique_filename_counter_(0) { } @@ -508,7 +508,7 @@ bool Collada::BuildFloatAnimation(ParamFloat* result, curve->set_pre_infinity(ConvertInfinity(fcd_curve->GetPreInfinity())); curve->set_post_infinity(ConvertInfinity(fcd_curve->GetPostInfinity())); - for (int i = 0; i != fcd_curve->GetKeyCount(); ++i) { + for (unsigned int i = 0; i != fcd_curve->GetKeyCount(); ++i) { FCDAnimationKey* fcd_key = fcd_curve->GetKey(i); switch (fcd_key->interpolation) { case FUDaeInterpolation::STEP: @@ -1512,6 +1512,9 @@ Shape* Collada::BuildSkinnedShape(FCDocument* doc, return NULL; } } + default: + // do nothing + break; } } if (!copied) { @@ -1600,6 +1603,9 @@ Shape* Collada::BuildSkinnedShape(FCDocument* doc, source_stream.semantic_index()); break; } + default: + // do nothing + break; } } if (!copied) { @@ -2414,6 +2420,9 @@ void Collada::AddRenderState(FCDEffectPassState* pass_state, State* state) { << "FRONT_AND_BACK culling is unsupported"; break; } + case FUDaePassStateFaceType::INVALID: + O3D_ERROR(service_locator_) << "INVALID culling type"; + break; } UpdateCullingState(state); break; @@ -2605,6 +2614,9 @@ void Collada::AddRenderState(FCDEffectPassState* pass_state, State* state) { SetBoolState(state, State::kStencilEnableParamName, value); break; } + default: + // do nothing + break; } } @@ -2783,7 +2795,6 @@ void Collada::SetParamsFromMaterial(FCDMaterial* material, LOG_ASSERT(p); String param_name(p->GetReference()); // Check for an effect binding - FCDEffect* effect = material->GetEffect(); FCDEffectProfileFX* profile_fx = FindProfileFX(material->GetEffect()); if (profile_fx) { FCDEffectTechnique* technique = profile_fx->GetTechnique(0); diff --git a/o3d/import/cross/collada.h b/o3d/import/cross/collada.h index 77382d8..a102e08 100644 --- a/o3d/import/cross/collada.h +++ b/o3d/import/cross/collada.h @@ -132,8 +132,8 @@ class Collada { struct Options { Options() : generate_mipmaps(true), - condition_document(false), keep_original_data(false), + condition_document(false), up_axis(0.0f, 0.0f, 0.0f), base_path(FilePath::kCurrentDirectory) {} // Whether or not to generate mip-maps on the textures we load. diff --git a/o3d/import/cross/collada_conditioner.cc b/o3d/import/cross/collada_conditioner.cc index 8ba9661..c5ec51c 100644 --- a/o3d/import/cross/collada_conditioner.cc +++ b/o3d/import/cross/collada_conditioner.cc @@ -53,19 +53,19 @@ FUDaeTextureFilterFunction::FilterFunction LookupFilterFunction( const char* name; FUDaeTextureFilterFunction::FilterFunction func; } functions[] = { - "None", FUDaeTextureFilterFunction::NONE, - "Linear", FUDaeTextureFilterFunction::LINEAR, - "Point", FUDaeTextureFilterFunction::NEAREST, // DX - "Nearest", FUDaeTextureFilterFunction::NEAREST, // GL - "LinearMipmapLinear", FUDaeTextureFilterFunction::LINEAR_MIPMAP_LINEAR, - "LinearMipmapNearest", FUDaeTextureFilterFunction::LINEAR_MIPMAP_NEAREST, - "NearestMipmapNearest", FUDaeTextureFilterFunction::LINEAR_MIPMAP_NEAREST, - "NearestMipmapLinear", FUDaeTextureFilterFunction::NEAREST_MIPMAP_LINEAR, + {"None", FUDaeTextureFilterFunction::NONE}, + {"Linear", FUDaeTextureFilterFunction::LINEAR}, + {"Point", FUDaeTextureFilterFunction::NEAREST}, // DX + {"Nearest", FUDaeTextureFilterFunction::NEAREST}, // GL + {"LinearMipmapLinear", FUDaeTextureFilterFunction::LINEAR_MIPMAP_LINEAR}, + {"LinearMipmapNearest", FUDaeTextureFilterFunction::LINEAR_MIPMAP_NEAREST}, + {"NearestMipmapNearest", FUDaeTextureFilterFunction::LINEAR_MIPMAP_NEAREST}, + {"NearestMipmapLinear", FUDaeTextureFilterFunction::NEAREST_MIPMAP_LINEAR}, // TODO: Once FCollada supports the COLLADA v1.5 spec, // turn this on. // "Anisotropic", FUDaeTextureFilterFunction::ANISOTROPIC, }; - for (int i = 0; i < sizeof(functions) / sizeof(functions[0]); ++i) { + for (size_t i = 0; i < sizeof(functions) / sizeof(functions[0]); ++i) { if (!base::strcasecmp(functions[i].name, name)) { return functions[i].func; } @@ -80,19 +80,19 @@ FUDaeTextureWrapMode::WrapMode LookupWrapMode(const char* name) { const char* name; FUDaeTextureWrapMode::WrapMode mode; } modes[] = { - "None", FUDaeTextureWrapMode::NONE, + {"None", FUDaeTextureWrapMode::NONE}, // DX-style names: - "Wrap", FUDaeTextureWrapMode::WRAP, - "Mirror", FUDaeTextureWrapMode::MIRROR, - "Clamp", FUDaeTextureWrapMode::CLAMP, - "Border", FUDaeTextureWrapMode::BORDER, + {"Wrap", FUDaeTextureWrapMode::WRAP}, + {"Mirror", FUDaeTextureWrapMode::MIRROR}, + {"Clamp", FUDaeTextureWrapMode::CLAMP}, + {"Border", FUDaeTextureWrapMode::BORDER}, // GL-style names: - "Repeat", FUDaeTextureWrapMode::WRAP, - "MirroredRepeat", FUDaeTextureWrapMode::MIRROR, - "ClampToEdge", FUDaeTextureWrapMode::CLAMP, - "ClampToBorder", FUDaeTextureWrapMode::BORDER, + {"Repeat", FUDaeTextureWrapMode::WRAP}, + {"MirroredRepeat", FUDaeTextureWrapMode::MIRROR}, + {"ClampToEdge", FUDaeTextureWrapMode::CLAMP}, + {"ClampToBorder", FUDaeTextureWrapMode::BORDER}, }; - for (int i = 0; i < sizeof(modes) / sizeof(modes[0]); ++i) { + for (size_t i = 0; i < sizeof(modes) / sizeof(modes[0]); ++i) { if (!base::strcasecmp(modes[i].name, name)) { return modes[i].mode; } diff --git a/o3d/import/cross/gz_compressor.cc b/o3d/import/cross/gz_compressor.cc index 6c853e1..e42f2e7 100644 --- a/o3d/import/cross/gz_compressor.cc +++ b/o3d/import/cross/gz_compressor.cc @@ -47,8 +47,8 @@ namespace o3d { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GzCompressor::GzCompressor(StreamProcessor *callback_client) - : callback_client_(callback_client), - stream_is_closed_(false) { + : stream_is_closed_(false), + callback_client_(callback_client) { strm_.zalloc = Z_NULL; strm_.zfree = Z_NULL; strm_.opaque = Z_NULL; diff --git a/o3d/import/cross/memory_stream.h b/o3d/import/cross/memory_stream.h index 00585b6..e71379a 100644 --- a/o3d/import/cross/memory_stream.h +++ b/o3d/import/cross/memory_stream.h @@ -55,13 +55,13 @@ namespace o3d { class MemoryReadStream { public: MemoryReadStream(const uint8 *memory, size_t n) - : memory_(memory), length_(n), read_index_(0) {} + : memory_(memory), read_index_(0), length_(n) {} // Explicit copy constructor MemoryReadStream(const MemoryReadStream &stream) : memory_(stream.memory_), - length_(stream.length_), - read_index_(stream.read_index_) {} + read_index_(stream.read_index_), + length_(stream.length_) {} virtual ~MemoryReadStream() {} @@ -179,13 +179,13 @@ class MemoryWriteStream { MemoryWriteStream() : memory_(NULL), write_index_(0), length_(0) {} MemoryWriteStream(uint8 *memory, size_t n) - : memory_(memory), length_(n), write_index_(0) {} + : memory_(memory), write_index_(0), length_(n) {} // Explicit copy constructor MemoryWriteStream(const MemoryWriteStream &stream) : memory_(stream.memory_), - length_(stream.length_), - write_index_(stream.write_index_) {} + write_index_(stream.write_index_), + length_(stream.length_) {} virtual ~MemoryWriteStream() {} diff --git a/o3d/import/cross/raw_data.cc b/o3d/import/cross/raw_data.cc index deabe37..66e0109 100644 --- a/o3d/import/cross/raw_data.cc +++ b/o3d/import/cross/raw_data.cc @@ -396,7 +396,7 @@ bool RawData::GetTempFilePathFromURI(const String &uri, String filename; // try to retain the original file suffix (.jpg, etc.) - int dot_position = uri.rfind('.'); + std::string::size_type dot_position = uri.rfind('.'); if (dot_position != std::string::npos) { filename = uuid_string + uri.substr(dot_position); } else { diff --git a/o3d/import/cross/tar_generator.cc b/o3d/import/cross/tar_generator.cc index 0b71e69..ed72e05 100644 --- a/o3d/import/cross/tar_generator.cc +++ b/o3d/import/cross/tar_generator.cc @@ -119,7 +119,8 @@ void TarGenerator::WriteHeader(const String& file_name, ::snprintf(p + kGroupIDOffset, 8, "%07o", group_id); // File size - ::snprintf(p + kFileSizeOffset, 12, "%011o", file_size); + ::snprintf(p + kFileSizeOffset, 12, "%011o", + static_cast<unsigned int>(file_size)); // Modification time // TODO: write the correct current time here... @@ -189,7 +190,7 @@ void TarGenerator::ComputeCheckSum(uint8 *header) { checksum += header[i]; } snprintf(reinterpret_cast<char*>(header + kHeaderCheckSumOffset), - 8, "%06o\0\0", checksum); + 8, "%06o%c%c", checksum, 0, 0); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/o3d/import/cross/tar_processor.cc b/o3d/import/cross/tar_processor.cc index d126788..7b14c22 100644 --- a/o3d/import/cross/tar_processor.cc +++ b/o3d/import/cross/tar_processor.cc @@ -64,7 +64,7 @@ int TarProcessor::ProcessBytes(MemoryReadStream *stream, size_t n) { if (header_bytes_read_ == TAR_HEADER_SIZE) { // The tar format stupidly represents size_t values as octal strings!! - size_t file_size = 0; + unsigned int file_size = 0u; sscanf(header_ + kFileSizeOffset, "%o", &file_size); // Check if it's a long filename diff --git a/o3d/import/cross/targz_generator_test.cc b/o3d/import/cross/targz_generator_test.cc index 8715933..3104890 100644 --- a/o3d/import/cross/targz_generator_test.cc +++ b/o3d/import/cross/targz_generator_test.cc @@ -74,15 +74,13 @@ class TarGzTestClient : public StreamProcessor { // Checks that the data from the reference tar.gz file matches the tar.gz // stream we just ge5nerated - void Validate(uint8 *reference_data) { + uint8* compressed_data() { uint8 *received_data = compressed_data_; + return received_data; + } - // on Windows the platform field is different than our reference file - received_data[9] = 3; // Force platform in header to 'UNIX'. - - EXPECT_EQ(0, memcmp(reference_data, - received_data, - compressed_data_.GetLength())); + size_t compressed_data_length() { + return compressed_data_.GetLength(); } #if defined(GENERATE_GOLDEN) @@ -155,7 +153,15 @@ TEST_F(TarGzGeneratorTest, GenerateTarGz) { #endif - test_client.Validate(targz_data); + uint8 *received_data = test_client.compressed_data(); + + // The platform header in our reference file is set to UNIX, so + // force received data to match for all platforms. + received_data[9] = 3; + + EXPECT_EQ(0, memcmp(targz_data, + received_data, + test_client.compressed_data_length())); free(targz_data); free(image_data); diff --git a/o3d/import/cross/zip_archive.cc b/o3d/import/cross/zip_archive.cc index cd7f0455..946915c 100644 --- a/o3d/import/cross/zip_archive.cc +++ b/o3d/import/cross/zip_archive.cc @@ -863,7 +863,7 @@ bool ZipArchive::GetTempFileFromFile(const string &filename, #else // get just the final path component - int pos = filename.rfind('/'); + string::size_type pos = filename.rfind('/'); if (pos != string::npos) { // TODO : need to get "proper" temp dir for user // TODO : need to append GUID to filename diff --git a/o3d/import/mac/collada_conditioner_mac.mm b/o3d/import/mac/collada_conditioner_mac.mm index 97f98fa..cb39e85 100644 --- a/o3d/import/mac/collada_conditioner_mac.mm +++ b/o3d/import/mac/collada_conditioner_mac.mm @@ -99,7 +99,7 @@ bool ColladaConditioner::PreprocessShaderFile(const FilePath& in_filename, NSPipe *pipe = [NSPipe pipe]; [task setStandardOutput:pipe]; [task launch]; - NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile]; + [[pipe fileHandleForReading] readDataToEndOfFile]; return true; } } // end namespace o3d diff --git a/o3d/serializer/cross/serializer.cc b/o3d/serializer/cross/serializer.cc index 25996c8..96dd01b 100644 --- a/o3d/serializer/cross/serializer.cc +++ b/o3d/serializer/cross/serializer.cc @@ -297,7 +297,7 @@ class PropertiesVisitor : public VisitorBase<PropertiesVisitor> { writer_->BeginCompacting(); writer_->OpenArray(); const ElementRefArray& elements = shape->GetElementRefs(); - for (int i = 0; i != elements.size(); ++i) { + for (ElementRefArray::size_type i = 0; i != elements.size(); ++i) { Serialize(writer_, elements[i].Get()); } writer_->CloseArray(); @@ -312,7 +312,8 @@ class PropertiesVisitor : public VisitorBase<PropertiesVisitor> { writer_->OpenArray(); const Skin::MatrixArray& inverse_bind_pose_matrices = skin->inverse_bind_pose_matrices(); - for (int i = 0; i != inverse_bind_pose_matrices.size(); ++i) { + for (Skin::MatrixArray::size_type i = 0; + i != inverse_bind_pose_matrices.size(); ++i) { const Matrix4& matrix = inverse_bind_pose_matrices[i]; Serialize(writer_, matrix); } @@ -327,7 +328,7 @@ class PropertiesVisitor : public VisitorBase<PropertiesVisitor> { writer_->BeginCompacting(); writer_->OpenArray(); const ShapeRefArray& shape_array = transform->GetShapeRefs(); - for (int i = 0; i != shape_array.size(); ++i) { + for (ShapeRefArray::size_type i = 0; i != shape_array.size(); ++i) { Serialize(writer_, shape_array[i]); } writer_->CloseArray(); @@ -427,7 +428,8 @@ class CustomVisitor : public VisitorBase<CustomVisitor> { writer_->OpenArray(); const StreamParamVector& vertex_stream_params = skin_eval->vertex_stream_params(); - for (int i = 0; i != vertex_stream_params.size(); ++i) { + for (StreamParamVector::size_type i = 0; + i != vertex_stream_params.size(); ++i) { const Stream& stream = vertex_stream_params[i]->stream(); writer_->OpenObject(); writer_->WritePropertyName("stream"); @@ -452,7 +454,8 @@ class CustomVisitor : public VisitorBase<CustomVisitor> { writer_->OpenArray(); const StreamParamVector& vertex_stream_params = stream_bank->vertex_stream_params(); - for (int i = 0; i != vertex_stream_params.size(); ++i) { + for (StreamParamVector::size_type i = 0; + i != vertex_stream_params.size(); ++i) { const Stream& stream = vertex_stream_params[i]->stream(); writer_->OpenObject(); writer_->WritePropertyName("stream"); @@ -757,7 +760,8 @@ void Serializer::SerializePack(Pack* pack) { std::vector<const ObjectBase::Class*> classes = class_manager_->GetAllClasses(); - for (int i = 0; i != classes.size(); ++i) { + for (std::vector<const ObjectBase::Class*>::size_type i = 0; + i != classes.size(); ++i) { const ObjectBase::Class* current_class = classes[i]; if (!ObjectBase::ClassIsA(current_class, Param::GetApparentClass())) { std::vector<ObjectBase*> objects_of_class; @@ -771,7 +775,8 @@ void Serializer::SerializePack(Pack* pack) { if (objects_of_class.size() != 0) { writer_->WritePropertyName(current_class->name()); writer_->OpenArray(); - for (int j = 0; j != objects_of_class.size(); ++j) { + for (std::vector<ObjectBase*>::size_type j = 0; + j != objects_of_class.size(); ++j) { writer_->OpenObject(); SerializeObject(objects_of_class[j]); writer_->CloseObject(); diff --git a/o3d/serializer/cross/serializer_binary.cc b/o3d/serializer/cross/serializer_binary.cc index 56793c4..463b165 100644 --- a/o3d/serializer/cross/serializer_binary.cc +++ b/o3d/serializer/cross/serializer_binary.cc @@ -105,9 +105,6 @@ void SerializeBuffer(const Buffer &buffer, MemoryBuffer<uint8> *output) { // Write out the number of elements stream.WriteLittleEndianUInt32(num_elements); - // Make note of stream position at end of header - size_t data_start_position = stream.GetStreamPosition(); - // Write out the data for each field // Write out the specification for the fields for (size_t i = 0; i < num_fields; ++i) { diff --git a/o3d/statsreport/formatter.h b/o3d/statsreport/formatter.h index eab534d..38316a6 100644 --- a/o3d/statsreport/formatter.h +++ b/o3d/statsreport/formatter.h @@ -35,7 +35,7 @@ #ifndef O3D_STATSREPORT_FORMATTER_H__ #define O3D_STATSREPORT_FORMATTER_H__ -#include <strstream> +#include <sstream> #include "base/basictypes.h" #include "metrics.h" @@ -63,13 +63,13 @@ class Formatter { // Terminates the output string and returns it. // It is an error to add metrics after output() is called. - const char *output() { + const std::string output() { output_ << std::ends; return output_.str(); } private: - mutable std::strstream output_; + mutable std::ostringstream output_; DISALLOW_COPY_AND_ASSIGN(Formatter); }; diff --git a/o3d/statsreport/formatter_unittest.cc b/o3d/statsreport/formatter_unittest.cc index 6567efd..f1315ea0 100644 --- a/o3d/statsreport/formatter_unittest.cc +++ b/o3d/statsreport/formatter_unittest.cc @@ -50,5 +50,5 @@ TEST(Formatter, Format) { "&integer1:i=3000" "&boolean1:b=t" "&boolean2:b=f", - formatter.output()); + formatter.output().c_str()); } diff --git a/o3d/statsreport/uploader_aggregation-mac.mm b/o3d/statsreport/uploader_aggregation-mac.mm index ff7d86ef..5037f32 100644 --- a/o3d/statsreport/uploader_aggregation-mac.mm +++ b/o3d/statsreport/uploader_aggregation-mac.mm @@ -112,7 +112,7 @@ static bool ReportMetrics(const char* extra_url_data, DLOG(INFO) << "formatter.output() = " << formatter.output(); return stats_uploader->UploadMetrics(extra_url_data, user_agent, - formatter.output()); + formatter.output().c_str()); } void ResetPersistentMetrics() { diff --git a/o3d/statsreport/uploader_aggregation-posix.cc b/o3d/statsreport/uploader_aggregation-posix.cc index dca530b..91f807b 100644 --- a/o3d/statsreport/uploader_aggregation-posix.cc +++ b/o3d/statsreport/uploader_aggregation-posix.cc @@ -67,7 +67,8 @@ bool ReportMetrics(MetricsAggregatorPosix *aggregator, Formatter formatter(PRODUCT_NAME_STRING, interval); aggregator->FormatMetrics(&formatter); - return UploadMetrics(extra_url_data, user_agent, formatter.output()); + DLOG(INFO) << "formatter.output() = " << formatter.output(); + return UploadMetrics(extra_url_data, user_agent, formatter.output().c_str()); } } // namespace diff --git a/o3d/statsreport/uploader_aggregation-win32.cc b/o3d/statsreport/uploader_aggregation-win32.cc index a22dcf3..d2f438e 100644 --- a/o3d/statsreport/uploader_aggregation-win32.cc +++ b/o3d/statsreport/uploader_aggregation-win32.cc @@ -71,7 +71,7 @@ static bool ReportMetrics(const char* extra_url_data, formatter.AddMetric(*it); DLOG(INFO) << "formatter.output() = " << formatter.output(); return stats_uploader->UploadMetrics(extra_url_data, user_agent, - formatter.output()); + formatter.output().c_str()); } void ResetPersistentMetrics(CRegKey *key) { diff --git a/o3d/tests/archive_files/test2.tar.gz b/o3d/tests/archive_files/test2.tar.gz Binary files differindex 4986e73..3bcb1036 100644 --- a/o3d/tests/archive_files/test2.tar.gz +++ b/o3d/tests/archive_files/test2.tar.gz |