Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Unified Diff: trunk/src/ui/gfx/image/image.cc

Issue 347983004: Revert 278589 "Use ImageSkiaSource to create ImageSkia from Imag..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | trunk/src/ui/gfx/image/image_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/ui/gfx/image/image.cc
===================================================================
--- trunk/src/ui/gfx/image/image.cc (revision 278650)
+++ trunk/src/ui/gfx/image/image.cc (working copy)
@@ -5,7 +5,6 @@
#include "ui/gfx/image/image.h"
#include <algorithm>
-#include <set>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -13,7 +12,6 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image_png_rep.h"
#include "ui/gfx/image/image_skia.h"
-#include "ui/gfx/image/image_skia_source.h"
#include "ui/gfx/size.h"
#if !defined(OS_IOS)
@@ -37,20 +35,20 @@
UIImage* uiimage);
// Caller takes ownership of the returned UIImage.
UIImage* CreateUIImageFromPNG(
- const std::vector<ImagePNGRep>& image_png_reps);
+ const std::vector<gfx::ImagePNGRep>& image_png_reps);
gfx::Size UIImageSize(UIImage* image);
#elif defined(OS_MACOSX)
scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromNSImage(
NSImage* nsimage);
// Caller takes ownership of the returned NSImage.
-NSImage* NSImageFromPNG(const std::vector<ImagePNGRep>& image_png_reps,
+NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps,
CGColorSpaceRef color_space);
gfx::Size NSImageSize(NSImage* image);
#endif // defined(OS_MACOSX)
#if defined(OS_IOS)
ImageSkia* ImageSkiaFromPNG(
- const std::vector<ImagePNGRep>& image_png_reps);
+ const std::vector<gfx::ImagePNGRep>& image_png_reps);
scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia(
const ImageSkia* skia);
#else
@@ -61,91 +59,31 @@
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
bitmap.allocPixels();
bitmap.eraseARGB(0xff, 0xff, 0, 0);
- return new ImageSkia(ImageSkiaRep(bitmap, 1.0f));
+ return new gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, 1.0f));
}
-class PNGImageSource : public ImageSkiaSource {
- public:
- PNGImageSource() {}
- virtual ~PNGImageSource() {}
-
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
- if (image_skia_reps_.empty())
- return ImageSkiaRep();
-
- const ImageSkiaRep* rep = NULL;
- // gfx::ImageSkia passes one of the resource scale factors. The source
- // should return:
- // 1) The ImageSkiaRep with the highest scale if all available
- // scales are smaller than |scale|.
- // 2) The ImageSkiaRep with the smallest one that is larger than |scale|.
- for (ImageSkiaRepSet::const_iterator iter = image_skia_reps_.begin();
- iter != image_skia_reps_.end(); ++iter) {
- if ((*iter).scale() == scale)
- return (*iter);
- if (!rep || rep->scale() < (*iter).scale())
- rep = &(*iter);
- if (rep->scale() >= scale)
- break;
- }
- return rep ? *rep : ImageSkiaRep();
- }
-
- const gfx::Size size() const {
- return size_;
- }
-
- bool AddPNGData(const ImagePNGRep& png_rep) {
- const gfx::ImageSkiaRep rep = ToImageSkiaRep(png_rep);
- if (rep.is_null())
- return false;
- if (size_.IsEmpty())
- size_ = gfx::Size(rep.GetWidth(), rep.GetHeight());
- image_skia_reps_.insert(rep);
- return true;
- }
-
- static ImageSkiaRep ToImageSkiaRep(const ImagePNGRep& png_rep) {
- scoped_refptr<base::RefCountedMemory> raw_data = png_rep.raw_data;
- CHECK(raw_data.get());
- SkBitmap bitmap;
- if (!PNGCodec::Decode(raw_data->front(), raw_data->size(),
- &bitmap)) {
- LOG(ERROR) << "Unable to decode PNG for " << png_rep.scale << ".";
- return ImageSkiaRep();
- }
- return ImageSkiaRep(bitmap, png_rep.scale);
- }
-
- private:
- struct Compare {
- bool operator()(const ImageSkiaRep& rep1, const ImageSkiaRep& rep2) {
- return rep1.scale() < rep2.scale();
- }
- };
-
- typedef std::set<ImageSkiaRep, Compare> ImageSkiaRepSet;
- ImageSkiaRepSet image_skia_reps_;
- gfx::Size size_;
-
- DISALLOW_COPY_AND_ASSIGN(PNGImageSource);
-};
-
ImageSkia* ImageSkiaFromPNG(
- const std::vector<ImagePNGRep>& image_png_reps) {
+ const std::vector<gfx::ImagePNGRep>& image_png_reps) {
if (image_png_reps.empty())
return GetErrorImageSkia();
- scoped_ptr<PNGImageSource> image_source(new PNGImageSource);
+ scoped_ptr<gfx::ImageSkia> image_skia(new ImageSkia());
for (size_t i = 0; i < image_png_reps.size(); ++i) {
- if (!image_source->AddPNGData(image_png_reps[i]))
+ scoped_refptr<base::RefCountedMemory> raw_data =
+ image_png_reps[i].raw_data;
+ CHECK(raw_data.get());
+ SkBitmap bitmap;
+ if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
+ &bitmap)) {
+ LOG(ERROR) << "Unable to decode PNG for "
+ << image_png_reps[i].scale
+ << ".";
return GetErrorImageSkia();
+ }
+ image_skia->AddRepresentation(gfx::ImageSkiaRep(
+ bitmap, image_png_reps[i].scale));
}
- const gfx::Size& size = image_source->size();
- DCHECK(!size.IsEmpty());
- if (size.IsEmpty())
- return GetErrorImageSkia();
- return new ImageSkia(image_source.release(), size);
+ return image_skia.release();
}
scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia(
@@ -154,7 +92,7 @@
scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes());
if (image_skia_rep.scale() != 1.0f ||
- !PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false,
+ !gfx::PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false,
&png_bytes->data())) {
return NULL;
}
@@ -364,7 +302,7 @@
// ImageReps. This way, the Image can be cheaply copied.
class ImageStorage : public base::RefCounted<ImageStorage> {
public:
- ImageStorage(Image::RepresentationType default_type)
+ ImageStorage(gfx::Image::RepresentationType default_type)
: default_representation_type_(default_type),
#if defined(OS_MACOSX) && !defined(OS_IOS)
default_representation_color_space_(
@@ -373,10 +311,10 @@
representations_deleter_(&representations_) {
}
- Image::RepresentationType default_representation_type() {
+ gfx::Image::RepresentationType default_representation_type() {
return default_representation_type_;
}
- Image::RepresentationMap& representations() { return representations_; }
+ gfx::Image::RepresentationMap& representations() { return representations_; }
#if defined(OS_MACOSX) && !defined(OS_IOS)
void set_default_representation_color_space(CGColorSpaceRef color_space) {
@@ -394,7 +332,7 @@
// The type of image that was passed to the constructor. This key will always
// exist in the |representations_| map.
- Image::RepresentationType default_representation_type_;
+ gfx::Image::RepresentationType default_representation_type_;
#if defined(OS_MACOSX) && !defined(OS_IOS)
// The default representation's colorspace. This is used for converting to
@@ -406,7 +344,7 @@
// All the representations of an Image. Size will always be at least one, with
// more for any converted representations.
- Image::RepresentationMap representations_;
+ gfx::Image::RepresentationMap representations_;
STLValueDeleter<Image::RepresentationMap> representations_deleter_;
@@ -475,14 +413,14 @@
// static
Image Image::CreateFrom1xBitmap(const SkBitmap& bitmap) {
- return Image(ImageSkia::CreateFrom1xBitmap(bitmap));
+ return gfx::Image(ImageSkia::CreateFrom1xBitmap(bitmap));
}
// static
Image Image::CreateFrom1xPNGBytes(const unsigned char* input,
size_t input_size) {
if (input_size == 0u)
- return Image();
+ return gfx::Image();
scoped_refptr<base::RefCountedBytes> raw_data(new base::RefCountedBytes());
raw_data->data().assign(input, input + input_size);
@@ -493,11 +431,11 @@
Image Image::CreateFrom1xPNGBytes(
const scoped_refptr<base::RefCountedMemory>& input) {
if (!input.get() || input->size() == 0u)
- return Image();
+ return gfx::Image();
- std::vector<ImagePNGRep> image_reps;
+ std::vector<gfx::ImagePNGRep> image_reps;
image_reps.push_back(ImagePNGRep(input, 1.0f));
- return Image(image_reps);
+ return gfx::Image(image_reps);
}
const SkBitmap* Image::ToSkBitmap() const {
@@ -612,7 +550,7 @@
internal::ImageRep* rep = GetRepresentation(kImageRepPNG, false);
if (rep) {
- const std::vector<ImagePNGRep>& image_png_reps =
+ const std::vector<gfx::ImagePNGRep>& image_png_reps =
rep->AsImageRepPNG()->image_reps();
for (size_t i = 0; i < image_png_reps.size(); ++i) {
if (image_png_reps[i].scale == 1.0f)
@@ -663,7 +601,7 @@
// final type eg (converting from ImageRepSkia to ImageRepPNG to get an
// ImageRepCocoa).
std::vector<ImagePNGRep> image_png_reps;
- image_png_reps.push_back(ImagePNGRep(png_bytes, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
rep = new internal::ImageRepPNG(image_png_reps);
AddRepresentation(rep);
return png_bytes;
@@ -745,7 +683,7 @@
return GetRepresentation(DefaultRepresentationType(), true)->Size();
}
-void Image::SwapRepresentations(Image* other) {
+void Image::SwapRepresentations(gfx::Image* other) {
storage_.swap(other->storage_);
}
« no previous file with comments | « no previous file | trunk/src/ui/gfx/image/image_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698