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(
} // namespace
void UIResourceBitmap::Create(sk_sp<SkPixelRef> pixel_ref,
const gfx::Size& size,
const SkImageInfo& info,
UIResourceFormat format) {
DCHECK(size.width());
DCHECK(size.height());
DCHECK(info.width());
DCHECK(info.height());
DCHECK(pixel_ref);
DCHECK(pixel_ref->isImmutable());
format_ = format;
size_ = size;
info_ = info;
pixel_ref_ = std::move(pixel_ref);
// Default values for secondary parameters.
opaque_ = (format == ETC1);
}
void UIResourceBitmap::DrawToCanvas(SkCanvas* canvas, SkPaint* paint) {
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);
canvas->drawBitmap(bitmap, 0, 0, paint);
canvas->flush();
......@@ -63,11 +60,8 @@ UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) {
DCHECK(skbitmap.isImmutable());
sk_sp<SkPixelRef> pixel_ref = sk_ref_sp(skbitmap.pixelRef());
const SkImageInfo& info = pixel_ref->info();
Create(std::move(pixel_ref), gfx::Size(info.width(), info.height()),
Create(std::move(pixel_ref), skbitmap.info(),
SkColorTypeToUIResourceFormat(skbitmap.colorType()));
SetOpaque(skbitmap.isOpaque());
}
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(
SkMallocPixelRef::MakeAllocate(info, info.minRowBytes(), NULL));
pixel_ref->setImmutable();
Create(std::move(pixel_ref), size, UIResourceBitmap::RGBA8);
SetOpaque(is_opaque);
Create(std::move(pixel_ref), info, UIResourceBitmap::RGBA8);
}
UIResourceBitmap::UIResourceBitmap(sk_sp<SkPixelRef> pixel_ref,
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;
......
......@@ -32,10 +32,9 @@ class CC_EXPORT UIResourceBitmap {
ETC1
};
gfx::Size GetSize() const { return size_; }
gfx::Size GetSize() const { return gfx::Size(info_.width(), info_.height()); }
UIResourceFormat GetFormat() const { return format_; }
bool GetOpaque() const { return opaque_; }
void SetOpaque(bool opaque) { opaque_ = opaque; }
bool GetOpaque() const { return info_.isOpaque(); }
// Draw the UIResourceBitmap onto the provided |canvas| using the style
// information specified by |paint|.
......@@ -51,7 +50,7 @@ class CC_EXPORT UIResourceBitmap {
// Returns the memory usage of the bitmap.
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 {
......@@ -62,13 +61,12 @@ class CC_EXPORT UIResourceBitmap {
friend class AutoLockUIResourceBitmap;
void Create(sk_sp<SkPixelRef> pixel_ref,
const gfx::Size& size,
const SkImageInfo& info,
UIResourceFormat format);
sk_sp<SkPixelRef> pixel_ref_;
UIResourceFormat format_;
gfx::Size size_;
bool opaque_;
SkImageInfo info_;
};
} // 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