Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
| 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 #ifndef SkDevice_DEFINED | 8 #ifndef SkDevice_DEFINED |
| 9 #define SkDevice_DEFINED | 9 #define SkDevice_DEFINED |
| 10 | 10 |
| 11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
| 12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
| 14 #include "SkColor.h" | 14 #include "SkColor.h" |
| 15 #include "SkImageFilter.h" | 15 #include "SkImageFilter.h" |
| 16 | 16 |
| 17 class SkClipStack; | 17 class SkClipStack; |
| 18 class SkDraw; | 18 class SkDraw; |
| 19 struct SkIRect; | 19 struct SkIRect; |
| 20 class SkImage; | |
| 20 class SkMatrix; | 21 class SkMatrix; |
| 21 class SkMetaData; | 22 class SkMetaData; |
| 22 class SkRegion; | 23 class SkRegion; |
| 23 struct SkDeviceProperties; | 24 struct SkDeviceProperties; |
| 24 class GrRenderTarget; | 25 class GrRenderTarget; |
| 26 class SkSurface_Base; | |
| 27 | |
| 25 | 28 |
| 26 class SK_API SkBaseDevice : public SkRefCnt { | 29 class SK_API SkBaseDevice : public SkRefCnt { |
| 27 public: | 30 public: |
| 28 SK_DECLARE_INST_COUNT(SkBaseDevice) | 31 SK_DECLARE_INST_COUNT(SkBaseDevice) |
| 29 | 32 |
| 30 /** | 33 /** |
| 31 * Construct a new device. | 34 * Construct a new device. |
| 32 */ | 35 */ |
| 33 SkBaseDevice(); | 36 SkBaseDevice(); |
| 34 explicit SkBaseDevice(const SkDeviceProperties&); | 37 explicit SkBaseDevice(const SkDeviceProperties&); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 * pre-concated with the current matrix. | 195 * pre-concated with the current matrix. |
| 193 */ | 196 */ |
| 194 virtual void drawPath(const SkDraw&, const SkPath& path, | 197 virtual void drawPath(const SkDraw&, const SkPath& path, |
| 195 const SkPaint& paint, | 198 const SkPaint& paint, |
| 196 const SkMatrix* prePathMatrix = NULL, | 199 const SkMatrix* prePathMatrix = NULL, |
| 197 bool pathIsMutable = false) = 0; | 200 bool pathIsMutable = false) = 0; |
| 198 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, | 201 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
| 199 const SkMatrix& matrix, const SkPaint& paint) = 0; | 202 const SkMatrix& matrix, const SkPaint& paint) = 0; |
| 200 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, | 203 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
| 201 int x, int y, const SkPaint& paint) = 0; | 204 int x, int y, const SkPaint& paint) = 0; |
| 205 virtual void drawImage(const SkDraw&, const SkImage& image, | |
| 206 int x, int y, const SkPaint& paint); | |
| 202 | 207 |
| 203 /** | 208 /** |
| 204 * The default impl. will create a bitmap-shader from the bitmap, | 209 * The default impl. will create a bitmap-shader from the bitmap, |
| 205 * and call drawRect with it. | 210 * and call drawRect with it. |
| 206 */ | 211 */ |
| 207 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, | 212 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, |
| 208 const SkRect* srcOrNull, const SkRect& dst, | 213 const SkRect* srcOrNull, const SkRect& dst, |
| 209 const SkPaint& paint, | 214 const SkPaint& paint, |
| 210 SkCanvas::DrawBitmapRectFlags flags) = 0; | 215 SkCanvas::DrawBitmapRectFlags flags) = 0; |
| 211 | 216 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 * Override and return true for filters that the device can handle | 271 * Override and return true for filters that the device can handle |
| 267 * intrinsically. Doing so means that SkCanvas will pass-through this | 272 * intrinsically. Doing so means that SkCanvas will pass-through this |
| 268 * filter to drawSprite and drawDevice (and potentially filterImage). | 273 * filter to drawSprite and drawDevice (and potentially filterImage). |
| 269 * Returning false means the SkCanvas will have apply the filter itself, | 274 * Returning false means the SkCanvas will have apply the filter itself, |
| 270 * and just pass the resulting image to the device. | 275 * and just pass the resulting image to the device. |
| 271 */ | 276 */ |
| 272 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } | 277 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } |
| 273 | 278 |
| 274 /** | 279 /** |
| 275 * Related (but not required) to canHandleImageFilter, this method returns | 280 * Related (but not required) to canHandleImageFilter, this method returns |
| 276 * true if the device could apply the filter to the src bitmap and return | 281 * true if the device could apply the filter to the src image and return |
| 277 * the result (and updates offset as needed). | 282 * the result (and updates offset as needed). |
| 278 * If the device does not recognize or support this filter, | 283 * If the device does not recognize or support this filter, |
| 279 * it just returns false and leaves result and offset unchanged. | 284 * it just returns false and leaves result and offset unchanged. |
| 280 */ | 285 */ |
| 281 virtual bool filterImage(const SkImageFilter*, const SkBitmap&, | 286 virtual bool filterImage(const SkImageFilter*, SkImage&, |
| 282 const SkImageFilter::Context&, | 287 const SkImageFilter::Context&, |
| 283 SkBitmap* /*result*/, SkIPoint* /*offset*/) { | 288 SkAutoTUnref<SkImage>& /*result*/, SkIPoint* /*offs et*/) { |
| 284 return false; | 289 return false; |
| 285 } | 290 } |
| 286 | 291 |
| 287 protected: | 292 protected: |
| 288 // default impl returns NULL | 293 // default impl returns NULL |
| 289 virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&); | 294 virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&); |
| 290 | 295 |
| 291 // default impl returns NULL | 296 // default impl returns NULL |
| 292 virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes); | 297 virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes); |
| 293 | 298 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 : fInfo(info) | 348 : fInfo(info) |
| 344 , fUsage(usage) | 349 , fUsage(usage) |
| 345 , fPixelGeometry(AdjustGeometry(info, usage, geo)) | 350 , fPixelGeometry(AdjustGeometry(info, usage, geo)) |
| 346 {} | 351 {} |
| 347 | 352 |
| 348 const SkImageInfo fInfo; | 353 const SkImageInfo fInfo; |
| 349 const Usage fUsage; | 354 const Usage fUsage; |
| 350 const SkPixelGeometry fPixelGeometry; | 355 const SkPixelGeometry fPixelGeometry; |
| 351 }; | 356 }; |
| 352 | 357 |
| 358 virtual SkSurface* onCreateCompatibleSurface(const CreateInfo&) { | |
| 359 return NULL; | |
| 360 } | |
| 361 // TODO: left to compile pdf et al. | |
| 353 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) { | 362 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) { |
| 354 return NULL; | 363 return NULL; |
| 355 } | 364 } |
| 356 | 365 |
| 357 virtual void initForRootLayer(SkPixelGeometry geo); | 366 virtual void initForRootLayer(SkPixelGeometry geo); |
| 358 | 367 |
| 359 private: | 368 private: |
| 360 friend class SkCanvas; | 369 friend class SkCanvas; |
| 361 friend struct DeviceCM; //for setMatrixClip | 370 friend struct DeviceCM; //for setMatrixClip |
| 362 friend class SkDraw; | 371 friend class SkDraw; |
| 363 friend class SkDrawIter; | 372 friend class SkDrawIter; |
| 364 friend class SkDeviceFilteredPaint; | 373 friend class SkDeviceFilteredPaint; |
| 365 friend class SkDeviceImageFilterProxy; | 374 friend class SkDeviceImageFilterProxy; |
| 366 friend class SkDeferredDevice; // for newSurface | 375 friend class SkDeferredDevice; // for newSurface |
| 367 friend class SkNoPixelsBitmapDevice; | 376 friend class SkNoPixelsBitmapDevice; |
| 368 | 377 |
| 378 friend class SkSurface; | |
| 379 friend class SkSurface_Gpu; | |
| 369 friend class SkSurface_Raster; | 380 friend class SkSurface_Raster; |
| 370 | 381 |
| 382 // TODO: remove when GrRenderTarget is-a SkSurface. | |
|
bsalomon
2015/02/13 14:24:35
Do you mean to make GrRenderTarget be a subclass o
| |
| 383 SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } | |
| 384 void setSurfaceBase(SkSurface_Base* sb) { | |
| 385 SkASSERT(fSurfaceBase == NULL || sb == NULL); | |
| 386 fSurfaceBase = sb; | |
| 387 } | |
| 388 | |
| 371 // used to change the backend's pixels (and possibly config/rowbytes) | 389 // used to change the backend's pixels (and possibly config/rowbytes) |
| 372 // but cannot change the width/height, so there should be no change to | 390 // but cannot change the width/height, so there should be no change to |
| 373 // any clip information. | 391 // any clip information. |
| 374 // TODO: move to SkBitmapDevice | 392 // TODO: move to SkBitmapDevice |
| 375 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) {} | 393 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) {} |
| 376 | 394 |
| 377 virtual bool forceConservativeRasterClip() const { return false; } | 395 virtual bool forceConservativeRasterClip() const { return false; } |
| 378 | 396 |
| 379 // just called by SkCanvas when built as a layer | 397 // just called by SkCanvas when built as a layer |
| 380 void setOrigin(int x, int y) { fOrigin.set(x, y); } | 398 void setOrigin(int x, int y) { fOrigin.set(x, y); } |
| 381 | 399 |
| 382 /** Causes any deferred drawing to the device to be completed. | 400 /** Causes any deferred drawing to the device to be completed. |
| 383 */ | 401 */ |
| 384 virtual void flush() {} | 402 virtual void flush() {} |
| 385 | 403 |
| 386 virtual SkImageFilter::Cache* getImageFilterCache() { return NULL; } | 404 virtual SkImageFilter::Cache* getImageFilterCache() { return NULL; } |
| 387 | 405 |
| 388 SkIPoint fOrigin; | 406 SkIPoint fOrigin; |
| 389 SkMetaData* fMetaData; | 407 SkMetaData* fMetaData; |
| 390 SkDeviceProperties* fLeakyProperties; // will always exist. | 408 SkDeviceProperties* fLeakyProperties; // will always exist. |
| 391 | 409 |
| 410 SkSurface_Base* fSurfaceBase; | |
| 411 | |
| 392 #ifdef SK_DEBUG | 412 #ifdef SK_DEBUG |
| 393 bool fAttachedToCanvas; | 413 bool fAttachedToCanvas; |
| 394 #endif | 414 #endif |
| 395 | 415 |
| 396 typedef SkRefCnt INHERITED; | 416 typedef SkRefCnt INHERITED; |
| 397 }; | 417 }; |
| 398 | 418 |
| 399 #endif | 419 #endif |
| OLD | NEW |