summaryrefslogtreecommitdiffstats
path: root/o3d/core/cross/canvas.cc
diff options
context:
space:
mode:
Diffstat (limited to 'o3d/core/cross/canvas.cc')
-rw-r--r--o3d/core/cross/canvas.cc34
1 files changed, 14 insertions, 20 deletions
diff --git a/o3d/core/cross/canvas.cc b/o3d/core/cross/canvas.cc
index 26fabbd..7dccb2d 100644
--- a/o3d/core/cross/canvas.cc
+++ b/o3d/core/cross/canvas.cc
@@ -154,9 +154,8 @@ void Canvas::DrawBitmap(Texture2D* texture2d,
return;
}
- void* texture_data;
- Texture2DLockHelper lock_helper(texture2d, 0);
- texture_data = lock_helper.GetData();
+ Texture2D::LockHelper lock_helper(texture2d, 0);
+ uint8* texture_data = lock_helper.GetDataAs<uint8>();
if (!texture_data) {
return;
}
@@ -177,7 +176,11 @@ void Canvas::DrawBitmap(Texture2D* texture2d,
unsigned char* bitmap_data = static_cast<unsigned char*>(
bitmap.getPixels());
- memcpy(bitmap_data, texture_data, width * height * 4);
+ for (int yy = 0; yy < height; ++yy) {
+ memcpy(bitmap_data + yy * width,
+ texture_data + yy * lock_helper.pitch(),
+ width * 4);
+ }
if (texture2d->format() == Texture2D::XRGB8) {
// Set the alpha to 1
@@ -242,13 +245,8 @@ bool Canvas::CopyToTexture(Texture2D* texture_2d) {
int width = sk_bitmap_.width();
int height = sk_bitmap_.height();
- Texture2DLockHelper lock_helper_0(texture_2d, 0);
- void* texture_data = lock_helper_0.GetData();
- if (!texture_data) {
- return false;
- }
-
- memcpy(texture_data, sk_bitmap_.getPixels(), width * height * 4);
+ texture_2d->SetRect(0, 0, 0, width, height,
+ sk_bitmap_.getPixels(), width * 4);
// Fill in all the mipmap levels of the texture by drawing scaled down
// versions of the canvas bitmap contents.
@@ -256,21 +254,17 @@ bool Canvas::CopyToTexture(Texture2D* texture_2d) {
int levels = texture_2d->levels();
for (int i = 1; (!levels && width > 1 && height > 1) || i < levels; i++) {
- width = width >> 1;
- height = height >> 1;
+ width = std::max(1, width >> 1);
+ height = std::max(1, height >> 1);
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
- Texture2DLockHelper lock_helper_n(texture_2d, i);
- texture_data = lock_helper_n.GetData();
- if (!texture_data) {
- return false;
- }
-
- bitmap.setPixels(texture_data);
+ scoped_array<uint8> buffer(new uint8[width * height * 4]);
+ bitmap.setPixels(buffer.get());
SkCanvas canvas(bitmap);
SkScalar scaleFactor = SkScalarDiv(SK_Scalar1, SkIntToScalar(1 << i));
canvas.scale(scaleFactor, scaleFactor);
canvas.drawBitmap(sk_bitmap_, 0, 0);
+ texture_2d->SetRect(i, 0, 0, width, height, bitmap.getPixels(), width * 4);
}
return true;