From 5d4ba8869476831ee73b15a052af8003d0a1fa2e Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Tue, 31 Jul 2012 15:45:27 +0000 Subject: check-point for gpu support in SkImage/SkSurface git-svn-id: http://skia.googlecode.com/svn/trunk@4859 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/image/SkImage_Gpu.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/image/SkImage_Gpu.cpp (limited to 'src/image/SkImage_Gpu.cpp') diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp new file mode 100644 index 0000000000..6ccf10bfd8 --- /dev/null +++ b/src/image/SkImage_Gpu.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkImage_Base.h" +#include "SkImagePriv.h" +#include "SkBitmap.h" +#include "SkCanvas.h" +#include "SkData.h" +#include "SkDataPixelRef.h" + +class SkImage_Gpu : public SkImage_Base { +public: + static bool ValidArgs(GrContext* context, + const GrPlatformTextureDesc& desc) { + if (0 == desc.fTextureHandle) { + return false; + } + if (desc.fWidth < 0 || desc.fHeight < 0) { + return false; + } + return true; + } + + SkImage_Gpu(GrContext* context, const GrPlatformTextureDesc& desc); + virtual ~SkImage_Gpu(); + + virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; + +private: + SkBitmap fBitmap; + + typedef SkImage_Base INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// + +SkImage_Gpu::SkImage_Gpu(GrContext* context, const GrPlatformTextureDesc& desc) + : INHERITED(desc.fWidth, desc.fHeight) { +#if 0 + bool isOpaque; + SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + + fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); + fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref(); + fBitmap.setIsOpaque(isOpaque); + fBitmap.setImmutable(); +#endif +} + +SkImage_Gpu::~SkImage_Gpu() {} + +void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) { + canvas->drawBitmap(fBitmap, x, y, paint); +} + +/////////////////////////////////////////////////////////////////////////////// + +SkImage* SkImage::NewRasterCopy(NewTexture(GrContext* context, + const GrPlatformTextureDesc& desc) { + if (NULL == context) { + return NULL; + } + if (!SkImage_Gpu::ValidArgs(context, desc)) { + return NULL; + } + + return SkNEW_ARGS(SkImage_Gpu, (context, desc)); +} + -- cgit v1.2.3