OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/image/image.h" | 5 #include "ui/gfx/image/image.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 CHECK(pixbuf); | 335 CHECK(pixbuf); |
336 } | 336 } |
337 | 337 |
338 virtual ~ImageRepGdk() { | 338 virtual ~ImageRepGdk() { |
339 if (pixbuf_) { | 339 if (pixbuf_) { |
340 g_object_unref(pixbuf_); | 340 g_object_unref(pixbuf_); |
341 pixbuf_ = NULL; | 341 pixbuf_ = NULL; |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 virtual int Width() const { | 345 virtual int Width() const OVERRIDE { |
346 return gdk_pixbuf_get_width(pixbuf_); | 346 return gdk_pixbuf_get_width(pixbuf_); |
347 } | 347 } |
348 | 348 |
349 virtual int Height() const { | 349 virtual int Height() const OVERRIDE { |
350 return gdk_pixbuf_get_height(pixbuf_); | 350 return gdk_pixbuf_get_height(pixbuf_); |
351 } | 351 } |
352 | 352 |
353 virtual gfx::Size Size() const { | 353 virtual gfx::Size Size() const OVERRIDE { |
354 return gfx::Size(Width(), Height()); | 354 return gfx::Size(Width(), Height()); |
355 } | 355 } |
356 | 356 |
357 GdkPixbuf* pixbuf() const { return pixbuf_; } | 357 GdkPixbuf* pixbuf() const { return pixbuf_; } |
358 | 358 |
359 private: | 359 private: |
360 GdkPixbuf* pixbuf_; | 360 GdkPixbuf* pixbuf_; |
361 | 361 |
362 DISALLOW_COPY_AND_ASSIGN(ImageRepGdk); | 362 DISALLOW_COPY_AND_ASSIGN(ImageRepGdk); |
363 }; | 363 }; |
364 | 364 |
365 // Represents data that lives on the display server instead of in the client. | 365 // Represents data that lives on the display server instead of in the client. |
366 class ImageRepCairo : public ImageRep { | 366 class ImageRepCairo : public ImageRep { |
367 public: | 367 public: |
368 explicit ImageRepCairo(GdkPixbuf* pixbuf) | 368 explicit ImageRepCairo(GdkPixbuf* pixbuf) |
369 : ImageRep(Image::kImageRepCairo), | 369 : ImageRep(Image::kImageRepCairo), |
370 cairo_cache_(new CairoCachedSurface) { | 370 cairo_cache_(new CairoCachedSurface) { |
371 CHECK(pixbuf); | 371 CHECK(pixbuf); |
372 cairo_cache_->UsePixbuf(pixbuf); | 372 cairo_cache_->UsePixbuf(pixbuf); |
373 } | 373 } |
374 | 374 |
375 virtual ~ImageRepCairo() { | 375 virtual ~ImageRepCairo() { |
376 delete cairo_cache_; | 376 delete cairo_cache_; |
377 } | 377 } |
378 | 378 |
379 virtual int Width() const { | 379 virtual int Width() const OVERRIDE { |
380 return cairo_cache_->Width(); | 380 return cairo_cache_->Width(); |
381 } | 381 } |
382 | 382 |
383 virtual int Height() const { | 383 virtual int Height() const OVERRIDE { |
384 return cairo_cache_->Height(); | 384 return cairo_cache_->Height(); |
385 } | 385 } |
386 | 386 |
387 virtual gfx::Size Size() const { | 387 virtual gfx::Size Size() const OVERRIDE { |
388 return gfx::Size(Width(), Height()); | 388 return gfx::Size(Width(), Height()); |
389 } | 389 } |
390 | 390 |
391 CairoCachedSurface* surface() const { return cairo_cache_; } | 391 CairoCachedSurface* surface() const { return cairo_cache_; } |
392 | 392 |
393 private: | 393 private: |
394 CairoCachedSurface* cairo_cache_; | 394 CairoCachedSurface* cairo_cache_; |
395 | 395 |
396 DISALLOW_COPY_AND_ASSIGN(ImageRepCairo); | 396 DISALLOW_COPY_AND_ASSIGN(ImageRepCairo); |
397 }; | 397 }; |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 915 } |
916 return it->second; | 916 return it->second; |
917 } | 917 } |
918 | 918 |
919 void Image::AddRepresentation(internal::ImageRep* rep) const { | 919 void Image::AddRepresentation(internal::ImageRep* rep) const { |
920 CHECK(storage_.get()); | 920 CHECK(storage_.get()); |
921 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 921 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
922 } | 922 } |
923 | 923 |
924 } // namespace gfx | 924 } // namespace gfx |
OLD | NEW |