blob: 5d93605566991e4cb2c1de9cee99c76db134e92f [file] [log] [blame]
reed@google.com58b21ec2012-07-30 18:20:12 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed@google.com889b09e2012-07-27 21:10:42 +00007
8#ifndef SkImagePriv_DEFINED
9#define SkImagePriv_DEFINED
10
11#include "SkBitmap.h"
12#include "SkImage.h"
13
mike@reedtribe.org70e35902012-07-29 20:38:16 +000014class SkPicture;
15
reed@google.com383a6972013-10-21 14:00:07 +000016extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info&);
reed@google.com889b09e2012-07-27 21:10:42 +000017
18extern int SkImageBytesPerPixel(SkImage::ColorType);
19
20extern bool SkBitmapToImageInfo(const SkBitmap&, SkImage::Info*);
reed@google.com97af1a62012-08-28 12:19:02 +000021
22// Call this if you explicitly want to use/share this pixelRef in the image
reed@google.com889b09e2012-07-27 21:10:42 +000023extern SkImage* SkNewImageFromPixelRef(const SkImage::Info&, SkPixelRef*,
24 size_t rowBytes);
25
26/**
27 * Examines the bitmap to decide if it can share the existing pixelRef, or
reed@google.com97af1a62012-08-28 12:19:02 +000028 * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will
29 * be shared if either the bitmap is marked as immutable, or canSharePixelRef
30 * is true.
31 *
32 * If the bitmap's config cannot be converted into a corresponding
33 * SkImage::Info, or the bitmap's pixels cannot be accessed, this will return
34 * NULL.
reed@google.com889b09e2012-07-27 21:10:42 +000035 */
reed@google.com97af1a62012-08-28 12:19:02 +000036extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef);
reed@google.com889b09e2012-07-27 21:10:42 +000037
mike@reedtribe.org70e35902012-07-29 20:38:16 +000038extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*,
39 SkScalar x, SkScalar y, const SkPaint*);
reed@google.com9ea5a3b2012-07-30 21:03:46 +000040
commit-bot@chromium.orgdfec28d2013-07-23 15:52:16 +000041extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*,
42 const SkRect*, const SkRect&, const SkPaint*);
43
reed@google.com9ea5a3b2012-07-30 21:03:46 +000044/**
45 * Return an SkImage whose contents are those of the specified picture. Note:
46 * The picture itself is unmodified, and may continue to be used for recording
47 */
48extern SkImage* SkNewImageFromPicture(const SkPicture*);
mike@reedtribe.org70e35902012-07-29 20:38:16 +000049
reed@google.com889b09e2012-07-27 21:10:42 +000050static inline size_t SkImageMinRowBytes(const SkImage::Info& info) {
mike@reedtribe.org70e35902012-07-29 20:38:16 +000051 size_t rb = info.fWidth * SkImageBytesPerPixel(info.fColorType);
52 return SkAlign4(rb);
reed@google.com889b09e2012-07-27 21:10:42 +000053}
54
reed@google.com97af1a62012-08-28 12:19:02 +000055// Given an image created from SkNewImageFromBitmap, return its pixelref. This
56// may be called to see if the surface and the image share the same pixelref,
57// in which case the surface may need to perform a copy-on-write.
58extern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage);
59
junov@chromium.org45c3db82013-04-11 17:52:05 +000060// Given an image created with NewPicture, return its SkPicture.
61extern SkPicture* SkPictureImageGetPicture(SkImage* pictureImage);
62
robertphillips@google.com97b6b072012-10-31 14:48:39 +000063// Given an image created with NewTexture, return its GrTexture. This
64// may be called to see if the surface and the image share the same GrTexture,
65// in which case the surface may need to perform a copy-on-write.
junov@chromium.org45c3db82013-04-11 17:52:05 +000066extern GrTexture* SkTextureImageGetTexture(SkImage* textureImage);
robertphillips@google.com97b6b072012-10-31 14:48:39 +000067
68// Update the texture wrapped by an image created with NewTexture. This
69// is called when a surface and image share the same GrTexture and the
70// surface needs to perform a copy-on-write
71extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
72
reed@google.com889b09e2012-07-27 21:10:42 +000073#endif