skia2/include/utils/mac/SkCGUtils.h
scroggo a1193e4b0e Make SkStream *not* ref counted.
SkStream is a stateful object, so it does not make sense for it to have
multiple owners. Make SkStream inherit directly from SkNoncopyable.

Update methods which previously called SkStream::ref() (e.g.
SkImageDecoder::buildTileIndex() and SkFrontBufferedStream::Create(),
which required the existing owners to call SkStream::unref()) to take
ownership of their SkStream parameters and delete when done (including
on failure).

Switch all SkAutoTUnref<SkStream>s to SkAutoTDelete<SkStream>s. In some
cases this means heap allocating streams that were previously stack
allocated.

Respect ownership rules of SkTypeface::CreateFromStream() and
SkImageDecoder::buildTileIndex().

Update the comments for exceptional methods which do not affect the
ownership of their SkStream parameters (e.g.
SkPicture::CreateFromStream() and SkTypeface::Deserialize()) to be
explicit about ownership.

Remove test_stream_life, which tested that buildTileIndex() behaved
correctly when SkStream was a ref counted object. The test does not
make sense now that it is not.

In SkPDFStream, remove the SkMemoryStream member. Instead of using it,
create a new SkMemoryStream to pass to fDataStream (which is now an
SkAutoTDelete).

Make other pdf rasterizers behave like SkPDFDocumentToBitmap.

SkPDFDocumentToBitmap delete the SkStream, so do the same in the
following pdf rasterizers:

SkPopplerRasterizePDF
SkNativeRasterizePDF
SkNoRasterizePDF

Requires a change to Android, which currently treats SkStreams as ref
counted objects.

Review URL: https://codereview.chromium.org/849103004
2015-01-21 12:09:53 -08:00

82 lines
2.6 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkCGUtils_DEFINED
#define SkCGUtils_DEFINED
#include "SkSize.h"
#include "SkImageInfo.h"
#ifdef SK_BUILD_FOR_MAC
#include <ApplicationServices/ApplicationServices.h>
#endif
#ifdef SK_BUILD_FOR_IOS
#include <CoreGraphics/CoreGraphics.h>
#endif
class SkBitmap;
class SkData;
class SkStream;
/**
* Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not
* null, use it to determine the size of the bitmap, and scale the image to fill the bitmap.
* Otherwise use the image's width/height.
*
* On failure, return false, and leave bitmap unchanged.
*/
SK_API bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef src, SkISize* scaleToFit = NULL);
/**
* Copy the pixels from src into the memory specified by info/rowBytes/dstPixels. On failure,
* return false (e.g. ImageInfo incompatible with src).
*/
SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* dstPixels,
CGImageRef src);
/**
* Create an imageref from the specified bitmap using the specified colorspace.
* If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
*/
SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
CGColorSpaceRef space);
/**
* Create an imageref from the specified bitmap using the colorspace returned
* by CGColorSpaceCreateDeviceRGB()
*/
static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
return SkCreateCGImageRefWithColorspace(bm, NULL);
}
/**
* Draw the bitmap into the specified CG context. The bitmap will be converted
* to a CGImage using the generic RGB colorspace. (x,y) specifies the position
* of the top-left corner of the bitmap. The bitmap is converted using the
* colorspace returned by CGColorSpaceCreateDeviceRGB()
*/
void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
/**
* Create an SkBitmap drawing of the encoded PDF document, returning true on
* success. Deletes the stream when finished.
*/
bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
/**
* Return a provider that wraps the specified stream. It will become the only
* owner of the stream, so the caller must stop referring to the stream.
*
* When the provider is finally deleted, it will delete the stream.
*/
CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
CGDataProviderRef SkCreateDataProviderFromData(SkData*);
#endif