Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/image/SkImage_Gpu.cpp

Issue 20354003: Make SkImage_Gpu share it's pixelref with the surface to prevent premature return to scratch pool. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkImage.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrTexture.h" 13 #include "GrTexture.h"
14 #include "SkGrPixelRef.h" 14 #include "SkGrPixelRef.h"
15 15
16 class SkImage_Gpu : public SkImage_Base { 16 class SkImage_Gpu : public SkImage_Base {
17 public: 17 public:
18 SK_DECLARE_INST_COUNT(SkImage_Gpu) 18 SK_DECLARE_INST_COUNT(SkImage_Gpu)
19 19
20 SkImage_Gpu(GrTexture*); 20 explicit SkImage_Gpu(const SkBitmap&);
21 virtual ~SkImage_Gpu(); 21 virtual ~SkImage_Gpu();
22 22
23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OV ERRIDE; 23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OV ERRIDE;
24 virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& ds t, const SkPaint*) SK_OVERRIDE; 24 virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& ds t, const SkPaint*) SK_OVERRIDE;
25 virtual GrTexture* onGetTexture() SK_OVERRIDE; 25 virtual GrTexture* onGetTexture() SK_OVERRIDE;
26 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE { 26 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE {
27 // TODO 27 // TODO
28 return false; 28 return false;
29 } 29 }
30 30
31 GrTexture* getTexture() { return fTexture; } 31 GrTexture* getTexture() { return fBitmap.getTexture(); }
32
33 void setTexture(GrTexture* texture);
34 32
35 private: 33 private:
36 GrTexture* fTexture;
37 SkBitmap fBitmap; 34 SkBitmap fBitmap;
38 35
39 typedef SkImage_Base INHERITED; 36 typedef SkImage_Base INHERITED;
40 }; 37 };
41 38
42 SK_DEFINE_INST_COUNT(SkImage_Gpu) 39 SK_DEFINE_INST_COUNT(SkImage_Gpu)
43 40
44 /////////////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////////////
45 42
46 SkImage_Gpu::SkImage_Gpu(GrTexture* texture) 43 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap)
47 : INHERITED(texture->width(), texture->height()) 44 : INHERITED(bitmap.width(), bitmap.height())
48 , fTexture(texture) { 45 , fBitmap(bitmap) {
49 46 SkASSERT(NULL != fBitmap.getTexture());
50 SkASSERT(NULL != fTexture);
51 fTexture->ref();
52 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, fTexture->width(), fTexture-> height());
53 fBitmap.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (fTexture)))->unref();
54 } 47 }
55 48
56 SkImage_Gpu::~SkImage_Gpu() { 49 SkImage_Gpu::~SkImage_Gpu() {
57 SkSafeUnref(fTexture);
58 } 50 }
59 51
60 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 52 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
61 const SkPaint* paint) { 53 const SkPaint* paint) {
62 canvas->drawBitmap(fBitmap, x, y, paint); 54 canvas->drawBitmap(fBitmap, x, y, paint);
63 } 55 }
64 56
65 void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const Sk Rect& dst, 57 void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const Sk Rect& dst,
66 const SkPaint* paint) { 58 const SkPaint* paint) {
67 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); 59 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
68 } 60 }
69 61
70 GrTexture* SkImage_Gpu::onGetTexture() { 62 GrTexture* SkImage_Gpu::onGetTexture() {
71 return fTexture; 63 return fBitmap.getTexture();
72 }
73
74 void SkImage_Gpu::setTexture(GrTexture* texture) {
75
76 if (texture == fTexture) {
77 return;
78 }
79
80 SkRefCnt_SafeAssign(fTexture, texture);
81 fBitmap.setPixelRef(new SkGrPixelRef(texture))->unref();
82 } 64 }
83 65
84 /////////////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////////////
85 67
86 SkImage* SkImage::NewTexture(GrTexture* texture) { 68 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) {
87 if (NULL == texture) { 69 if (NULL == bitmap.getTexture()) {
88 return NULL; 70 return NULL;
89 } 71 }
90 72
91 return SkNEW_ARGS(SkImage_Gpu, (texture)); 73 return SkNEW_ARGS(SkImage_Gpu, (bitmap));
92 } 74 }
93 75
94 GrTexture* SkTextureImageGetTexture(SkImage* image) { 76 GrTexture* SkTextureImageGetTexture(SkImage* image) {
95 return ((SkImage_Gpu*)image)->getTexture(); 77 return ((SkImage_Gpu*)image)->getTexture();
96 } 78 }
97
98 void SkTextureImageSetTexture(SkImage* image, GrTexture* texture) {
99 ((SkImage_Gpu*)image)->setTexture(texture);
100 }
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698