Skip to content

Commit

Permalink
Add allocator to ImageOperations
Browse files Browse the repository at this point in the history
TBR=senorblanco
R=junov
BUG=164052

Review URL: https://chromiumcodereview.appspot.com/12016002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177676 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
nduca@chromium.org committed Jan 18, 2013
1 parent 23d8008 commit 7f02ff9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
33 changes: 20 additions & 13 deletions skia/ext/image_operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "build/build_config.h"
#include "skia/ext/convolver.h"
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkFontHost.h"

Expand Down Expand Up @@ -344,17 +343,22 @@ ImageOperations::ResizeMethod ResizeMethodToAlgorithmMethod(
SkBitmap ImageOperations::Resize(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height,
const SkIRect& dest_subset) {
if (method == ImageOperations::RESIZE_SUBPIXEL)
return ResizeSubpixel(source, dest_width, dest_height, dest_subset);
else
return ResizeBasic(source, method, dest_width, dest_height, dest_subset);
const SkIRect& dest_subset,
SkBitmap::Allocator* allocator) {
if (method == ImageOperations::RESIZE_SUBPIXEL) {
return ResizeSubpixel(source, dest_width, dest_height,
dest_subset, allocator);
} else {
return ResizeBasic(source, method, dest_width, dest_height, dest_subset,
allocator);
}
}

// static
SkBitmap ImageOperations::ResizeSubpixel(const SkBitmap& source,
int dest_width, int dest_height,
const SkIRect& dest_subset) {
const SkIRect& dest_subset,
SkBitmap::Allocator* allocator) {
TRACE_EVENT2("skia", "ImageOperations::ResizeSubpixel",
"src_pixels", source.width()*source.height(),
"dst_pixels", dest_width*dest_height);
Expand Down Expand Up @@ -385,7 +389,7 @@ SkBitmap ImageOperations::ResizeSubpixel(const SkBitmap& source,
dest_subset.fLeft + dest_subset.width() * w,
dest_subset.fTop + dest_subset.height() * h };
SkBitmap img = ResizeBasic(source, ImageOperations::RESIZE_LANCZOS3, width,
height, subset);
height, subset, allocator);
const int row_words = img.rowBytes() / 4;
if (w == 1 && h == 1)
return img;
Expand All @@ -394,7 +398,7 @@ SkBitmap ImageOperations::ResizeSubpixel(const SkBitmap& source,
SkBitmap result;
result.setConfig(SkBitmap::kARGB_8888_Config, dest_subset.width(),
dest_subset.height());
result.allocPixels();
result.allocPixels(allocator, NULL);
if (!result.readyToDraw())
return img;

Expand Down Expand Up @@ -465,7 +469,8 @@ SkBitmap ImageOperations::ResizeSubpixel(const SkBitmap& source,
SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height,
const SkIRect& dest_subset) {
const SkIRect& dest_subset,
SkBitmap::Allocator* allocator) {
TRACE_EVENT2("skia", "ImageOperations::ResizeBasic",
"src_pixels", source.width()*source.height(),
"dst_pixels", dest_width*dest_height);
Expand Down Expand Up @@ -511,7 +516,7 @@ SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source,
SkBitmap result;
result.setConfig(SkBitmap::kARGB_8888_Config,
dest_subset.width(), dest_subset.height());
result.allocPixels();
result.allocPixels(allocator, NULL);
if (!result.readyToDraw())
return SkBitmap();

Expand All @@ -533,9 +538,11 @@ SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source,
// static
SkBitmap ImageOperations::Resize(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height) {
int dest_width, int dest_height,
SkBitmap::Allocator* allocator) {
SkIRect dest_subset = { 0, 0, dest_width, dest_height };
return Resize(source, method, dest_width, dest_height, dest_subset);
return Resize(source, method, dest_width, dest_height, dest_subset,
allocator);
}

} // namespace skia
14 changes: 9 additions & 5 deletions skia/ext/image_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#ifndef SKIA_EXT_IMAGE_OPERATIONS_H_
#define SKIA_EXT_IMAGE_OPERATIONS_H_

#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkTypes.h"

class SkBitmap;
struct SkIRect;

namespace skia {
Expand Down Expand Up @@ -101,13 +101,15 @@ class SK_API ImageOperations {
static SkBitmap Resize(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height,
const SkIRect& dest_subset);
const SkIRect& dest_subset,
SkBitmap::Allocator* allocator = NULL);

// Alternate version for resizing and returning the entire bitmap rather than
// a subset.
static SkBitmap Resize(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height);
int dest_width, int dest_height,
SkBitmap::Allocator* allocator = NULL);

private:
ImageOperations(); // Class for scoping only.
Expand All @@ -116,12 +118,14 @@ class SK_API ImageOperations {
static SkBitmap ResizeBasic(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height,
const SkIRect& dest_subset);
const SkIRect& dest_subset,
SkBitmap::Allocator* allocator = NULL);

// Subpixel renderer.
static SkBitmap ResizeSubpixel(const SkBitmap& source,
int dest_width, int dest_height,
const SkIRect& dest_subset);
const SkIRect& dest_subset,
SkBitmap::Allocator* allocator = NULL);
};

} // namespace skia
Expand Down

0 comments on commit 7f02ff9

Please sign in to comment.