Commit 5ac2cb3b authored by msarett's avatar msarett Committed by Commit bot

Remove use of legacy pixel ref API in ui_resource_bitmap

SkPixelRef no longer stores an SkImageInfo

BUG=skia:6535
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2848063002
Cr-Commit-Position: refs/heads/master@{#468329}
parent d9be36be
...@@ -36,23 +36,20 @@ UIResourceBitmap::UIResourceFormat SkColorTypeToUIResourceFormat( ...@@ -36,23 +36,20 @@ UIResourceBitmap::UIResourceFormat SkColorTypeToUIResourceFormat(
} // namespace } // namespace
void UIResourceBitmap::Create(sk_sp<SkPixelRef> pixel_ref, void UIResourceBitmap::Create(sk_sp<SkPixelRef> pixel_ref,
const gfx::Size& size, const SkImageInfo& info,
UIResourceFormat format) { UIResourceFormat format) {
DCHECK(size.width()); DCHECK(info.width());
DCHECK(size.height()); DCHECK(info.height());
DCHECK(pixel_ref); DCHECK(pixel_ref);
DCHECK(pixel_ref->isImmutable()); DCHECK(pixel_ref->isImmutable());
format_ = format; format_ = format;
size_ = size; info_ = info;
pixel_ref_ = std::move(pixel_ref); pixel_ref_ = std::move(pixel_ref);
// Default values for secondary parameters.
opaque_ = (format == ETC1);
} }
void UIResourceBitmap::DrawToCanvas(SkCanvas* canvas, SkPaint* paint) { void UIResourceBitmap::DrawToCanvas(SkCanvas* canvas, SkPaint* paint) {
SkBitmap bitmap; SkBitmap bitmap;
bitmap.setInfo(pixel_ref_.get()->info(), pixel_ref_.get()->rowBytes()); bitmap.setInfo(info_, pixel_ref_.get()->rowBytes());
bitmap.setPixelRef(pixel_ref_, 0, 0); bitmap.setPixelRef(pixel_ref_, 0, 0);
canvas->drawBitmap(bitmap, 0, 0, paint); canvas->drawBitmap(bitmap, 0, 0, paint);
canvas->flush(); canvas->flush();
...@@ -63,11 +60,8 @@ UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { ...@@ -63,11 +60,8 @@ UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) {
DCHECK(skbitmap.isImmutable()); DCHECK(skbitmap.isImmutable());
sk_sp<SkPixelRef> pixel_ref = sk_ref_sp(skbitmap.pixelRef()); sk_sp<SkPixelRef> pixel_ref = sk_ref_sp(skbitmap.pixelRef());
const SkImageInfo& info = pixel_ref->info(); Create(std::move(pixel_ref), skbitmap.info(),
Create(std::move(pixel_ref), gfx::Size(info.width(), info.height()),
SkColorTypeToUIResourceFormat(skbitmap.colorType())); SkColorTypeToUIResourceFormat(skbitmap.colorType()));
SetOpaque(skbitmap.isOpaque());
} }
UIResourceBitmap::UIResourceBitmap(const gfx::Size& size, bool is_opaque) { UIResourceBitmap::UIResourceBitmap(const gfx::Size& size, bool is_opaque) {
...@@ -77,13 +71,14 @@ UIResourceBitmap::UIResourceBitmap(const gfx::Size& size, bool is_opaque) { ...@@ -77,13 +71,14 @@ UIResourceBitmap::UIResourceBitmap(const gfx::Size& size, bool is_opaque) {
sk_sp<SkPixelRef> pixel_ref( sk_sp<SkPixelRef> pixel_ref(
SkMallocPixelRef::MakeAllocate(info, info.minRowBytes(), NULL)); SkMallocPixelRef::MakeAllocate(info, info.minRowBytes(), NULL));
pixel_ref->setImmutable(); pixel_ref->setImmutable();
Create(std::move(pixel_ref), size, UIResourceBitmap::RGBA8); Create(std::move(pixel_ref), info, UIResourceBitmap::RGBA8);
SetOpaque(is_opaque);
} }
UIResourceBitmap::UIResourceBitmap(sk_sp<SkPixelRef> pixel_ref, UIResourceBitmap::UIResourceBitmap(sk_sp<SkPixelRef> pixel_ref,
const gfx::Size& size) { const gfx::Size& size) {
Create(std::move(pixel_ref), size, UIResourceBitmap::ETC1); SkImageInfo info =
SkImageInfo::MakeN32(size.width(), size.height(), kOpaque_SkAlphaType);
Create(std::move(pixel_ref), info, UIResourceBitmap::ETC1);
} }
UIResourceBitmap::UIResourceBitmap(const UIResourceBitmap& other) = default; UIResourceBitmap::UIResourceBitmap(const UIResourceBitmap& other) = default;
......
...@@ -32,10 +32,9 @@ class CC_EXPORT UIResourceBitmap { ...@@ -32,10 +32,9 @@ class CC_EXPORT UIResourceBitmap {
ETC1 ETC1
}; };
gfx::Size GetSize() const { return size_; } gfx::Size GetSize() const { return gfx::Size(info_.width(), info_.height()); }
UIResourceFormat GetFormat() const { return format_; } UIResourceFormat GetFormat() const { return format_; }
bool GetOpaque() const { return opaque_; } bool GetOpaque() const { return info_.isOpaque(); }
void SetOpaque(bool opaque) { opaque_ = opaque; }
// Draw the UIResourceBitmap onto the provided |canvas| using the style // Draw the UIResourceBitmap onto the provided |canvas| using the style
// information specified by |paint|. // information specified by |paint|.
...@@ -51,7 +50,7 @@ class CC_EXPORT UIResourceBitmap { ...@@ -51,7 +50,7 @@ class CC_EXPORT UIResourceBitmap {
// Returns the memory usage of the bitmap. // Returns the memory usage of the bitmap.
size_t EstimateMemoryUsage() const { size_t EstimateMemoryUsage() const {
return pixel_ref_ ? pixel_ref_->rowBytes() * size_.height() : 0; return pixel_ref_ ? pixel_ref_->rowBytes() * info_.height() : 0;
} }
const uint8_t* GetPixels() const { const uint8_t* GetPixels() const {
...@@ -62,13 +61,12 @@ class CC_EXPORT UIResourceBitmap { ...@@ -62,13 +61,12 @@ class CC_EXPORT UIResourceBitmap {
friend class AutoLockUIResourceBitmap; friend class AutoLockUIResourceBitmap;
void Create(sk_sp<SkPixelRef> pixel_ref, void Create(sk_sp<SkPixelRef> pixel_ref,
const gfx::Size& size, const SkImageInfo& info,
UIResourceFormat format); UIResourceFormat format);
sk_sp<SkPixelRef> pixel_ref_; sk_sp<SkPixelRef> pixel_ref_;
UIResourceFormat format_; UIResourceFormat format_;
gfx::Size size_; SkImageInfo info_;
bool opaque_;
}; };
} // namespace cc } // namespace cc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment