diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-07 16:05:49 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-07 16:05:49 +0000 |
commit | 65fabb5884a6087fb01030269ae8ee514191c1aa (patch) | |
tree | efb5258d66c2ee8cd21b99ef9f5cbdd9f47bb220 | |
parent | 318f90781e92aa320b9887fccc75ce5aa4861340 (diff) | |
download | chromium_src-65fabb5884a6087fb01030269ae8ee514191c1aa.zip chromium_src-65fabb5884a6087fb01030269ae8ee514191c1aa.tar.gz chromium_src-65fabb5884a6087fb01030269ae8ee514191c1aa.tar.bz2 |
Make Canvas and other ImageBuffer uses able to detect failure and not create
the canvas.
Review URL: http://codereview.chromium.org/9668
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4987 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/port/platform/graphics/ImageBufferSkia.cpp | 18 | ||||
-rw-r--r-- | webkit/port/platform/graphics/PlatformContextSkia.cpp | 3 |
2 files changed, 20 insertions, 1 deletions
diff --git a/webkit/port/platform/graphics/ImageBufferSkia.cpp b/webkit/port/platform/graphics/ImageBufferSkia.cpp index b9c54e6..80056f4 100644 --- a/webkit/port/platform/graphics/ImageBufferSkia.cpp +++ b/webkit/port/platform/graphics/ImageBufferSkia.cpp @@ -42,8 +42,12 @@ using namespace std; namespace WebCore { +// We pass a technically-uninitialized canvas to the platform context here since +// the canvas initialization completes in ImageBuffer::ImageBuffer. But +// PlatformContext doesn't actually need to use the object, and this makes all +// the ownership easier to manage. ImageBufferData::ImageBufferData(const IntSize& size) - : m_canvas(size.width(), size.height(), false) + : m_canvas() , m_platformContext(&m_canvas) { } @@ -52,6 +56,11 @@ ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success) : m_data(size) , m_size(size) { + if (!m_data.m_canvas.initialize(size.width(), size.height(), false, NULL)) { + success = false; + return; + } + m_context.set(new GraphicsContext(&m_data.m_platformContext)); // Make the background transparent. It would be nice if this wasn't @@ -73,6 +82,13 @@ GraphicsContext* ImageBuffer::context() const Image* ImageBuffer::image() const { if (!m_image) { + // This creates a COPY of the image and will cache that copy. This means + // that if subsequent operations take place on the context, neither the + // currently-returned image, nor the results of future image() calls, + // will contain that operation. + // + // This seems silly, but is the way the CG port works: image() is + // intended to be used only when rendering is "complete." m_image = BitmapImageSingleFrameSkia::create( *m_data.m_platformContext.bitmap()); } diff --git a/webkit/port/platform/graphics/PlatformContextSkia.cpp b/webkit/port/platform/graphics/PlatformContextSkia.cpp index 33e06e4..351e8ea 100644 --- a/webkit/port/platform/graphics/PlatformContextSkia.cpp +++ b/webkit/port/platform/graphics/PlatformContextSkia.cpp @@ -138,6 +138,9 @@ SkColor PlatformContextSkia::State::applyAlpha(SkColor c) const // PlatformContextSkia --------------------------------------------------------- +// Danger: the canvas is not guaranteed to be initialized yet, so we can't use +// it in the constructor. In ImageBufferSkia, we pass a canvas in here that will +// be initialized at a later phase. PlatformContextSkia::PlatformContextSkia(gfx::PlatformCanvas* canvas) : m_canvas(canvas) , m_stateStack(sizeof(State)) |