Skip to content

Commit

Permalink
The *only* client of PlatformBitmap was a video capture unit test whi…
Browse files Browse the repository at this point in the history
…ch said in a comment that an SkBitmap would do just as well.

R=djsollen@chromium.org,miu@chromium.org
CC=senorblanco@chromium.org,junov@chromium.org

Review URL: https://codereview.chromium.org/1396613006

Cr-Commit-Position: refs/heads/master@{#353941}
  • Loading branch information
Naburimannu authored and Commit bot committed Oct 14, 2015
1 parent e450c78 commit 63fedf9
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,13 @@ class CaptureTestRenderViewHost : public TestRenderViewHost {
gfx::Size size = controller_->GetCopyResultSize();
SkColor color = controller_->GetSolidColor();

// Although it's not necessary, use a PlatformBitmap here (instead of a
// regular SkBitmap) to exercise possible threading issues.
skia::PlatformBitmap output;
EXPECT_TRUE(output.Allocate(size.width(), size.height(), false));
SkBitmap output;
EXPECT_TRUE(output.tryAllocN32Pixels(size.width(), size.height()));
{
SkAutoLockPixels locker(output.GetBitmap());
output.GetBitmap().eraseColor(color);
SkAutoLockPixels locker(output);
output.eraseColor(color);
}
callback.Run(output.GetBitmap(), content::READBACK_SUCCESS);
callback.Run(output, content::READBACK_SUCCESS);
controller_->SignalCopy();
}

Expand Down
22 changes: 0 additions & 22 deletions skia/ext/bitmap_platform_device_cairo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,4 @@ SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
return CreateCanvas(dev, failureType);
}

// Port of PlatformBitmap to linux
PlatformBitmap::~PlatformBitmap() {
cairo_destroy(surface_);
}

bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
// The SkBitmap allocates and owns the bitmap memory; PlatformBitmap owns the
// cairo drawing context tied to the bitmap. The SkBitmap's pixelRef can
// outlive the PlatformBitmap if additional copies are made.
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);

cairo_surface_t* surf = cairo_image_surface_create(
CAIRO_FORMAT_ARGB32,
width,
height);
if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy(surf);
return false;
}
return InstallCairoSurfacePixels(&bitmap_, surf, is_opaque);
}

} // namespace skia
22 changes: 0 additions & 22 deletions skia/ext/bitmap_platform_device_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,26 +298,4 @@ SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
return CreateCanvas(dev, failureType);
}

// Port of PlatformBitmap to mac

PlatformBitmap::~PlatformBitmap() {
if (surface_)
CGContextRelease(surface_);
}

bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
if (RasterDeviceTooBigToAllocate(width, height))
return false;

if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque))
return false;

if (!is_opaque)
bitmap_.eraseColor(0);

surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(),
bitmap_.height());
return true;
}

} // namespace skia
13 changes: 0 additions & 13 deletions skia/ext/bitmap_platform_device_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,4 @@ SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
return CreateCanvas(dev, failureType);
}

// Port of PlatformBitmap to android
PlatformBitmap::~PlatformBitmap() {
// Nothing to do.
}

bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque))
return false;

surface_ = bitmap_.getPixels();
return true;
}

} // namespace skia
31 changes: 0 additions & 31 deletions skia/ext/bitmap_platform_device_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,35 +317,4 @@ SkCanvas* CreatePlatformCanvas(int width,
return CreateCanvas(dev, failureType);
}

// Port of PlatformBitmap to win

PlatformBitmap::~PlatformBitmap() {
if (surface_) {
if (platform_extra_)
SelectObject(surface_, reinterpret_cast<HGDIOBJ>(platform_extra_));
DeleteDC(surface_);
}
}

bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
void* data;
HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, 0, &data);
if (!hbitmap)
return false;

surface_ = CreateCompatibleDC(NULL);
InitializeDC(surface_);
// When the memory DC is created, its display surface is exactly one
// monochrome pixel wide and one monochrome pixel high. Save this object
// off, we'll restore it just before deleting the memory DC.
HGDIOBJ stock_bitmap = SelectObject(surface_, hbitmap);
platform_extra_ = reinterpret_cast<intptr_t>(stock_bitmap);

if (!InstallHBitmapPixels(&bitmap_, width, height, is_opaque, data, hbitmap))
return false;
bitmap_.lockPixels();

