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

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

Issue 1266883002: unify pixelref and image ID space, so we can share IDs when we share pixels (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('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 "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
76 76
77 SkShader* onNewShader(SkShader::TileMode, 77 SkShader* onNewShader(SkShader::TileMode,
78 SkShader::TileMode, 78 SkShader::TileMode,
79 const SkMatrix* localMatrix) const override; 79 const SkMatrix* localMatrix) const override;
80 80
81 bool isOpaque() const override; 81 bool isOpaque() const override;
82 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; 82 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
83 83
84 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props, bool lockPix els = false) 84 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props, bool lockPix els = false)
85 : INHERITED(bm.width(), bm.height(), props) 85 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props)
86 , fBitmap(bm) { 86 , fBitmap(bm) {
87 if (lockPixels) { 87 if (lockPixels) {
88 fBitmap.lockPixels(); 88 fBitmap.lockPixels();
89 } 89 }
90 SkASSERT(fBitmap.isImmutable()); 90 SkASSERT(fBitmap.isImmutable());
91 } 91 }
92 92
93 private: 93 private:
94 SkImage_Raster() : INHERITED(0, 0, NULL) { 94 SkImage_Raster() : INHERITED(0, 0, fBitmap.getGenerationID(), NULL) {
95 fBitmap.setImmutable(); 95 fBitmap.setImmutable();
96 } 96 }
97 97
98 SkBitmap fBitmap; 98 SkBitmap fBitmap;
99 99
100 typedef SkImage_Base INHERITED; 100 typedef SkImage_Base INHERITED;
101 }; 101 };
102 102
103 /////////////////////////////////////////////////////////////////////////////// 103 ///////////////////////////////////////////////////////////////////////////////
104 104
105 static void release_data(void* addr, void* context) { 105 static void release_data(void* addr, void* context) {
106 SkData* data = static_cast<SkData*>(context); 106 SkData* data = static_cast<SkData*>(context);
107 data->unref(); 107 data->unref();
108 } 108 }
109 109
110 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes, 110 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes,
111 SkColorTable* ctable, const SkSurfaceProps* props ) 111 SkColorTable* ctable, const SkSurfaceProps* props )
112 : INHERITED(info.width(), info.height(), props) 112 : INHERITED(info.width(), info.height(), kNeedNewImageUniqueID, props)
113 { 113 {
114 data->ref(); 114 data->ref();
115 void* addr = const_cast<void*>(data->data()); 115 void* addr = const_cast<void*>(data->data());
116 116
117 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data); 117 fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data);
118 fBitmap.setImmutable(); 118 fBitmap.setImmutable();
119 fBitmap.lockPixels(); 119 fBitmap.lockPixels();
120 } 120 }
121 121
122 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin, 122 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin,
123 size_t rowBytes, const SkSurfaceProps* props) 123 size_t rowBytes, const SkSurfaceProps* props)
124 : INHERITED(info.width(), info.height(), props) 124 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props)
125 { 125 {
126 fBitmap.setInfo(info, rowBytes); 126 fBitmap.setInfo(info, rowBytes);
127 fBitmap.setPixelRef(pr, pixelRefOrigin); 127 fBitmap.setPixelRef(pr, pixelRefOrigin);
128 fBitmap.lockPixels(); 128 fBitmap.lockPixels();
129 SkASSERT(fBitmap.isImmutable()); 129 SkASSERT(fBitmap.isImmutable());
130 } 130 }
131 131
132 SkImage_Raster::~SkImage_Raster() {} 132 SkImage_Raster::~SkImage_Raster() {}
133 133
134 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY, 134 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // pixelref since the caller might call setImmutable() themselves 278 // pixelref since the caller might call setImmutable() themselves
279 // (thus changing our state). 279 // (thus changing our state).
280 if (fBitmap.isImmutable()) { 280 if (fBitmap.isImmutable()) {
281 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); 281 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
282 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); 282 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
283 return true; 283 return true;
284 } 284 }
285 } 285 }
286 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); 286 return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
287 } 287 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698