opacity_filter_canvas.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SKIA_EXT_OPACITY_FILTER_CANVAS_H_
  5. #define SKIA_EXT_OPACITY_FILTER_CANVAS_H_
  6. #include "third_party/skia/include/utils/SkPaintFilterCanvas.h"
  7. namespace skia {
  8. // This filter canvas allows setting an opacity on every draw call to a canvas,
  9. // and to disable image filtering. Note that the opacity setting is only
  10. // correct in very limited conditions: when there is only zero or one opaque,
  11. // nonlayer draw for every pixel in the surface.
  12. class SK_API OpacityFilterCanvas : public SkPaintFilterCanvas {
  13. public:
  14. OpacityFilterCanvas(SkCanvas* canvas,
  15. float opacity,
  16. bool disable_image_filtering);
  17. protected:
  18. bool onFilter(SkPaint& paint) const override;
  19. void onDrawImage2(const SkImage*,
  20. SkScalar dx,
  21. SkScalar dy,
  22. const SkSamplingOptions&,
  23. const SkPaint*) override;
  24. void onDrawImageRect2(const SkImage*,
  25. const SkRect& src,
  26. const SkRect& dst,
  27. const SkSamplingOptions&,
  28. const SkPaint*,
  29. SrcRectConstraint) override;
  30. void onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[],
  31. int count,
  32. const SkPoint dstClips[],
  33. const SkMatrix preViewMatrices[],
  34. const SkSamplingOptions&,
  35. const SkPaint*,
  36. SrcRectConstraint) override;
  37. void onDrawPicture(const SkPicture* picture,
  38. const SkMatrix* matrix,
  39. const SkPaint* paint) override;
  40. private:
  41. typedef SkPaintFilterCanvas INHERITED;
  42. float opacity_;
  43. bool disable_image_filtering_;
  44. };
  45. } // namespace skia
  46. #endif // SKIA_EXT_OPACITY_FILTER_CANVAS_H_