return true;
}

} // namespace skia
6 changes: 0 additions & 6 deletions skia/ext/bitmap_platform_device_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ namespace skia {
// format that Skia supports and can then use this to draw ClearType into, etc.
// This pixel data is provided to the bitmap that the device contains so that it
// can be shared.
//
// The GDI bitmap created for drawing is actually owned by a
// PlatformBitmapPixelRef, and stored in an SkBitmap via the normal skia
// SkPixelRef refcounting mechanism. In this way, the GDI bitmap can outlive
// the device created to draw into it. So it is safe to call accessBitmap() on
// the device, and retain the returned SkBitmap.
class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
public:
// Factory function. is_opaque should be set if the caller knows the bitmap
Expand Down
2 changes: 0 additions & 2 deletions skia/ext/platform_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,4 @@ SkCanvas* CreateCanvas(const skia::RefPtr<SkBaseDevice>& device, OnFailureType f
return new SkCanvas(device.get());
}

PlatformBitmap::PlatformBitmap() : surface_(0), platform_extra_(0) {}

} // namespace skia
28 changes: 0 additions & 28 deletions skia/ext/platform_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,6 @@ class SK_API ScopedPlatformPaint {
ScopedPlatformPaint& operator=(const ScopedPlatformPaint&);
};

// PlatformBitmap holds a PlatformSurface that can also be used as an SkBitmap.
class SK_API PlatformBitmap {
public:
PlatformBitmap();
~PlatformBitmap();

// Returns true if the bitmap was able to allocate its surface.
bool Allocate(int width, int height, bool is_opaque);

// Returns the platform surface, or 0 if Allocate() did not return true.
PlatformSurface GetSurface() { return surface_; }

// Return the skia bitmap, which will be empty if Allocate() did not
// return true.
//
// The resulting SkBitmap holds a refcount on the underlying platform surface,
// so the surface will remain allocated so long as the SkBitmap or its copies
// stay around.
const SkBitmap& GetBitmap() { return bitmap_; }

private:
SkBitmap bitmap_;
PlatformSurface surface_; // initialized to 0
intptr_t platform_extra_; // platform specific, initialized to 0

DISALLOW_COPY_AND_ASSIGN(PlatformBitmap);
};

} // namespace skia

#endif // SKIA_EXT_PLATFORM_CANVAS_H_
61 changes: 0 additions & 61 deletions skia/ext/platform_canvas_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,65 +397,4 @@ TEST(PlatformCanvas, TranslateLayer) {

#endif // #if !defined(USE_AURA)

TEST(PlatformBitmapTest, PlatformBitmap) {
const int kWidth = 400;
const int kHeight = 300;
scoped_ptr<PlatformBitmap> platform_bitmap(new PlatformBitmap);

EXPECT_TRUE(0 == platform_bitmap->GetSurface());
EXPECT_TRUE(platform_bitmap->GetBitmap().empty());
EXPECT_TRUE(platform_bitmap->GetBitmap().isNull());

EXPECT_TRUE(platform_bitmap->Allocate(kWidth, kHeight, /*is_opaque=*/false));

EXPECT_TRUE(0 != platform_bitmap->GetSurface());
EXPECT_FALSE(platform_bitmap->GetBitmap().empty());
EXPECT_FALSE(platform_bitmap->GetBitmap().isNull());
EXPECT_EQ(kWidth, platform_bitmap->GetBitmap().width());
EXPECT_EQ(kHeight, platform_bitmap->GetBitmap().height());
EXPECT_LE(static_cast<size_t>(platform_bitmap->GetBitmap().width()*4),
platform_bitmap->GetBitmap().rowBytes());
EXPECT_EQ(kN32_SkColorType, // Same for all platforms.
platform_bitmap->GetBitmap().colorType());
EXPECT_TRUE(platform_bitmap->GetBitmap().lockPixelsAreWritable());
#if defined(SK_DEBUG)
EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->isLocked());
#endif
EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->unique());

*(platform_bitmap->GetBitmap().getAddr32(10, 20)) = 0xDEED1020;
*(platform_bitmap->GetBitmap().getAddr32(20, 30)) = 0xDEED2030;

SkBitmap sk_bitmap = platform_bitmap->GetBitmap();
sk_bitmap.lockPixels();

EXPECT_FALSE(platform_bitmap->GetBitmap().pixelRef()->unique());
EXPECT_FALSE(sk_bitmap.pixelRef()->unique());

EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));

*(platform_bitmap->GetBitmap().getAddr32(30, 40)) = 0xDEED3040;

// The SkBitmaps derived from a PlatformBitmap must be capable of outliving
// the PlatformBitmap.
platform_bitmap.reset();

EXPECT_TRUE(sk_bitmap.pixelRef()->unique());

EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));
EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40));
sk_bitmap.unlockPixels();

EXPECT_EQ(NULL, sk_bitmap.getPixels());

sk_bitmap.lockPixels();
EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));
EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40));
sk_bitmap.unlockPixels();
}


} // namespace skia

0 comments on commit 63fedf9

Please sign in to comment.