summaryrefslogtreecommitdiffstats
path: root/o3d/core/cross/pack.cc
diff options
context:
space:
mode:
authoryux@google.com <yux@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 01:07:36 +0000
committeryux@google.com <yux@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 01:07:36 +0000
commit128ff759facb55e3c0c1326e97c00b325ac3f484 (patch)
tree868fda83a815ac414abac1466091faced5bc3eb1 /o3d/core/cross/pack.cc
parent267088ffb702c649bfd2c1123f1f9c3f391b69d2 (diff)
downloadchromium_src-128ff759facb55e3c0c1326e97c00b325ac3f484.zip
chromium_src-128ff759facb55e3c0c1326e97c00b325ac3f484.tar.gz
chromium_src-128ff759facb55e3c0c1326e97c00b325ac3f484.tar.bz2
expose bitmap in js.
Review URL: http://codereview.chromium.org/150058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20700 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core/cross/pack.cc')
-rw-r--r--o3d/core/cross/pack.cc52
1 files changed, 45 insertions, 7 deletions
diff --git a/o3d/core/cross/pack.cc b/o3d/core/cross/pack.cc
index 96b06de..87c64be8 100644
--- a/o3d/core/cross/pack.cc
+++ b/o3d/core/cross/pack.cc
@@ -135,14 +135,14 @@ Texture* Pack::CreateTextureFromFile(const String& uri,
// TODO: Add support for volume texture when we have code to load
// them
- Bitmap bitmap;
- if (!bitmap.LoadFromFile(filepath, file_type, generate_mipmaps)) {
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (!bitmap->LoadFromFile(filepath, file_type, generate_mipmaps)) {
O3D_ERROR(service_locator())
<< "Failed to load bitmap file \"" << uri << "\"";
return NULL;
}
- return CreateTextureFromBitmap(&bitmap, uri);
+ return CreateTextureFromBitmap(bitmap, uri);
}
// Creates a Texture object from a file in the current render context format.
@@ -198,7 +198,6 @@ Texture* Pack::CreateTextureFromBitmap(Bitmap *bitmap, const String& uri) {
return texture.Get();
}
-
// Creates a Texture object from RawData and allocates
// the necessary resources for it.
Texture* Pack::CreateTextureFromRawData(RawData *raw_data,
@@ -213,14 +212,53 @@ Texture* Pack::CreateTextureFromRawData(RawData *raw_data,
DLOG(INFO) << "CreateTextureFromRawData(uri='" << uri << "')";
- Bitmap bitmap;
- if (!bitmap.LoadFromRawData(raw_data, Bitmap::UNKNOWN, generate_mips)) {
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (!bitmap->LoadFromRawData(raw_data, Bitmap::UNKNOWN, generate_mips)) {
O3D_ERROR(service_locator())
<< "Failed to load bitmap from raw data \"" << uri << "\"";
return NULL;
}
- return CreateTextureFromBitmap(&bitmap, uri);
+ return CreateTextureFromBitmap(bitmap, uri);
+}
+
+// Create a bitmap object.
+Bitmap* Pack::CreateBitmap(int width, int height,
+ Texture::Format format) {
+ DCHECK(Bitmap::CheckImageDimensions(width, height));
+
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (bitmap.IsNull()) {
+ O3D_ERROR(service_locator())
+ << "Failed to create bitmap object.";
+ return NULL;
+ }
+ bitmap->Allocate(format, width, height, 1, false);
+ if (!bitmap->image_data()) {
+ O3D_ERROR(service_locator())
+ << "Failed to allocate memory for bitmap.";
+ return NULL;
+ }
+ RegisterObject(bitmap);
+ return bitmap.Get();
+}
+
+// Create a new bitmap object from rawdata.
+Bitmap* Pack::CreateBitmapFromRawData(RawData* raw_data) {
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (bitmap.IsNull()) {
+ O3D_ERROR(service_locator())
+ << "Failed to create bitmap object.";
+ return NULL;
+ }
+ if (!bitmap->LoadFromRawData(raw_data, Bitmap::UNKNOWN,
+ false)) {
+ O3D_ERROR(service_locator())
+ << "Failed to load bitmap from raw data.";
+ return NULL;
+ }
+ RegisterObject(bitmap);
+ return bitmap.Get();
}
// Creates a Texture2D object and allocates the necessary resources for it.