blob: 6ccf10bfd8413cf21b5111d8ac136e3e81d62f96 [file] [log] [blame]
reed@google.com5d4ba882012-07-31 15:45:27 +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 */
7
8#include "SkImage_Base.h"
9#include "SkImagePriv.h"
10#include "SkBitmap.h"
11#include "SkCanvas.h"
12#include "SkData.h"
13#include "SkDataPixelRef.h"
14
15class SkImage_Gpu : public SkImage_Base {
16public:
17 static bool ValidArgs(GrContext* context,
18 const GrPlatformTextureDesc& desc) {
19 if (0 == desc.fTextureHandle) {
20 return false;
21 }
22 if (desc.fWidth < 0 || desc.fHeight < 0) {
23 return false;
24 }
25 return true;
26 }
27
28 SkImage_Gpu(GrContext* context, const GrPlatformTextureDesc& desc);
29 virtual ~SkImage_Gpu();
30
31 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE;
32
33private:
34 SkBitmap fBitmap;
35
36 typedef SkImage_Base INHERITED;
37};
38
39///////////////////////////////////////////////////////////////////////////////
40
41SkImage_Gpu::SkImage_Gpu(GrContext* context, const GrPlatformTextureDesc& desc)
42 : INHERITED(desc.fWidth, desc.fHeight) {
43#if 0
44 bool isOpaque;
45 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
46
47 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes);
48 fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref();
49 fBitmap.setIsOpaque(isOpaque);
50 fBitmap.setImmutable();
51#endif
52}
53
54SkImage_Gpu::~SkImage_Gpu() {}
55
56void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
57 canvas->drawBitmap(fBitmap, x, y, paint);
58}
59
60///////////////////////////////////////////////////////////////////////////////
61
62SkImage* SkImage::NewRasterCopy(NewTexture(GrContext* context,
63 const GrPlatformTextureDesc& desc) {
64 if (NULL == context) {
65 return NULL;
66 }
67 if (!SkImage_Gpu::ValidArgs(context, desc)) {
68 return NULL;
69 }
70
71 return SkNEW_ARGS(SkImage_Gpu, (context, desc));
72}
73