blob: d3b1c79a79903b5cd9d6b5362bc0f53552dbdced [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
reed@google.com889b09e2012-07-27 21:10:42 +000011#include "SkImage.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080012#include "SkSurface.h"
reed@google.com889b09e2012-07-27 21:10:42 +000013
reed@google.com97af1a62012-08-28 12:19:02 +000014// Call this if you explicitly want to use/share this pixelRef in the image
kkinnunen73953e72015-02-23 22:12:12 -080015extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
16 const SkIPoint& pixelRefOrigin,
17 size_t rowBytes,
reed4af267b2014-11-21 08:46:37 -080018 const SkSurfaceProps*);
reed@google.com889b09e2012-07-27 21:10:42 +000019
20/**
21 * Examines the bitmap to decide if it can share the existing pixelRef, or
reed@google.com97af1a62012-08-28 12:19:02 +000022 * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will
23 * be shared if either the bitmap is marked as immutable, or canSharePixelRef
24 * is true.
25 *
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000026 * If the bitmap's colortype cannot be converted into a corresponding
reed@google.com2bd8b812013-11-01 13:46:54 +000027 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return
reed@google.com97af1a62012-08-28 12:19:02 +000028 * NULL.
reed@google.com889b09e2012-07-27 21:10:42 +000029 */
reed4af267b2014-11-21 08:46:37 -080030extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef, const SkSurfaceProps*);
reed@google.com889b09e2012-07-27 21:10:42 +000031
reed@google.com2bd8b812013-11-01 13:46:54 +000032static inline size_t SkImageMinRowBytes(const SkImageInfo& info) {
reed759373a2015-07-03 21:01:10 -070033 size_t minRB = info.minRowBytes();
34 if (kIndex_8_SkColorType != info.colorType()) {
35 minRB = SkAlign4(minRB);
36 }
37 return minRB;
reed@google.com889b09e2012-07-27 21:10:42 +000038}
39
reed@google.com97af1a62012-08-28 12:19:02 +000040// Given an image created from SkNewImageFromBitmap, return its pixelref. This
41// may be called to see if the surface and the image share the same pixelref,
42// in which case the surface may need to perform a copy-on-write.
piotaixr65151752014-10-16 11:58:39 -070043extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
reed@google.com97af1a62012-08-28 12:19:02 +000044
bsalomoneaaaf0b2015-01-23 08:08:04 -080045// When a texture is shared by a surface and an image its budgeted status is that of the
46// surface. This function is used when the surface makes a new texture for itself in order
47// for the orphaned image to determine whether the original texture counts against the
48// budget or not.
49extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage);
50
robertphillips@google.com97b6b072012-10-31 14:48:39 +000051// Update the texture wrapped by an image created with NewTexture. This
52// is called when a surface and image share the same GrTexture and the
53// surface needs to perform a copy-on-write
54extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
55
reed@google.com889b09e2012-07-27 21:10:42 +000056#endif