2010-12-22 21:39:39 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrTexture_DEFINED
|
|
|
|
#define GrTexture_DEFINED
|
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
#include "GrSurface.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2014-07-25 14:32:33 +00:00
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkRefCnt.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-06-04 20:05:28 +00:00
|
|
|
class GrResourceKey;
|
2012-07-25 21:27:09 +00:00
|
|
|
class GrTextureParams;
|
2014-09-29 21:20:11 +00:00
|
|
|
class GrTexturePriv;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
class GrTexture : public GrSurface {
|
2010-12-22 21:39:39 +00:00
|
|
|
public:
|
|
|
|
/**
|
2011-02-17 16:43:10 +00:00
|
|
|
* Approximate number of bytes used by the texture
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
2014-05-05 19:09:13 +00:00
|
|
|
virtual size_t gpuMemorySize() const SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-08-20 19:22:38 +00:00
|
|
|
// GrSurface overrides
|
2012-06-21 21:09:06 +00:00
|
|
|
virtual bool readPixels(int left, int top, int width, int height,
|
2012-08-20 19:22:38 +00:00
|
|
|
GrPixelConfig config,
|
|
|
|
void* buffer,
|
|
|
|
size_t rowBytes = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
|
2011-11-16 20:36:03 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
virtual void writePixels(int left, int top, int width, int height,
|
2012-08-20 19:22:38 +00:00
|
|
|
GrPixelConfig config,
|
|
|
|
const void* buffer,
|
|
|
|
size_t rowBytes = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
|
2012-06-21 21:09:06 +00:00
|
|
|
|
|
|
|
virtual GrTexture* asTexture() SK_OVERRIDE { return this; }
|
|
|
|
virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; }
|
2014-05-09 20:46:48 +00:00
|
|
|
virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget.get(); }
|
|
|
|
virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fRenderTarget.get(); }
|
2011-04-05 17:08:27 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
/**
|
|
|
|
* Return the native ID or handle to the texture, depending on the
|
2012-10-25 18:56:10 +00:00
|
|
|
* platform. e.g. on OpenGL, return the texture ID.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
2012-10-25 18:56:10 +00:00
|
|
|
virtual GrBackendObject getTextureHandle() const = 0;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2014-05-09 18:02:51 +00:00
|
|
|
/**
|
2014-05-09 20:46:48 +00:00
|
|
|
* This function indicates that the texture parameters (wrap mode, filtering, ...) have been
|
|
|
|
* changed externally to Skia.
|
2014-05-09 18:02:51 +00:00
|
|
|
*/
|
2014-05-09 20:46:48 +00:00
|
|
|
virtual void textureParamsModified() = 0;
|
|
|
|
|
|
|
|
/**
|
2014-09-29 21:20:11 +00:00
|
|
|
* Informational texture flags. This will be removed soon.
|
2014-05-09 20:46:48 +00:00
|
|
|
*/
|
|
|
|
enum FlagBits {
|
|
|
|
kFirstBit = (kLastPublic_GrTextureFlagBit << 1),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This texture should be returned to the texture cache when
|
|
|
|
* it is no longer reffed
|
|
|
|
*/
|
|
|
|
kReturnToCache_FlagBit = kFirstBit,
|
|
|
|
};
|
|
|
|
|
|
|
|
void resetFlag(GrTextureFlags flags) {
|
|
|
|
fDesc.fFlags = fDesc.fFlags & ~flags;
|
|
|
|
}
|
2014-05-09 18:02:51 +00:00
|
|
|
|
2013-08-28 14:17:03 +00:00
|
|
|
#ifdef SK_DEBUG
|
2010-12-22 21:39:39 +00:00
|
|
|
void validate() const {
|
|
|
|
this->INHERITED::validate();
|
2012-06-04 12:48:45 +00:00
|
|
|
this->validateDesc();
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-10-02 16:42:21 +00:00
|
|
|
|
2014-09-29 21:20:11 +00:00
|
|
|
/** Access methods that are only to be used within Skia code. */
|
|
|
|
inline GrTexturePriv texturePriv();
|
|
|
|
inline const GrTexturePriv texturePriv() const;
|
2012-06-04 20:05:28 +00:00
|
|
|
|
2011-04-05 21:16:14 +00:00
|
|
|
protected:
|
2013-04-09 15:04:12 +00:00
|
|
|
// A texture refs its rt representation but not vice-versa. It is up to
|
|
|
|
// the subclass constructor to initialize this pointer.
|
|
|
|
SkAutoTUnref<GrRenderTarget> fRenderTarget;
|
2011-04-05 21:16:14 +00:00
|
|
|
|
2014-09-29 21:20:11 +00:00
|
|
|
GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc);
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2013-04-09 15:04:12 +00:00
|
|
|
virtual ~GrTexture();
|
2011-07-26 12:32:36 +00:00
|
|
|
|
2011-04-05 21:16:14 +00:00
|
|
|
// GrResource overrides
|
2012-06-22 12:41:43 +00:00
|
|
|
virtual void onRelease() SK_OVERRIDE;
|
|
|
|
virtual void onAbandon() SK_OVERRIDE;
|
2011-04-05 21:16:14 +00:00
|
|
|
|
2012-06-04 12:48:45 +00:00
|
|
|
void validateDesc() const;
|
|
|
|
|
2014-05-09 17:37:55 +00:00
|
|
|
private:
|
2014-05-09 20:46:48 +00:00
|
|
|
void dirtyMipMaps(bool mipMapsDirty);
|
|
|
|
|
|
|
|
enum MipMapsStatus {
|
|
|
|
kNotAllocated_MipMapsStatus,
|
|
|
|
kAllocated_MipMapsStatus,
|
|
|
|
kValid_MipMapsStatus
|
|
|
|
};
|
|
|
|
|
2014-09-29 21:20:11 +00:00
|
|
|
MipMapsStatus fMipMapsStatus;
|
|
|
|
// These two shift a fixed-point value into normalized coordinates
|
|
|
|
// for this texture if the texture is power of two sized.
|
|
|
|
int fShiftFixedX;
|
|
|
|
int fShiftFixedY;
|
|
|
|
|
|
|
|
friend class GrTexturePriv;
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2014-09-29 21:20:11 +00:00
|
|
|
typedef GrSurface INHERITED;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
2013-03-29 19:22:36 +00:00
|
|
|
/**
|
|
|
|
* Represents a texture that is intended to be accessed in device coords with an offset.
|
|
|
|
*/
|
|
|
|
class GrDeviceCoordTexture {
|
|
|
|
public:
|
|
|
|
GrDeviceCoordTexture() { fOffset.set(0, 0); }
|
|
|
|
|
|
|
|
GrDeviceCoordTexture(const GrDeviceCoordTexture& other) {
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrDeviceCoordTexture(GrTexture* texture, const SkIPoint& offset)
|
|
|
|
: fTexture(SkSafeRef(texture))
|
|
|
|
, fOffset(offset) {
|
|
|
|
}
|
|
|
|
|
|
|
|
GrDeviceCoordTexture& operator=(const GrDeviceCoordTexture& other) {
|
|
|
|
fTexture.reset(SkSafeRef(other.fTexture.get()));
|
|
|
|
fOffset = other.fOffset;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkIPoint& offset() const { return fOffset; }
|
|
|
|
|
|
|
|
void setOffset(const SkIPoint& offset) { fOffset = offset; }
|
|
|
|
void setOffset(int ox, int oy) { fOffset.set(ox, oy); }
|
|
|
|
|
|
|
|
GrTexture* texture() const { return fTexture.get(); }
|
|
|
|
|
|
|
|
GrTexture* setTexture(GrTexture* texture) {
|
|
|
|
fTexture.reset(SkSafeRef(texture));
|
|
|
|
return texture;
|
|
|
|
}
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2013-03-29 19:22:36 +00:00
|
|
|
private:
|
|
|
|
SkAutoTUnref<GrTexture> fTexture;
|
|
|
|
SkIPoint fOffset;
|
|
|
|
};
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
#endif
|