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

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

Issue 132643007: Revert "Revert of https://codereview.chromium.org/129423002/" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 | « src/image/SkImage_Base.h ('k') | src/image/SkSurface_Raster.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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 static SkImage* NewEmpty(); 51 static SkImage* NewEmpty();
52 52
53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb); 53 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb);
54 virtual ~SkImage_Raster(); 54 virtual ~SkImage_Raster();
55 55
56 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRI DE; 56 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRI DE;
57 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; 57 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE;
58 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; 58 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE;
59 59
60 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 60 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
61 SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes); 61 SkImage_Raster(SkPixelRef*);
62 62
63 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 63 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
64 64
65 private: 65 private:
66 SkImage_Raster() : INHERITED(0, 0) {} 66 SkImage_Raster() : INHERITED(0, 0) {}
67 67
68 SkBitmap fBitmap; 68 SkBitmap fBitmap;
69 69
70 typedef SkImage_Base INHERITED; 70 typedef SkImage_Base INHERITED;
71 }; 71 };
72 72
73 /////////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////////
74 74
75 SkImage* SkImage_Raster::NewEmpty() { 75 SkImage* SkImage_Raster::NewEmpty() {
76 // Returns lazily created singleton 76 // Returns lazily created singleton
77 static SkImage* gEmpty; 77 static SkImage* gEmpty;
78 if (NULL == gEmpty) { 78 if (NULL == gEmpty) {
79 gEmpty = SkNEW(SkImage_Raster); 79 gEmpty = SkNEW(SkImage_Raster);
80 } 80 }
81 gEmpty->ref(); 81 gEmpty->ref();
82 return gEmpty; 82 return gEmpty;
83 } 83 }
84 84
85 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) 85 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
86 : INHERITED(info.fWidth, info.fHeight) { 86 : INHERITED(info.fWidth, info.fHeight) {
87 fBitmap.setConfig(info, rowBytes);
88 SkAutoTUnref<SkPixelRef> ref( 87 SkAutoTUnref<SkPixelRef> ref(
89 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data, 0)); 88 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data, 0));
90 fBitmap.setPixelRef(ref); 89 fBitmap.installPixelRef(ref);
91 fBitmap.setImmutable(); 90 fBitmap.setImmutable();
92 } 91 }
93 92
94 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes ) 93 SkImage_Raster::SkImage_Raster(SkPixelRef* pr)
95 : INHERITED(info.fWidth, info.fHeight) 94 : INHERITED(pr->info())
96 { 95 {
97 fBitmap.setConfig(info, rowBytes); 96 fBitmap.installPixelRef(pr);
98 fBitmap.setPixelRef(pr);
99 } 97 }
100 98
101 SkImage_Raster::~SkImage_Raster() {} 99 SkImage_Raster::~SkImage_Raster() {}
102 100
103 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) { 101 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) {
104 canvas->drawBitmap(fBitmap, x, y, paint); 102 canvas->drawBitmap(fBitmap, x, y, paint);
105 } 103 }
106 104
107 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) { 105 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) {
108 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); 106 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // did they give us enough data? 146 // did they give us enough data?
149 size_t size = info.fHeight * rowBytes; 147 size_t size = info.fHeight * rowBytes;
150 if (pixelData->size() < size) { 148 if (pixelData->size() < size) {
151 return NULL; 149 return NULL;
152 } 150 }
153 151
154 SkAutoDataUnref data(pixelData); 152 SkAutoDataUnref data(pixelData);
155 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes)); 153 return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes));
156 } 154 }
157 155
158 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, 156 SkImage* SkNewImageFromPixelRef(SkPixelRef* pr) {
159 size_t rowBytes) { 157 return SkNEW_ARGS(SkImage_Raster, (pr));
160 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes));
161 } 158 }
162 159
163 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { 160 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
164 return ((SkImage_Raster*)image)->getPixelRef(); 161 return ((SkImage_Raster*)image)->getPixelRef();
165 } 162 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Base.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698