skia2/include/gpu/SkGrPixelRef.h
scroggo@google.com a2a3192847 Fix some extract subset bugs.
In SkBitmap::extractSubset, perform a deepCopy, if the pixelRef supports it.

Fixes a bug in the 'extractbitmap' gm, which attempts to draw a subset of a texture backed bitmap (if the canvas is really an SkGpuCanvas).

Also fix some bugs that happen when there is a pixel offset. These fixes get bypassed by the deepCopy, but a user can still set a pixel offset manually.

When copying GPU backed bitmap with a pixel offset, copy the offset.

If the new config is the same as the old, copy fRowBytes as well.

Add a function to SkBitmap.cpp (getUpperLeftFromOffset) to find the x,y coordinate to use when copying to a new config.

Fix a bug where readPixels copied to the correct desired config and we were setting the generation ID to match even though the desired config was not the same as the original config (caught by my new tests!).

Add some tests to verify the correct behavior.

Review URL: https://codereview.appspot.com/6839043

git-svn-id: http://skia.googlecode.com/svn/trunk@6710 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-12-07 19:14:45 +00:00

72 lines
1.8 KiB
C++

/*
* Copyright 2010 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkGrPixelRef_DEFINED
#define SkGrPixelRef_DEFINED
#include "SkBitmap.h"
#include "SkPixelRef.h"
#include "GrTexture.h"
#include "GrRenderTarget.h"
/**
* Common baseclass that implements onLockPixels() by calling onReadPixels().
* Since it has a copy, it always returns false for onLockPixelsAreWritable().
*/
class SK_API SkROLockPixelsPixelRef : public SkPixelRef {
public:
SkROLockPixelsPixelRef();
virtual ~SkROLockPixelsPixelRef();
protected:
// override from SkPixelRef
virtual void* onLockPixels(SkColorTable** ptr);
virtual void onUnlockPixels();
virtual bool onLockPixelsAreWritable() const; // return false;
private:
SkBitmap fBitmap;
typedef SkPixelRef INHERITED;
};
/**
* PixelRef that wraps a GrSurface
*/
class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
public:
/**
* Constructs a pixel ref around a GrSurface. If the caller has locked the GrSurface in the
* cache and would like the pixel ref to unlock it in its destructor then transferCacheLock
* should be set to true.
*/
SkGrPixelRef(GrSurface* surface, bool transferCacheLock = false);
virtual ~SkGrPixelRef();
// override from SkPixelRef
virtual SkGpuTexture* getTexture() SK_OVERRIDE;
SK_DECLARE_UNFLATTENABLE_OBJECT()
protected:
// overrides from SkPixelRef
virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE;
private:
GrSurface* fSurface;
bool fUnlock; // if true the pixel ref owns a texture cache lock on fSurface
typedef SkROLockPixelsPixelRef INHERITED;
};
#endif