blob: ab0a5237fd3eadc5a87f21c29d5150559fa10daa [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"
robertphillips@google.com97b6b072012-10-31 14:48:39 +000012#include "GrContext.h"
13#include "GrTexture.h"
14#include "SkGrPixelRef.h"
reed@google.com5d4ba882012-07-31 15:45:27 +000015
16class SkImage_Gpu : public SkImage_Base {
17public:
robertphillips@google.com97b6b072012-10-31 14:48:39 +000018 SK_DECLARE_INST_COUNT(SkImage_Gpu)
reed@google.com5d4ba882012-07-31 15:45:27 +000019
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +000020 explicit SkImage_Gpu(const SkBitmap&);
reed@google.com5d4ba882012-07-31 15:45:27 +000021 virtual ~SkImage_Gpu();
22
robertphillips@google.com97b6b072012-10-31 14:48:39 +000023 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OVERRIDE;
commit-bot@chromium.orgdfec28d2013-07-23 15:52:16 +000024 virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*) SK_OVERRIDE;
junov@chromium.orgda904742013-05-01 22:38:16 +000025 virtual GrTexture* onGetTexture() SK_OVERRIDE;
reed@google.com4b0757b2013-05-20 16:33:41 +000026 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE {
27 // TODO
28 return false;
29 }
robertphillips@google.com97b6b072012-10-31 14:48:39 +000030
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +000031 GrTexture* getTexture() { return fBitmap.getTexture(); }
reed@google.com5d4ba882012-07-31 15:45:27 +000032
33private:
34 SkBitmap fBitmap;
35
36 typedef SkImage_Base INHERITED;
37};
38
39///////////////////////////////////////////////////////////////////////////////
40
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +000041SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap)
42 : INHERITED(bitmap.width(), bitmap.height())
43 , fBitmap(bitmap) {
44 SkASSERT(NULL != fBitmap.getTexture());
reed@google.com5d4ba882012-07-31 15:45:27 +000045}
46
robertphillips@google.com97b6b072012-10-31 14:48:39 +000047SkImage_Gpu::~SkImage_Gpu() {
robertphillips@google.com97b6b072012-10-31 14:48:39 +000048}
reed@google.com5d4ba882012-07-31 15:45:27 +000049
robertphillips@google.com97b6b072012-10-31 14:48:39 +000050void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
51 const SkPaint* paint) {
reed@google.com5d4ba882012-07-31 15:45:27 +000052 canvas->drawBitmap(fBitmap, x, y, paint);
53}
54
commit-bot@chromium.orgdfec28d2013-07-23 15:52:16 +000055void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst,
56 const SkPaint* paint) {
57 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
58}
59
junov@chromium.orgda904742013-05-01 22:38:16 +000060GrTexture* SkImage_Gpu::onGetTexture() {
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +000061 return fBitmap.getTexture();
reed@google.com5d4ba882012-07-31 15:45:27 +000062}
63
robertphillips@google.com97b6b072012-10-31 14:48:39 +000064///////////////////////////////////////////////////////////////////////////////
65
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +000066SkImage* SkImage::NewTexture(const SkBitmap& bitmap) {
67 if (NULL == bitmap.getTexture()) {
robertphillips@google.com97b6b072012-10-31 14:48:39 +000068 return NULL;
69 }
70
commit-bot@chromium.org4d24b742013-07-25 23:29:40 +000071 return SkNEW_ARGS(SkImage_Gpu, (bitmap));
robertphillips@google.com97b6b072012-10-31 14:48:39 +000072}
73
74GrTexture* SkTextureImageGetTexture(SkImage* image) {
75 return ((SkImage_Gpu*)image)->getTexture();
76}